1
0
mirror of https://github.com/mitb-archive/filebot synced 2025-01-14 07:18:03 -05:00

Make sure TimeStampMetric works the same for all epochs

This commit is contained in:
Reinhard Pointner 2016-08-11 20:27:18 +08:00
parent cd01fe26bf
commit ecf9cf96dd
2 changed files with 16 additions and 8 deletions

View File

@ -512,13 +512,14 @@ public enum EpisodeMetrics implements SimilarityMetric {
}), }),
// Match by file last modified and episode release dates // Match by file last modified and episode release dates
TimeStamp(new TimeStampMetric() { TimeStamp(new TimeStampMetric(10, ChronoUnit.YEARS) {
@Override @Override
public float getSimilarity(Object o1, Object o2) { public float getSimilarity(Object o1, Object o2) {
// adjust differentiation accuracy to about 3 years // adjust differentiation accuracy to about 2.5 years
float f = super.getSimilarity(o1, o2); float f = super.getSimilarity(o1, o2);
return f >= 0.9 ? 1 : f >= 0 ? 0 : -1;
return f >= 0.75 ? 1 : f >= 0 ? 0 : -1;
} }
private long getTimeStamp(SimpleDate date) { private long getTimeStamp(SimpleDate date) {

View File

@ -4,21 +4,28 @@ package net.filebot.similarity;
import java.io.File; import java.io.File;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.attribute.BasicFileAttributes;
import java.time.temporal.ChronoUnit;
public class TimeStampMetric implements SimilarityMetric { public class TimeStampMetric implements SimilarityMetric {
private long epoch;
public TimeStampMetric(int i, ChronoUnit unit) {
this.epoch = unit.getDuration().multipliedBy(i).toMillis();
}
@Override @Override
public float getSimilarity(Object o1, Object o2) { public float getSimilarity(Object o1, Object o2) {
long t1 = getTimeStamp(o1); long t1 = getTimeStamp(o1);
long t2 = getTimeStamp(o2); long t2 = getTimeStamp(o2);
if (t1 <= 0 || t2 <= 0) if (t1 > 0 && t2 > 0) {
return -1; float delta = Math.abs(t1 - t2);
float min = Math.min(t1, t2); return delta > epoch ? 1 : 1 - (delta / epoch);
float max = Math.max(t1, t2); }
return min / max; return -1;
} }
public long getTimeStamp(Object object) { public long getTimeStamp(Object object) {