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

@ -119,11 +119,15 @@ class Engine:
return self.get_recommendations(user) return self.get_recommendations(user)
else: 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. # 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 = [*range(play_index)]+[*range(play_index+1,video_num)]
# video_indx = list(range(video_num)) random.shuffle(video_indx)
random.shuffle(video_indx) video_indx.append(play_index)
video_indx.append(play_index)
next_clip_index = video_indx[:nc] next_clip_index = video_indx[:nc]
next_playlist_index = video_indx[nc:nc+np] next_playlist_index = video_indx[nc:nc+np]
stay_same_index = video_indx[nc+np:] stay_same_index = video_indx[nc+np:]
@ -131,28 +135,37 @@ class Engine:
rec_list = [] rec_list = []
# select next clip for nextClip pool except when the playlist has only one clip. # select next clip for nextClip pool except when the playlist has only one clip.
for i in next_clip_index: for i in next_clip_index:
for playlist in self.playlists: if prev_grid_list[i].get('playlist') is None:
if playlist.get('name')== prev_grid_list[i].get('playlist'): # add this to deal with the absence of "playlist" data in old grid event.
if len(playlist["clips"]) == 1: # If there's no playlist data recorded, add the nextClip pool to nextPlaylist pool.
next_playlist_index.append(i) next_playlist_index.append(next_clip_index)
break 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? else:
elif prev_grid_list[i].get('playlistPosition', 0) + 1 == len(playlist['clips']): # if "playlist" and "playlistPostion" (if not, default to 0) exists in grid event
playlist_pos = 0 for playlist in self.playlists:
else: if playlist.get('name')== prev_grid_list[i].get('playlist'):
playlist_pos = prev_grid_list[i].get('playlistPosition', 0) + 1 if len(playlist["clips"]) == 1:
next_playlist_index.append(i)
rec_list.append((i, { break
'clips': playlist['clips'], # Discuss how this behavour should be: should it switch to a new playlist if it is the end of the playlist clip sequence already?
# 'position': random.randrange(len(playlist['clips'])), elif prev_grid_list[i].get('playlistPosition', 0) + 1 == len(playlist['clips']):
'position': playlist_pos, playlist_pos = 0
'name': playlist['name'], else:
'tags': playlist['tags'], playlist_pos = prev_grid_list[i].get('playlistPosition', 0) + 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) # 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 = [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:
vids_exclude.remove(None)
video = self.get_recommendations(user, vids_exclude) video = self.get_recommendations(user, vids_exclude)
rec_list += [(i, video[i]) for i in next_playlist_index] rec_list += [(i, video[i]) for i in next_playlist_index]