adjusted to add the variable 'pass' for the clips that has been watched more than cutoff time

This commit is contained in:
pythagoraswitch 2018-11-19 21:07:04 +01:00
parent b5172bbc96
commit 4c2cb60d9c

View file

@ -249,20 +249,20 @@ class Engine:
random.shuffle(videos) random.shuffle(videos)
return [{ return [{
'clips': video['clips'], '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'], 'name': video['name'],
'tags': video['tags'], 'tags': video['tags'],
} for video in videos] } for video in videos]
def update_user_playlists(self, user, watch_cutoff = 0.9): 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. # 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] # "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. # + 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. # + 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) playlists = copy.deepcopy(self.playlists)
play = {} play = {}
watched = [] watched = []
@ -291,6 +291,8 @@ class Engine:
if event["data"]["position"] >= cutoff_pos: if event["data"]["position"] >= cutoff_pos:
watched.append((playlist["name"],i)) watched.append((playlist["name"],i))
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]:
# record the original "in" position to calculate cutoff position in the future # record the original "in" position to calculate cutoff position in the future
@ -308,8 +310,6 @@ class Engine:
if playlist["name"] == k: if playlist["name"] == k:
if len(v) == len(playlist["clips"]): if len(v) == len(playlist["clips"]):
playlists.remove(playlist) playlists.remove(playlist)
else:
playlist["clips"] = [playlist["clips"][i] for i in range(len(playlist["clips"])) if i not in v]
break break
return(playlists) return(playlists)