bug fixes

This commit is contained in:
pythagoraswitch 2018-11-20 01:41:37 +01:00
parent 21781747a2
commit 001e377003

View file

@ -33,6 +33,10 @@ class Engine:
if os.path.exists(filename): if os.path.exists(filename):
with open(filename) as f: with open(filename) as f:
self.playlists = json.load(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: else:
self.playlists = [] 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. # + If clips are all marked as "pass" in a playlist, elliminate the playlist from the user playlists.
playlists = copy.deepcopy(self.playlists) playlists = copy.deepcopy(self.playlists)
play = {} play = {}
watched = []
clip_max_dur = 10800 # = 3 hours; arbitrary max duration allowed for (pause time - play time) to detect outlier/bugs 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)" # 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" # 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"] cutoff_pos = (playlist["clips"][i]["out"]-playlist["clips"][i]["orig_in"])*watch_cutoff + playlist["clips"][i]["orig_in"]
if event["data"]["position"] >= cutoff_pos: if event["data"]["position"] >= cutoff_pos:
watched.append((playlist["name"],i)) playlist["clips"][i]["pass"] = True
playlist["clips"][i].get("pass",False) == True
else: else:
if "orig_in" not in playlist["clips"][i]: if "orig_in" not in playlist["clips"][i]:
@ -318,15 +320,14 @@ class Engine:
break break
play = {} play = {}
d_watched = defaultdict(set) for playlist in playlists.copy():
for k, v in watched: unwatched = [clip for clip in playlist["clips"] if not clip.get("pass")]
d_watched[k].add(v) if not unwatched:
for k, v in d_watched.items():
for playlist in playlists:
if playlist["name"] == k:
if len(v) == len(playlist["clips"]):
playlists.remove(playlist) playlists.remove(playlist)
break # 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) return(playlists)