From 83af674af95bc4e1e65c35d66e9dd3015cd52d6c Mon Sep 17 00:00:00 2001 From: pythagoraswitch Date: Wed, 25 Jul 2018 16:07:31 +0200 Subject: [PATCH] minor additions to incorporate the future data scheme change --- recommendation_engine.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/recommendation_engine.py b/recommendation_engine.py index 14fdbc7..88a241b 100644 --- a/recommendation_engine.py +++ b/recommendation_engine.py @@ -110,12 +110,13 @@ class Engine: else: # Once the "index" is added to play event data, played index will be excluded from the random shuffle # and deterministically added to staySame pool. + # video_indx = [*range(playIndex)]+[*range(playIndex+1,video_num)] video_indx = list(range(video_num)) random.shuffle(video_indx) rec_list = [] # For now, randomly choose a clip in the same playlist instead of switching to the next clip. - # This will be changed once the clip position is tracked in the user data. + # This will be changed once the clip position is tracked in the user data as "playlistPostion" for i in video_indx[:nc]: if prev_grid_list[i].get('playlist') is None: # add this to deal with the absence of "playlist" data in a grid event temporarily. @@ -124,24 +125,32 @@ class Engine: nc = 0 break else: - # if "playlist" data exists in grid event (it should be in the future) + # if "playlist" and "playlistPostion" data exists in grid event (it should be in the future) for playlist in playlists: if playlist.get('name')== prev_grid_list[i].get('playlist'): + # Discuss how this behavour should be: should it switch to a new playlist if it is the end of the playlist clip sequence already? + # if prev_grid_list[i].get('index') == len(playlist['clips']): + # playlist_pos = 0 + # else: + # playlist_pos = prev_grid_list[i].get('index') + 1 + rec_list.append((i, { 'clips': playlist['clips'], 'position': random.randrange(len(playlist['clips'])), + # 'position': playlist_pos, 'name': playlist['name'], 'tags': playlist['tags'], })) # randomly select playlists (excluding the playlists from the current grid once "playlist" is recorded for grid events) - # for nextPlaylist pool + # for nextPlaylist pool. vids_exclude = [] # vids_exclude = [e.get("playlist") for e in prev_grid_list] video = self.get_recommendations(user, vids_exclude) rec_list += [(i, video[i]) for i in video_indx[nc:nc+np]] #staySame pool + # video_indx.append(playIndex) rec_list += [(i,{}) for i in video_indx[nc+np:]] rec_list = sorted(rec_list, key=lambda k:k[0])