added top scoring keywords to debug view output
This commit is contained in:
parent
001e377003
commit
2405b8b7c7
1 changed files with 21 additions and 3 deletions
|
@ -97,13 +97,23 @@ class Engine:
|
||||||
def get_videos(self, user):
|
def get_videos(self, user):
|
||||||
# Update self_playlists first to reflect changes
|
# Update self_playlists first to reflect changes
|
||||||
playlists = self.update_user_playlists(user)
|
playlists = self.update_user_playlists(user)
|
||||||
|
# Get the user keyword scores for debug view
|
||||||
|
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()}
|
||||||
|
top_user_keywords = sorted([(k,v) for (k,v) in theme_tags.items()], key=lambda kv: kv[1])[-5:]
|
||||||
|
top_user_characters = sorted([(k,v) for (k,v) in character_tags.items()], key=lambda kv: kv[1])[-5:]
|
||||||
|
|
||||||
if user.get('events', [{}])[0].get("event")=="login":
|
if user.get('events', [{}])[0].get("event")=="login":
|
||||||
return {
|
return {
|
||||||
'user': {
|
'user': {
|
||||||
'keywords': user.get('keywords', {})
|
'keywords': user.get('keywords', {})
|
||||||
},
|
},
|
||||||
'videos': self.get_recommendations(playlists, user)
|
'videos': self.get_recommendations(playlists, user),
|
||||||
|
"_debug": {
|
||||||
|
"top_user_keywords":top_user_keywords,
|
||||||
|
"top_user_characters":top_user_characters
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
channels = {k: v.get('value', 0) for k, v in self.state['channels'].items()}
|
channels = {k: v.get('value', 0) for k, v in self.state['channels'].items()}
|
||||||
|
@ -133,7 +143,11 @@ class Engine:
|
||||||
'user': {
|
'user': {
|
||||||
'keywords': user.get('keywords', {})
|
'keywords': user.get('keywords', {})
|
||||||
},
|
},
|
||||||
'videos': self.get_recommendations(playlists, user)
|
'videos': self.get_recommendations(playlists, user),
|
||||||
|
"_debug": {
|
||||||
|
"top_user_keywords":top_user_keywords,
|
||||||
|
"top_user_characters":top_user_characters
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
@ -211,7 +225,11 @@ class Engine:
|
||||||
'user': {
|
'user': {
|
||||||
'keywords': user.get('keywords', {})
|
'keywords': user.get('keywords', {})
|
||||||
},
|
},
|
||||||
'videos': videos_
|
'videos': videos_,
|
||||||
|
"_debug": {
|
||||||
|
"top_user_keywords":top_user_keywords,
|
||||||
|
"top_user_characters":top_user_characters
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue