added top scoring playlists for user and global keywords to dd-re debug view
This commit is contained in:
parent
319e4d384e
commit
e3c61853c3
1 changed files with 46 additions and 20 deletions
|
@ -110,14 +110,17 @@ class Engine:
|
||||||
|
|
||||||
# If the most recent event is "login," initialize grid videos.
|
# If the most recent event is "login," initialize grid videos.
|
||||||
if user.get('events', [{}])[0].get("event")=="login":
|
if user.get('events', [{}])[0].get("event")=="login":
|
||||||
|
rec = self.get_recommendations(playlists, user)
|
||||||
return {
|
return {
|
||||||
'user': {
|
'user': {
|
||||||
'keywords': user.get('keywords', {})
|
'keywords': user.get('keywords', {})
|
||||||
},
|
},
|
||||||
'videos': self.get_recommendations(playlists, user),
|
'videos': rec["videos"],
|
||||||
"_debug": {
|
"_debug": {
|
||||||
"top_user_keywords":top_user_keywords,
|
"top_user_keywords": top_user_keywords,
|
||||||
"top_user_characters":top_user_characters
|
"top_user_characters": top_user_characters,
|
||||||
|
"top_user_playlists": rec["top_user_playlists"],
|
||||||
|
"top_global_playlists": rec["top_global_playlists"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,14 +147,17 @@ class Engine:
|
||||||
|
|
||||||
# if there were no grid events for all, initialize all grids.
|
# if there were no grid events for all, initialize all grids.
|
||||||
if len(prev_grid_list) < video_num:
|
if len(prev_grid_list) < video_num:
|
||||||
|
rec = self.get_recommendations(playlists, user)
|
||||||
return {
|
return {
|
||||||
'user': {
|
'user': {
|
||||||
'keywords': user.get('keywords', {})
|
'keywords': user.get('keywords', {})
|
||||||
},
|
},
|
||||||
'videos': self.get_recommendations(playlists, user),
|
'videos': rec["videos"],
|
||||||
"_debug": {
|
"_debug": {
|
||||||
"top_user_keywords":top_user_keywords,
|
"top_user_keywords": top_user_keywords,
|
||||||
"top_user_characters":top_user_characters
|
"top_user_characters": top_user_characters,
|
||||||
|
"top_user_playlists": rec["top_user_playlists"],
|
||||||
|
"top_global_playlists": rec["top_global_playlists"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,8 +221,8 @@ class Engine:
|
||||||
vids_exclude = [e.get("playlist") for e in prev_grid_list]
|
vids_exclude = [e.get("playlist") for e in prev_grid_list]
|
||||||
while None in vids_exclude:
|
while None in vids_exclude:
|
||||||
vids_exclude.remove(None)
|
vids_exclude.remove(None)
|
||||||
video = self.get_recommendations(playlists, user, vids_exclude)
|
rec = self.get_recommendations(playlists, user, vids_exclude)
|
||||||
rec_list += [(i, video[i]) for i in next_playlist_index]
|
rec_list += [(i, rec['videos'][i]) for i in next_playlist_index]
|
||||||
|
|
||||||
|
|
||||||
rec_list = sorted(rec_list, key=lambda k:k[0])
|
rec_list = sorted(rec_list, key=lambda k:k[0])
|
||||||
|
@ -227,8 +233,10 @@ class Engine:
|
||||||
},
|
},
|
||||||
'videos': videos_,
|
'videos': videos_,
|
||||||
"_debug": {
|
"_debug": {
|
||||||
"top_user_keywords":top_user_keywords,
|
"top_user_keywords": top_user_keywords,
|
||||||
"top_user_characters":top_user_characters
|
"top_user_characters": top_user_characters,
|
||||||
|
"top_user_playlists": rec["top_user_playlists"],
|
||||||
|
"top_global_playlists": rec["top_global_playlists"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,6 +277,13 @@ class Engine:
|
||||||
playlists,
|
playlists,
|
||||||
key=lambda playlist: -score[playlist['name']]
|
key=lambda playlist: -score[playlist['name']]
|
||||||
)
|
)
|
||||||
|
# Record the following for debug view input
|
||||||
|
top_user_playlists = [{
|
||||||
|
'name': playlist['name'],
|
||||||
|
'tags': playlist['tags']
|
||||||
|
'score': score[playlist['name']]
|
||||||
|
} for playlist in playlists[:channels['userKeywords']]]
|
||||||
|
|
||||||
videos = playlists[:channels['userKeywords']]
|
videos = playlists[:channels['userKeywords']]
|
||||||
playlists = playlists[channels['userKeywords']:]
|
playlists = playlists[channels['userKeywords']:]
|
||||||
# For each playlist, compute global keyword score
|
# For each playlist, compute global keyword score
|
||||||
|
@ -282,15 +297,26 @@ class Engine:
|
||||||
playlists,
|
playlists,
|
||||||
key=lambda playlist: -score[playlist['name']]
|
key=lambda playlist: -score[playlist['name']]
|
||||||
)
|
)
|
||||||
|
# Record the following for debug view input
|
||||||
|
top_global_playlists = [{
|
||||||
|
'name': playlist['name'],
|
||||||
|
'tags': playlist['tags']
|
||||||
|
'score': score[playlist['name']]
|
||||||
|
} for playlist in playlists[:channels['globalKeywords']]]
|
||||||
|
|
||||||
videos += playlists[:16 - channels['userKeywords']]
|
videos += playlists[:16 - channels['userKeywords']]
|
||||||
# Shuffle playlists (randomize layout) and shift clips (randomize start)
|
# Shuffle playlists (randomize layout) and shift clips (randomize start)
|
||||||
random.shuffle(videos)
|
random.shuffle(videos)
|
||||||
return [{
|
return {
|
||||||
|
'videos': [{
|
||||||
'clips': video['clips'],
|
'clips': video['clips'],
|
||||||
'position': random.choice([i for i in range(len(video["clips"])) if video["clips"][i].get("pass",False)!=True]),
|
'position': random.choice([i for i in range(len(video["clips"])) if not video["clips"][i].get("pass")]),
|
||||||
'name': video['name'],
|
'name': video['name'],
|
||||||
'tags': video['tags'],
|
'tags': video['tags'],
|
||||||
} for video in videos]
|
} for video in videos],
|
||||||
|
"top_user_playlists":top_user_playlists,
|
||||||
|
"top_global_playlists": top_global_playlists
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def update_user_playlists(self, user, watch_cutoff = 0.9):
|
def update_user_playlists(self, user, watch_cutoff = 0.9):
|
||||||
|
@ -349,7 +375,7 @@ class Engine:
|
||||||
|
|
||||||
|
|
||||||
def get_next(self, user, position):
|
def get_next(self, user, position):
|
||||||
# Update self_playlists first to reflect changes
|
# Update self_playlists to reflect user log history
|
||||||
playlists = self.update_user_playlists(user)
|
playlists = self.update_user_playlists(user)
|
||||||
|
|
||||||
grid_events = {}
|
grid_events = {}
|
||||||
|
@ -362,8 +388,8 @@ class Engine:
|
||||||
break
|
break
|
||||||
prev_grid_list = sorted([v for v in grid_events.values()], key=lambda k:k['index'])
|
prev_grid_list = sorted([v for v in grid_events.values()], key=lambda k:k['index'])
|
||||||
vids_exclude = [e.get("playlist") for e in prev_grid_list]
|
vids_exclude = [e.get("playlist") for e in prev_grid_list]
|
||||||
video = self.get_recommendations(playlists, user, vids_exclude)[position]
|
rec = self.get_recommendations(playlists, user, vids_exclude)
|
||||||
return video
|
return rec["videos"][position]
|
||||||
|
|
||||||
def update_state(self, data):
|
def update_state(self, data):
|
||||||
for key in data:
|
for key in data:
|
||||||
|
|
Loading…
Reference in a new issue