changelog and code simplification for #594

This commit is contained in:
Adrian Sampson 2014-03-08 13:58:37 -08:00
parent 3640045a3c
commit ef36890a4e
2 changed files with 13 additions and 6 deletions

View file

@ -60,9 +60,16 @@ def _splitstrip(string, delim=u','):
return [s.strip() for s in string.split(delim)]
def diff(item1, item2, attributes):
def diff(item1, item2):
"""Score two Item objects according to the Echo Nest numerical
fields.
"""
result = 0.0
for attr in attributes:
for attr in ATTRIBUTES:
if attr == 'bpm':
# BPM (tempo) is handled specially to normalize.
continue
try:
result += abs(
float(item1.get(attr, None)) -
@ -82,12 +89,9 @@ def diff(item1, item2, attributes):
def similar(lib, src_item, threshold=0.15, fmt='${difference}: ${path}'):
attributes = ATTRIBUTES.values()
attributes.remove('bpm')
for item in lib.items():
if item.path != src_item.path:
d = diff(item, src_item, attributes)
d = diff(item, src_item)
if d < threshold:
s = fmt.replace('${difference}', '{:2.2f}'.format(d))
ui.print_obj(item, lib, s)

View file

@ -18,6 +18,9 @@ New stuff:
johtso.
* :doc:`/plugins/smartplaylist`: Playlists can now be generated from multiple
queries (combined with "or" logic). Thanks to brilnius.
* :doc:`/plugins/echonest`: Echo Nest similarity now weights the tempo in
better proportion to other metrics. Also, options were added to specify
custom thresholds and output formats. Thanks to Adam M.
Fixes: