implemented user keyword score ranking

This commit is contained in:
pythagoraswitch 2018-09-26 22:14:58 +02:00
parent 4bd4af703e
commit 024c1008fb

View file

@ -43,9 +43,9 @@ class Engine:
else:
self.state = {
'channels': {
'globalKeywords': {'locked': False, 'value': 7},
'userKeywords': {'locked': False, 'value': 7},
'screenings': {'locked': True, 'value': 2}
'globalKeywords': {'locked': False, 'value': 8},
'userKeywords': {'locked': False, 'value': 8}
# 'screenings': {'locked': True, 'value': 2}
},
'globalKeywords': {},
}
@ -55,6 +55,11 @@ class Engine:
'nextPlaylist': {'locked': False, 'value': 4},
'staySame': {'locked': False, 'value': 8}
}
if 'userKeywordsWeights' not in self.state:
self.state['userKeywordsWeights'] = {
'themeTags': {'locked': False, 'value': 0.3},
'characterTags': {'locked': False, 'value': 0.7}
}
self.update_keywords()
@property
@ -203,6 +208,7 @@ class Engine:
channels = {k: v.get('value', 0) for k, v in self.state['channels'].items()}
sliders = {k: v.get('value', 0) for k, v in self.state['globalKeywords'].items()}
gridChange = {k: v.get('value', 0) for k, v in self.state['gridChange'].items()}
userKeywordsWeights = {k: v.get('value', 1) for k, v in self.state['userKeywordsWeights'].items()}
# Exclude playlists from the most recent grid
playlists = copy.deepcopy(self.playlists)
@ -211,13 +217,26 @@ class Engine:
if playlist["name"] in vids_exclude:
playlists.remove(playlist)
# For each playlist, compute user keyword score
user_keywords = user.get('keywords', {})
# For each playlist, compute user keyword score by theme and character tags
user_keywords = copy.deepcopy(user.get('keywords', {}))
theme_tags = {k.lower():v for k,v in user_keywords.items() if not k.isupper()}
character_tags = {k:v for k,v in user_keywords.items() if k.isupper()}
# manually modify some of the user keywords to match the playlist tags
theme_tags["god"] = theme_tags.get("god - gods",0)
theme_tags["visionary"] = theme_tags.get("visionary - enlightenment",0)
theme_tags["enlightenment"] = theme_tags.get("visionary - enlightenment",0)
character_tags["FEDOR MIKHAILOVICH SOFRONOV"] = character_tags.get("FYODOR MIKHAILOVICH SOFRONOV",0)
character_tags["SHKABARNYA OLGA SERGEEVNA"] = character_tags.get("OLGA SERGEEVNA SHKABARNYA",0)
character_tags["VICTORIA OLEGOVNA SKITSKAYA"] = character_tags.get("VIKTORIA OLEGOVNA SKITSKAYA",0)
score = {}
for playlist in playlists:
score[playlist['name']] = random.random()
for tag in [tag for tag in playlist['tags'] if tag in user_keywords]:
score[playlist['name']] += user_keywords[tag]
score[playlist['name']] = random.random() * 0.001
for tag in playlist['tags']:
if tag in theme_tags:
score[playlist['name']] += theme_tags[tag] * userKeywordsWeights["themeTags"]
elif tag in character_tags:
score[playlist['name']] += character_tags[tag] * userKeywordsWeights["characterTags"]
# Select highest scoring playlists
playlists = sorted(
playlists,