From ecf9cf96ddb87df7082a61fbbdcbbfa366e05b95 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Thu, 11 Aug 2016 20:27:18 +0800 Subject: [PATCH] Make sure TimeStampMetric works the same for all epochs --- .../net/filebot/similarity/EpisodeMetrics.java | 7 ++++--- .../net/filebot/similarity/TimeStampMetric.java | 17 ++++++++++++----- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/source/net/filebot/similarity/EpisodeMetrics.java b/source/net/filebot/similarity/EpisodeMetrics.java index e2da2b52..7f076109 100644 --- a/source/net/filebot/similarity/EpisodeMetrics.java +++ b/source/net/filebot/similarity/EpisodeMetrics.java @@ -512,13 +512,14 @@ public enum EpisodeMetrics implements SimilarityMetric { }), // Match by file last modified and episode release dates - TimeStamp(new TimeStampMetric() { + TimeStamp(new TimeStampMetric(10, ChronoUnit.YEARS) { @Override 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); - return f >= 0.9 ? 1 : f >= 0 ? 0 : -1; + + return f >= 0.75 ? 1 : f >= 0 ? 0 : -1; } private long getTimeStamp(SimpleDate date) { diff --git a/source/net/filebot/similarity/TimeStampMetric.java b/source/net/filebot/similarity/TimeStampMetric.java index deac557f..96c18eb7 100644 --- a/source/net/filebot/similarity/TimeStampMetric.java +++ b/source/net/filebot/similarity/TimeStampMetric.java @@ -4,21 +4,28 @@ package net.filebot.similarity; import java.io.File; import java.nio.file.Files; import java.nio.file.attribute.BasicFileAttributes; +import java.time.temporal.ChronoUnit; public class TimeStampMetric implements SimilarityMetric { + private long epoch; + + public TimeStampMetric(int i, ChronoUnit unit) { + this.epoch = unit.getDuration().multipliedBy(i).toMillis(); + } + @Override public float getSimilarity(Object o1, Object o2) { long t1 = getTimeStamp(o1); long t2 = getTimeStamp(o2); - if (t1 <= 0 || t2 <= 0) - return -1; + if (t1 > 0 && t2 > 0) { + float delta = Math.abs(t1 - t2); - float min = Math.min(t1, t2); - float max = Math.max(t1, t2); + return delta > epoch ? 1 : 1 - (delta / epoch); + } - return min / max; + return -1; } public long getTimeStamp(Object object) {