diff --git a/recommendation_engine.py b/recommendation_engine.py index 3361b05..55fbe53 100644 --- a/recommendation_engine.py +++ b/recommendation_engine.py @@ -87,8 +87,13 @@ class Engine: def get_videos(self, user): - if user.get('events', [{}])[0].get("event")=="login": - return self.get_recommendations(user) + if user.get('events', [{}])[0].get("event")=="login": + return { + 'user': { + 'keywords': user.get('keywords', {}) + }, + 'videos': self.get_recommendations(user) + } 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()} @@ -121,7 +126,12 @@ class Engine: # if there were no grid events for all, initialize all grids. if len(prev_grid_list) < video_num: - return self.get_recommendations(user) + return { + 'user': { + 'keywords': user.get('keywords', {}) + }, + 'videos': self.get_recommendations(user) + } else: if play_index is None: @@ -245,18 +255,12 @@ class Engine: )[:16 - channels['userKeywords'] - channels['globalKeywords']] # Shuffle playlists (randomize layout) and shift clips (randomize start) random.shuffle(videos) - videos_ = [{ + return [{ 'clips': video['clips'], 'position': random.randrange(len(video['clips'])), 'name': video['name'], 'tags': video['tags'], } for video in videos] - return { - 'user': { - 'keywords': user.get('keywords', {}) - }, - 'videos': videos_ - } def get_next(self, user, position):