modified for old data schema workaround
This commit is contained in:
parent
24bd733ef0
commit
d31e0912e6
1 changed files with 35 additions and 22 deletions
|
@ -118,12 +118,16 @@ class Engine:
|
||||||
if len(prev_grid_list) < video_num:
|
if len(prev_grid_list) < video_num:
|
||||||
return self.get_recommendations(user)
|
return self.get_recommendations(user)
|
||||||
|
|
||||||
|
else:
|
||||||
|
if play_index is None:
|
||||||
|
video_indx = list(range(video_num))
|
||||||
|
random.shuffle(video_indx)
|
||||||
else:
|
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,6 +135,13 @@ 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:
|
||||||
|
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:
|
for playlist in self.playlists:
|
||||||
if playlist.get('name')== prev_grid_list[i].get('playlist'):
|
if playlist.get('name')== prev_grid_list[i].get('playlist'):
|
||||||
if len(playlist["clips"]) == 1:
|
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)
|
# 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]
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue