Compare commits
2 commits
b3d727a9d0
...
4fadcf7927
| Author | SHA1 | Date | |
|---|---|---|---|
| 4fadcf7927 | |||
| d51748b1d0 |
1 changed files with 10 additions and 27 deletions
|
|
@ -58,10 +58,6 @@ class Engine:
|
||||||
self.state['userKeywordsWeights'] = {
|
self.state['userKeywordsWeights'] = {
|
||||||
'themeTags': {'locked': False, 'value': 0.3},
|
'themeTags': {'locked': False, 'value': 0.3},
|
||||||
'characterTags': {'locked': False, 'value': 0.7}
|
'characterTags': {'locked': False, 'value': 0.7}
|
||||||
<<<<<<< HEAD
|
|
||||||
=======
|
|
||||||
|
|
||||||
>>>>>>> iss2
|
|
||||||
}
|
}
|
||||||
self.update_keywords()
|
self.update_keywords()
|
||||||
|
|
||||||
|
|
@ -96,14 +92,14 @@ class Engine:
|
||||||
|
|
||||||
def get_videos(self, user):
|
def get_videos(self, user):
|
||||||
# Update self_playlists first to reflect changes
|
# 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":
|
if user.get('events', [{}])[0].get("event")=="login":
|
||||||
return {
|
return {
|
||||||
'user': {
|
'user': {
|
||||||
'keywords': user.get('keywords', {})
|
'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()}
|
channels = {k: v.get('value', 0) for k, v in self.state['channels'].items()}
|
||||||
|
|
@ -128,16 +124,12 @@ class Engine:
|
||||||
prev_grid_list = sorted([v for v in grid_events.values()], key=lambda k:k['index'])
|
prev_grid_list = sorted([v for v in grid_events.values()], key=lambda k:k['index'])
|
||||||
|
|
||||||
# if there were no grid events for all, initialize all grids.
|
# if there were no grid events for all, initialize all grids.
|
||||||
<<<<<<< HEAD
|
|
||||||
if len(prev_grid_list) < video_num:
|
|
||||||
=======
|
|
||||||
if len(prev_grid_list) < video_num:
|
if len(prev_grid_list) < video_num:
|
||||||
>>>>>>> iss2
|
|
||||||
return {
|
return {
|
||||||
'user': {
|
'user': {
|
||||||
'keywords': user.get('keywords', {})
|
'keywords': user.get('keywords', {})
|
||||||
},
|
},
|
||||||
'videos': self.get_recommendations(user)
|
'videos': self.get_recommendations(playlists, user)
|
||||||
}
|
}
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
@ -163,7 +155,7 @@ class Engine:
|
||||||
next_playlist_index.append(next_clip_index)
|
next_playlist_index.append(next_clip_index)
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
for playlist in self.playlists:
|
for playlist in playlists:
|
||||||
if playlist.get('name')== prev_grid_list[i].get('playlist'):
|
if playlist.get('name')== prev_grid_list[i].get('playlist'):
|
||||||
if len(playlist["clips"]) == 1:
|
if len(playlist["clips"]) == 1:
|
||||||
next_playlist_index.append(i)
|
next_playlist_index.append(i)
|
||||||
|
|
@ -187,7 +179,7 @@ class Engine:
|
||||||
vids_exclude = [e.get("playlist") for e in prev_grid_list]
|
vids_exclude = [e.get("playlist") for e in prev_grid_list]
|
||||||
while None in vids_exclude:
|
while None in vids_exclude:
|
||||||
vids_exclude.remove(None)
|
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]
|
rec_list += [(i, video[i]) for i in next_playlist_index]
|
||||||
|
|
||||||
#staySame pool
|
#staySame pool
|
||||||
|
|
@ -201,20 +193,15 @@ class Engine:
|
||||||
},
|
},
|
||||||
'videos': videos_
|
'videos': videos_
|
||||||
}
|
}
|
||||||
<<<<<<< HEAD
|
|
||||||
|
|
||||||
=======
|
|
||||||
>>>>>>> iss2
|
|
||||||
|
|
||||||
|
|
||||||
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()}
|
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()}
|
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()}
|
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()}
|
userKeywordsWeights = {k: v.get('value', 1) for k, v in self.state['userKeywordsWeights'].items()}
|
||||||
|
|
||||||
# Exclude playlists from the most recent grid
|
# Exclude playlists from the most recent grid
|
||||||
playlists = copy.deepcopy(self.playlists)
|
|
||||||
if len(vids_exclude) > 0:
|
if len(vids_exclude) > 0:
|
||||||
for playlist in playlists:
|
for playlist in playlists:
|
||||||
if playlist["name"] in vids_exclude:
|
if playlist["name"] in vids_exclude:
|
||||||
|
|
@ -231,11 +218,6 @@ class Engine:
|
||||||
character_tags["FEDOR MIKHAILOVICH SOFRONOV"] = character_tags.get("FYODOR MIKHAILOVICH SOFRONOV",0)
|
character_tags["FEDOR MIKHAILOVICH SOFRONOV"] = character_tags.get("FYODOR MIKHAILOVICH SOFRONOV",0)
|
||||||
character_tags["SHKABARNYA OLGA SERGEEVNA"] = character_tags.get("OLGA SERGEEVNA SHKABARNYA",0)
|
character_tags["SHKABARNYA OLGA SERGEEVNA"] = character_tags.get("OLGA SERGEEVNA SHKABARNYA",0)
|
||||||
character_tags["VICTORIA OLEGOVNA SKITSKAYA"] = character_tags.get("VIKTORIA OLEGOVNA SKITSKAYA",0)
|
character_tags["VICTORIA OLEGOVNA SKITSKAYA"] = character_tags.get("VIKTORIA OLEGOVNA SKITSKAYA",0)
|
||||||
<<<<<<< HEAD
|
|
||||||
|
|
||||||
=======
|
|
||||||
|
|
||||||
>>>>>>> iss2
|
|
||||||
score = {}
|
score = {}
|
||||||
for playlist in playlists:
|
for playlist in playlists:
|
||||||
score[playlist['name']] = random.random() * 0.001
|
score[playlist['name']] = random.random() * 0.001
|
||||||
|
|
@ -273,7 +255,7 @@ class Engine:
|
||||||
} for video in videos]
|
} 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.
|
# Output: playlists with updated in/out time of clips that have been watched.
|
||||||
# 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]
|
||||||
|
|
@ -281,6 +263,7 @@ class Engine:
|
||||||
# + 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, eliminate the clip from the playlist.
|
||||||
# + 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 the clips are all eliminated from a playlist, eliminate the playlist.
|
||||||
|
playlists = copy.deepcopy(self.playlists)
|
||||||
play = {}
|
play = {}
|
||||||
watched = []
|
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
|
||||||
|
|
@ -333,7 +316,7 @@ class Engine:
|
||||||
|
|
||||||
def get_next(self, user, position):
|
def get_next(self, user, position):
|
||||||
# Update self_playlists first to reflect changes
|
# Update self_playlists first to reflect changes
|
||||||
update_user_playlists(self.playlists, user)
|
playlists = self.update_user_playlists(user)
|
||||||
|
|
||||||
grid_events = {}
|
grid_events = {}
|
||||||
video_num = 16
|
video_num = 16
|
||||||
|
|
@ -345,7 +328,7 @@ class Engine:
|
||||||
break
|
break
|
||||||
prev_grid_list = sorted([v for v in grid_events.values()], key=lambda k:k['index'])
|
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]
|
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
|
return video
|
||||||
|
|
||||||
def update_state(self, data):
|
def update_state(self, data):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue