PICARD-2805: Handle None length in Metadata.length_score

This commit is contained in:
Philipp Wolfer
2023-12-21 23:52:45 +01:00
parent 8199ab249c
commit 2bff23937a
2 changed files with 6 additions and 1 deletions

View File

@@ -206,6 +206,8 @@ class Metadata(MutableMapping):
@staticmethod
def length_score(a, b):
if a is None or b is None:
return 0.0
return (1.0 - min(abs(a - b),
LENGTH_SCORE_THRES_MS) / float(LENGTH_SCORE_THRES_MS))

View File

@@ -311,7 +311,10 @@ class CommonTests:
(20000, 20000, 1.0),
(20000, 30000, 0.666666666667),
(20000, 40000, 0.333333333333),
(20000, 50000, 0.0)]
(20000, 50000, 0.0),
(20000, None, 0.0),
(None, 2000, 0.0),
(None, None, 0.0)]
for (a, b, expected) in results:
actual = Metadata.length_score(a, b)
self.assertAlmostEqual(expected, actual,