use update_user_playlists to limit playlist per user

This commit is contained in:
j 2018-11-19 19:52:00 +01:00
parent d51748b1d0
commit 4fadcf7927
1 changed files with 10 additions and 10 deletions

View File

@ -92,14 +92,14 @@ class Engine:
def get_videos(self, user):
# Update self_playlists first to reflect changes
update_user_playlists(self.playlists, user)
playlists = self.update_user_playlists(user)
if user.get('events', [{}])[0].get("event")=="login":
return {
'user': {
'keywords': user.get('keywords', {})
},
'videos': self.get_recommendations(user)
'videos': self.get_recommendations(playlists, user)
}
channels = {k: v.get('value', 0) for k, v in self.state['channels'].items()}
@ -129,7 +129,7 @@ class Engine:
'user': {
'keywords': user.get('keywords', {})
},
'videos': self.get_recommendations(user)
'videos': self.get_recommendations(playlists, user)
}
else:
@ -155,7 +155,7 @@ class Engine:
next_playlist_index.append(next_clip_index)
break
else:
for playlist in self.playlists:
for playlist in playlists:
if playlist.get('name')== prev_grid_list[i].get('playlist'):
if len(playlist["clips"]) == 1:
next_playlist_index.append(i)
@ -179,7 +179,7 @@ class Engine:
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(playlists, user, vids_exclude)
rec_list += [(i, video[i]) for i in next_playlist_index]
#staySame pool
@ -195,14 +195,13 @@ class Engine:
}
def get_recommendations(self, user, vids_exclude = []):
def get_recommendations(self, playlists, user, vids_exclude = []):
channels = {k: v.get('value', 0) for k, v in self.state['channels'].items()}
sliders = {k: v.get('value', 0) for k, v in self.state['globalKeywords'].items()}
gridChange = {k: v.get('value', 0) for k, v in self.state['gridChange'].items()}
userKeywordsWeights = {k: v.get('value', 1) for k, v in self.state['userKeywordsWeights'].items()}
# Exclude playlists from the most recent grid
playlists = copy.deepcopy(self.playlists)
if len(vids_exclude) > 0:
for playlist in playlists:
if playlist["name"] in vids_exclude:
@ -256,7 +255,7 @@ class Engine:
} for video in videos]
def update_user_playlists(playlists, user, watch_cutoff = 0.9):
def update_user_playlists(user, watch_cutoff = 0.9):
# Output: playlists with updated in/out time of clips that have been watched.
# Watched is defined as a video being played in full screen.
# "watch_cutoff" parameter: the portion of the clip duration to be determined as watched the whole clip. should be [0,1]
@ -264,6 +263,7 @@ class Engine:
# + If (play, pause) pairs exceed XX(80-90?) percent of the clip length, eliminate the clip from the playlist.
# + Otherwise, find the last pause position of a clip and record it as "in" position of the clip.
# + If the clips are all eliminated from a playlist, eliminate the playlist.
playlists = copy.deepcopy(self.playlists)
play = {}
watched = []
clip_max_dur = 10800 # = 3 hours; arbitrary max duration allowed for (pause time - play time) to detect outlier/bugs
@ -316,7 +316,7 @@ class Engine:
def get_next(self, user, position):
# Update self_playlists first to reflect changes
update_user_playlists(self.playlists, user)
playlists = self.update_user_playlists(user)
grid_events = {}
video_num = 16
@ -328,7 +328,7 @@ class Engine:
break
prev_grid_list = sorted([v for v in grid_events.values()], key=lambda k:k['index'])
vids_exclude = [e.get("playlist") for e in prev_grid_list]
video = self.get_recommendations(user, vids_exclude)[position]
video = self.get_recommendations(playlists, user, vids_exclude)[position]
return video
def update_state(self, data):