From 001e377003f9858f99f0d76fc7a0395f25238002 Mon Sep 17 00:00:00 2001 From: pythagoraswitch Date: Tue, 20 Nov 2018 01:41:37 +0100 Subject: [PATCH] bug fixes --- recommendation_engine.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/recommendation_engine.py b/recommendation_engine.py index 3f675aa..ceca1be 100644 --- a/recommendation_engine.py +++ b/recommendation_engine.py @@ -33,6 +33,10 @@ class Engine: if os.path.exists(filename): with open(filename) as f: self.playlists = json.load(f) + # ## the following is for testing purpose. + # for playlist in self.playlists: + # for clip in playlist["clips"]: + # clip["pass"] = bool(random.getrandbits(1)) else: self.playlists = [] @@ -281,7 +285,6 @@ class Engine: # + If clips are all marked as "pass" in a playlist, elliminate the playlist from the user playlists. 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 # The current max time of a clip duration is 10379.383333377269 from "DDLaunch: Erik Verlinde, Gravity as an emergent force (1956)" # A user could potentially spend more than 3 hours if they keep watching after the clip enters into the subsequent "scene" @@ -306,8 +309,7 @@ class Engine: cutoff_pos = (playlist["clips"][i]["out"]-playlist["clips"][i]["orig_in"])*watch_cutoff + playlist["clips"][i]["orig_in"] if event["data"]["position"] >= cutoff_pos: - watched.append((playlist["name"],i)) - playlist["clips"][i].get("pass",False) == True + playlist["clips"][i]["pass"] = True else: if "orig_in" not in playlist["clips"][i]: @@ -318,15 +320,14 @@ class Engine: break play = {} - d_watched = defaultdict(set) - for k, v in watched: - d_watched[k].add(v) - for k, v in d_watched.items(): - for playlist in playlists: - if playlist["name"] == k: - if len(v) == len(playlist["clips"]): - playlists.remove(playlist) - break + for playlist in playlists.copy(): + unwatched = [clip for clip in playlist["clips"] if not clip.get("pass")] + if not unwatched: + playlists.remove(playlist) + # If the number of playlists is reduced to 30, reset it to the original. + if len(playlists) < 30: + playlists = copy.deepcopy(self.playlists) + return(playlists)