From 21781747a2448e59100a1a230a72eef008b2b17f Mon Sep 17 00:00:00 2001 From: pythagoraswitch Date: Mon, 19 Nov 2018 22:24:41 +0100 Subject: [PATCH] adjusted to the variable 'pass' for nextClip and staySame cases in get_videos --- recommendation_engine.py | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/recommendation_engine.py b/recommendation_engine.py index 4792a1b..3f675aa 100644 --- a/recommendation_engine.py +++ b/recommendation_engine.py @@ -147,25 +147,41 @@ class Engine: stay_same_index = video_indx[nc+np:] rec_list = [] - # select next clip for nextClip pool except when the playlist has only one clip. + + # Make sure the playlist exists for staySame pool; otherwise add it to nextPlaylist pool. + for i in stay_same_index: + if prev_grid_list[i].get("playlist") not in [playlist["name"] for playlist in playlists]: + next_playlist_index.append(stay_same_index) + + # select next clip for nextClip pool except when the playlist has only one clip. It skips the clip with "pass":True when selecting the next clip. for i in next_clip_index: - if prev_grid_list[i].get('playlist') is None: - # add this to deal with the absence of "playlist" data in old grid event. - # If there's no playlist data recorded, add the nextClip pool to nextPlaylist pool. + if prev_grid_list[i].get("playlist") not in [playlist["name"] for playlist in playlists]: + # add this to deal with the absence of "playlist" data in old grid event or the case where the playlist has been eliminated. next_playlist_index.append(next_clip_index) break else: for playlist in playlists: if playlist.get('name')== prev_grid_list[i].get('playlist'): + unwatched_clips_indx = [j for j in range(len(playlist["clips"])) if playlist["clips"][j].get("pass",False)!=True] if len(playlist["clips"]) == 1: next_playlist_index.append(i) break # Discuss how this behavour should be: should it switch to a new playlist if it is the end of the playlist clip sequence already? elif prev_grid_list[i].get('playlistPosition', 0) + 1 == len(playlist['clips']): - playlist_pos = 0 + if unwatched_clips_indx[0] != prev_grid_list[i]['playlistPosition']: + playlist_pos = unwatched_clips_indx[0] + else: + next_playlist_index.append(i) else: - playlist_pos = prev_grid_list[i].get('playlistPosition', 0) + 1 - + if len([j for j in unwatched_clips_indx if j > prev_grid_list[i]['playlistPosition']]) == 0: + if unwatched_clips_indx[0] != prev_grid_list[i]['playlistPosition']: + playlist_pos = unwatched_clips_indx[0] + else: + next_playlist_index.append(i) + else: + playlist_pos = [j for j in unwatched_clips_indx if j > prev_grid_list[i]['playlistPosition']][0] + + rec_list.append((i, { 'clips': playlist['clips'], # 'position': random.randrange(len(playlist['clips'])),