From ab7de69dcd8540acf22aa4231f5b58145f644efa Mon Sep 17 00:00:00 2001 From: Xincognito10 Date: Sun, 3 Jun 2018 04:56:50 -0500 Subject: [PATCH] PICARD-1122: Fix preferred release types not working This commit implements an algorithm to fetch a release that matches the preferred release types outlined in the settings page. Further testing is required. --- picard/metadata.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/picard/metadata.py b/picard/metadata.py index 6ac303700..8e2aa5266 100644 --- a/picard/metadata.py +++ b/picard/metadata.py @@ -191,12 +191,22 @@ class Metadata(dict): parts.append((score, weights["format"])) if "releasetype" in weights: + # This section generates a score that determines how likely this release will be selected in a lookup. + # The score goes from 0 to 1 with 1 being the most likely to be chosen and 0 the least likely + # This score is based on the preferences of release-types found in this release + # This algorithm works by taking the scores of the primary type (and secondary if found) and averages them + # If no types are found, it is set to the score of the 'Other' type or 0.5 if 'Other' doesnt exist + type_scores = dict(config.setting["release_type_scores"]) + score = 0.0 + other_score = type_scores.get('Other', 0.5) if 'release-group' in release and 'primary-type' in release['release-group']: - release_type = release['release-group']['primary-type'] - score = type_scores.get(release_type, type_scores.get('Other', 0.5)) - else: - score = 0.0 + types_found = [release['release-group']['primary-type']] + if 'secondary-types' in release['release-group']: + types_found += release['release-group']['secondary-types'] + for release_type in types_found: + score += type_scores.get(release_type, other_score) + score /= len(types_found) parts.append((score, weights["releasetype"])) rg = QObject.tagger.get_release_group_by_id(release['release-group']['id'])