added random option for userKeywordWeights
This commit is contained in:
parent
b749d66bac
commit
6899cc5d37
1 changed files with 15 additions and 6 deletions
|
@ -54,14 +54,15 @@ class Engine:
|
||||||
}
|
}
|
||||||
if 'gridChange' not in self.state:
|
if 'gridChange' not in self.state:
|
||||||
self.state['gridChange'] = {
|
self.state['gridChange'] = {
|
||||||
'nextClip': {'locked': True, 'value': 4},
|
'nextClip': {'locked': False, 'value': 5},
|
||||||
'nextPlaylist': {'locked': False, 'value': 4},
|
'nextPlaylist': {'locked': False, 'value': 8},
|
||||||
'staySame': {'locked': False, 'value': 8}
|
'staySame': {'locked': True, 'value': 3}
|
||||||
}
|
}
|
||||||
if 'userKeywordsWeights' not in self.state:
|
if 'userKeywordsWeights' not in self.state:
|
||||||
self.state['userKeywordsWeights'] = {
|
self.state['userKeywordsWeights'] = {
|
||||||
'themeTags': {'locked': False, 'value': 0.3},
|
'themeTags': {'locked': False, 'value': 0.3},
|
||||||
'characterTags': {'locked': False, 'value': 0.7}
|
'characterTags': {'locked': False, 'value': 0.7},
|
||||||
|
'random' : {'locked': False, 'value': True}
|
||||||
}
|
}
|
||||||
self.update_keywords()
|
self.update_keywords()
|
||||||
|
|
||||||
|
@ -253,6 +254,14 @@ class Engine:
|
||||||
if playlist["name"] in vids_exclude:
|
if playlist["name"] in vids_exclude:
|
||||||
playlists.remove(playlist)
|
playlists.remove(playlist)
|
||||||
|
|
||||||
|
# Generate random weights if random option is chosen in the dashboard:
|
||||||
|
if userKeywordsWeights['random']:
|
||||||
|
themeWeights = random.random()
|
||||||
|
charWeights = 1-themeWeights
|
||||||
|
else:
|
||||||
|
themeWeights = userKeywordsWeights['themeTags']
|
||||||
|
charWeights = userKeywordsWeights['characterTags']
|
||||||
|
|
||||||
# For each playlist, compute user keyword score by theme and character tags
|
# For each playlist, compute user keyword score by theme and character tags
|
||||||
user_keywords = copy.deepcopy(user.get('keywords', {}))
|
user_keywords = copy.deepcopy(user.get('keywords', {}))
|
||||||
theme_tags = {k.lower():v for k,v in user_keywords.items() if not k.isupper()}
|
theme_tags = {k.lower():v for k,v in user_keywords.items() if not k.isupper()}
|
||||||
|
@ -269,9 +278,9 @@ class Engine:
|
||||||
score[playlist['name']] = random.random() * 0.001
|
score[playlist['name']] = random.random() * 0.001
|
||||||
for tag in playlist['tags']:
|
for tag in playlist['tags']:
|
||||||
if tag in theme_tags:
|
if tag in theme_tags:
|
||||||
score[playlist['name']] += theme_tags[tag] * userKeywordsWeights["themeTags"]
|
score[playlist['name']] += theme_tags[tag] * themeWeights
|
||||||
elif tag in character_tags:
|
elif tag in character_tags:
|
||||||
score[playlist['name']] += character_tags[tag] * userKeywordsWeights["characterTags"]
|
score[playlist['name']] += character_tags[tag] * charWeights
|
||||||
# Select highest scoring playlists
|
# Select highest scoring playlists
|
||||||
playlists = sorted(
|
playlists = sorted(
|
||||||
playlists,
|
playlists,
|
||||||
|
|
Loading…
Reference in a new issue