-
-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- implement film duplicate search - implement lucene index key for duplicate search - implement duplicate details dialog which will display all related films - code cleanup - simplify film tab cell renderer and blend different background colors for better readability
- Loading branch information
1 parent
669bda0
commit ac16488
Showing
26 changed files
with
956 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/main/java/mediathek/gui/actions/ShowDuplicateStatisticsAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package mediathek.gui.actions; | ||
|
||
import mediathek.gui.duplicates.statistics.DuplicateStatisticsDialog; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import javax.swing.*; | ||
import java.awt.*; | ||
import java.awt.event.ActionEvent; | ||
|
||
public class ShowDuplicateStatisticsAction extends AbstractAction { | ||
private final Frame owner; | ||
|
||
public ShowDuplicateStatisticsAction(@NotNull Frame owner) { | ||
this.owner = owner; | ||
putValue(Action.NAME, "Film-Statistik anzeigen"); | ||
} | ||
|
||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
var dlg = new DuplicateStatisticsDialog(owner, this); | ||
dlg.setVisible(true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
src/main/java/mediathek/gui/duplicates/FilmDuplicateEvaluationTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package mediathek.gui.duplicates; | ||
|
||
import ca.odell.glazedlists.TransactionList; | ||
import com.google.common.base.Stopwatch; | ||
import com.google.common.collect.Sets; | ||
import mediathek.config.Daten; | ||
import mediathek.daten.DatenFilm; | ||
import mediathek.daten.ListeFilme; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
import java.util.Comparator; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
public class FilmDuplicateEvaluationTask implements Runnable { | ||
private static final Logger logger = LogManager.getLogger(); | ||
private final ListeFilme listeFilme; | ||
|
||
public FilmDuplicateEvaluationTask() { | ||
this.listeFilme = Daten.getInstance().getListeFilme(); | ||
} | ||
|
||
private void printDuplicateStatistics() { | ||
Stopwatch watch = Stopwatch.createStarted(); | ||
final var duplicates = listeFilme.parallelStream() | ||
.filter(DatenFilm::isDuplicate) | ||
.toList(); | ||
|
||
var statisticsEventList = Daten.getInstance().getDuplicateStatistics(); | ||
|
||
Map<String, Long> statisticsMap = duplicates.parallelStream().collect(Collectors.groupingBy(DatenFilm::getSender, Collectors.counting())); | ||
TransactionList<FilmStatistics> tList = new TransactionList<>(statisticsEventList); | ||
tList.getReadWriteLock().writeLock().lock(); | ||
tList.clear(); | ||
for (var sender : statisticsMap.keySet()) { | ||
tList.add(new FilmStatistics(sender, statisticsMap.get(sender))); | ||
} | ||
tList.getReadWriteLock().writeLock().unlock(); | ||
watch.stop(); | ||
|
||
logger.trace("Duplicate stream filter took: {}", watch); | ||
logger.trace("Number of duplicates: {}", duplicates.size()); | ||
} | ||
|
||
private void checkDuplicates() { | ||
logger.trace("Start Duplicate URL search"); | ||
final Set<String> urlCache = Sets.newConcurrentHashSet(); | ||
|
||
Stopwatch watch = Stopwatch.createStarted(); | ||
listeFilme.stream() | ||
.filter(f -> !f.isLivestream()) | ||
.sorted(new BigSenderPenaltyComparator()) | ||
.forEach(film -> { | ||
final var url = film.getUrlNormalQuality(); | ||
film.setDuplicate(urlCache.contains(url)); | ||
urlCache.add(url); | ||
}); | ||
watch.stop(); | ||
logger.trace("Duplicate URL search took: {}", watch); | ||
urlCache.clear(); | ||
} | ||
|
||
private void calculateCommonStats() { | ||
Stopwatch watch = Stopwatch.createStarted(); | ||
final var films = listeFilme.parallelStream() | ||
.filter(f -> !f.isLivestream()) | ||
.toList(); | ||
|
||
var statisticsList = Daten.getInstance().getCommonStatistics(); | ||
|
||
Map<String, Long> statisticsMap = films.parallelStream() | ||
.collect(Collectors.groupingBy(DatenFilm::getSender, Collectors.counting())); | ||
TransactionList<FilmStatistics> tList = new TransactionList<>(statisticsList); | ||
tList.getReadWriteLock().writeLock().lock(); | ||
tList.clear(); | ||
for (var sender : statisticsMap.keySet()) { | ||
tList.add(new FilmStatistics(sender, statisticsMap.get(sender))); | ||
} | ||
tList.getReadWriteLock().writeLock().unlock(); | ||
watch.stop(); | ||
|
||
logger.trace("common stats calculation took: {}", watch); | ||
logger.trace("Number of films: {}", films.size()); | ||
} | ||
|
||
@Override | ||
public void run() { | ||
calculateCommonStats(); | ||
checkDuplicates(); | ||
printDuplicateStatistics(); | ||
} | ||
|
||
private static class BigSenderPenaltyComparator implements Comparator<DatenFilm> { | ||
@Override | ||
public int compare(DatenFilm s1, DatenFilm s2) { | ||
// "ARD" und "ZDF" immer am Ende um die kleineren Mediatheken nicht zu benachteiligen | ||
final var s1_sender = s1.getSender(); | ||
final var s2_sender = s2.getSender(); | ||
if (s1_sender.equals("ARD") || s1_sender.equals("ZDF")) { | ||
return 1; | ||
} | ||
if (s2_sender.equals("ARD") || s2_sender.equals("ZDF")) { | ||
return -1; | ||
} | ||
// Alphabetisch sortieren für alle anderen | ||
return s1.compareTo(s2); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package mediathek.gui.duplicates; | ||
|
||
public record FilmStatistics(String sender, long count) { | ||
} |
Oops, something went wrong.