mirror of
https://github.com/beetbox/beets.git
synced 2026-02-12 02:12:10 +01:00
Add Distance.raw_distance, to compliment max_distance.
This commit is contained in:
parent
51f40d26dc
commit
ac4e86981f
2 changed files with 19 additions and 5 deletions
|
|
@ -308,14 +308,11 @@ class Distance(object):
|
|||
|
||||
@property
|
||||
def distance(self):
|
||||
"""Returns an overall weighted distance across all penalties.
|
||||
"""Returns a weighted and normalised distance across all penalties.
|
||||
"""
|
||||
dist = 0.0
|
||||
for key, penalty in self._penalties.iteritems():
|
||||
dist += sum(penalty) * weights[key].as_number()
|
||||
dist_max = self.max_distance
|
||||
if dist_max:
|
||||
return dist / dist_max
|
||||
return self.raw_distance / self.max_distance
|
||||
return 0.0
|
||||
|
||||
@property
|
||||
|
|
@ -327,6 +324,15 @@ class Distance(object):
|
|||
dist_max += len(penalty) * weights[key].as_number()
|
||||
return dist_max
|
||||
|
||||
@property
|
||||
def raw_distance(self):
|
||||
"""Returns the raw (denormalised) distance.
|
||||
"""
|
||||
dist_raw = 0.0
|
||||
for key, penalty in self._penalties.iteritems():
|
||||
dist_raw += sum(penalty) * weights[key].as_number()
|
||||
return dist_raw
|
||||
|
||||
@property
|
||||
def sorted(self):
|
||||
"""Returns a list of (dist, key) pairs, with `dist` being the weighted
|
||||
|
|
|
|||
|
|
@ -200,6 +200,14 @@ class DistanceTest(unittest.TestCase):
|
|||
self.dist.add('medium', 0.0)
|
||||
self.assertEqual(self.dist.max_distance, 5.0)
|
||||
|
||||
def test_raw_distance(self):
|
||||
config['match']['distance_weights']['album'] = 3.0
|
||||
config['match']['distance_weights']['medium'] = 1.0
|
||||
self.dist.add('album', 0.5)
|
||||
self.dist.add('medium', 0.25)
|
||||
self.dist.add('medium', 0.5)
|
||||
self.assertEqual(self.dist.raw_distance, 2.25)
|
||||
|
||||
def test_sorted(self):
|
||||
config['match']['distance_weights']['album'] = 4.0
|
||||
config['match']['distance_weights']['medium'] = 2.0
|
||||
|
|
|
|||
Loading…
Reference in a new issue