Skip to content

Commit

Permalink
- always perform duplicate check when reading filmlist
Browse files Browse the repository at this point in the history
  • Loading branch information
derreisende77 committed Oct 21, 2024
1 parent 1899490 commit 03b9849
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/main/java/mediathek/config/Daten.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package mediathek.config;

import ca.odell.glazedlists.BasicEventList;
import ca.odell.glazedlists.EventList;
import com.google.common.util.concurrent.*;
import mediathek.Main;
import mediathek.SplashScreen;
Expand All @@ -10,6 +12,7 @@
import mediathek.daten.*;
import mediathek.daten.blacklist.ListeBlacklist;
import mediathek.filmlisten.FilmeLaden;
import mediathek.filmlisten.reader.FilmListReader;
import mediathek.javafx.bookmark.BookmarkDataList;
import mediathek.tool.ReplaceList;
import mediathek.tool.notification.INotificationCenter;
Expand All @@ -36,6 +39,8 @@
import java.util.concurrent.atomic.AtomicBoolean;

public class Daten {
private final EventList<FilmListReader.DuplicateStatistics> statisticsEventList = new BasicEventList<>();
public EventList<FilmListReader.DuplicateStatistics> getFilmListDuplicateStatisticsList() { return statisticsEventList; }
public static final MVColor mVColor = new MVColor(); // verwendete Farben
/**
* Prevent the unnecessary writing of a filmlist on startup when reading is enough
Expand Down
17 changes: 11 additions & 6 deletions src/main/java/mediathek/filmlisten/reader/FilmListReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.google.common.base.Stopwatch;
import com.google.common.collect.Sets;
import mediathek.config.Config;
import mediathek.config.Daten;
import mediathek.config.Konstanten;
import mediathek.controller.SenderFilmlistLoadApprover;
import mediathek.daten.Country;
Expand Down Expand Up @@ -44,7 +45,9 @@
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

public class FilmListReader implements AutoCloseable {
Expand Down Expand Up @@ -373,22 +376,24 @@ private void readData(JsonParser jp, ListeFilme listeFilme) throws IOException {
printDuplicateStatistics(listeFilme);
}

public record DuplicateStatistics(String sender, long count) {}

private void printDuplicateStatistics(@NotNull ListeFilme listeFilme) {
Stopwatch watch = Stopwatch.createStarted();
final var duplicates = listeFilme.parallelStream()
.filter(DatenFilm::isDuplicate)
.toList();
final var senders = duplicates.parallelStream().map(DatenFilm::getSender).distinct().toList();
final Map<String,Long> statistics = new HashMap<>();
var statisticsEventList = Daten.getInstance().getFilmListDuplicateStatisticsList();
for (var sender: senders) {
final var dupes = duplicates.parallelStream().filter(f -> f.getSender().equals(sender)).count();
statistics.put(sender, dupes);
statisticsEventList.add(new DuplicateStatistics(sender, dupes));
}
watch.stop();
logger.trace(statistics.toString());
logger.trace(statisticsEventList.toString());
long dupes = 0;
for (var key: statistics.keySet()) {
dupes += statistics.get(key);
for (var item : statisticsEventList) {
dupes += item.count;
}
logger.trace("Duplicate stream filter took: {}", watch);
logger.trace("Number of duplicates: {}", duplicates.size());
Expand Down

0 comments on commit 03b9849

Please sign in to comment.