modified for old data schema workaround

This commit is contained in:
pythagoraswitch 2018-08-03 12:16:46 +02:00
parent 24bd733ef0
commit d31e0912e6

View file

@ -118,12 +118,16 @@ class Engine:
if len(prev_grid_list) < video_num:
return self.get_recommendations(user)
else:
if play_index is None:
video_indx = list(range(video_num))
random.shuffle(video_indx)
else:
# played index is excluded from the random shuffle and deterministically added to staySame pool.
video_indx = [*range(play_index)]+[*range(play_index+1,video_num)]
# video_indx = list(range(video_num))
random.shuffle(video_indx)
video_indx.append(play_index)
next_clip_index = video_indx[:nc]
next_playlist_index = video_indx[nc:nc+np]
stay_same_index = video_indx[nc+np:]
@ -131,6 +135,13 @@ class Engine:
rec_list = []
# select next clip for nextClip pool except when the playlist has only one 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.
next_playlist_index.append(next_clip_index)
break
else:
# if "playlist" and "playlistPostion" (if not, default to 0) exists in grid event
for playlist in self.playlists:
if playlist.get('name')== prev_grid_list[i].get('playlist'):
if len(playlist["clips"]) == 1:
@ -153,6 +164,8 @@ class Engine:
# randomly select playlists (excluding the playlists from the current grid once "playlist" is recorded for grid events)
# for nextPlaylist pool.
vids_exclude = [e.get("playlist") for e in prev_grid_list]
while None in vids_exclude:
vids_exclude.remove(None)
video = self.get_recommendations(user, vids_exclude)
rec_list += [(i, video[i]) for i in next_playlist_index]