diff --git a/recommendation_engine.py b/recommendation_engine.py index 62dd371..4792a1b 100644 --- a/recommendation_engine.py +++ b/recommendation_engine.py @@ -249,20 +249,20 @@ class Engine: random.shuffle(videos) return [{ 'clips': video['clips'], - 'position': random.randrange(len(video['clips'])), + 'position': random.choice([i for i in range(len(video["clips"])) if video["clips"][i].get("pass",False)!=True]), 'name': video['name'], 'tags': video['tags'], } for video in videos] def update_user_playlists(self, user, watch_cutoff = 0.9): - # Output: playlists with updated in/out time of clips that have been watched. + # Output: playlists with updated in/out time of clips that have been watched as well as "pass" indicators for the clips that has been watched for more than watch_cutoff. # 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] # + check (play, pause) pairs and eliminate unusual cases most likely due to a bug. - # + If (play, pause) pairs exceed XX(80-90?) percent of the clip length, eliminate the clip from the playlist. + # + If (play, pause) pairs exceed XX(80-90?) percent of the clip length, add "pass": True to the clip. # + 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. + # + If clips are all marked as "pass" in a playlist, elliminate the playlist from the user playlists. playlists = copy.deepcopy(self.playlists) play = {} watched = [] @@ -291,6 +291,8 @@ class Engine: if event["data"]["position"] >= cutoff_pos: watched.append((playlist["name"],i)) + playlist["clips"][i].get("pass",False) == True + else: if "orig_in" not in playlist["clips"][i]: # record the original "in" position to calculate cutoff position in the future @@ -308,8 +310,6 @@ class Engine: if playlist["name"] == k: if len(v) == len(playlist["clips"]): playlists.remove(playlist) - else: - playlist["clips"] = [playlist["clips"][i] for i in range(len(playlist["clips"])) if i not in v] break return(playlists)