From 4bd4af703e4a8f942d88ce6ffbe89b0a34fb363d Mon Sep 17 00:00:00 2001 From: j Date: Tue, 25 Sep 2018 17:50:52 +0200 Subject: [PATCH] only change return signature of get_videos --- recommendation_engine.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) 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):