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.
This commit is contained in:
Xincognito10
2018-06-03 04:56:50 -05:00
committed by Sambhav Kothari
parent 715713ec75
commit ab7de69dcd

View File

@@ -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'])