From 0fe5752db3edd82f3d4604b06c9bab4b8fac294e Mon Sep 17 00:00:00 2001 From: j Date: Fri, 21 Sep 2018 22:09:45 +0200 Subject: [PATCH] return user keywords --- recommendation_engine.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/recommendation_engine.py b/recommendation_engine.py index 4a8b075..3361b05 100644 --- a/recommendation_engine.py +++ b/recommendation_engine.py @@ -178,7 +178,13 @@ class Engine: rec_list += [(i,{}) for i in stay_same_index] rec_list = sorted(rec_list, key=lambda k:k[0]) - return [e[1] for e in rec_list] + videos_ = [e[1] for e in rec_list] + return { + 'user': { + 'keywords': user.get('keywords', {}) + }, + 'videos': videos_ + } # NOTE for future improvement: vids_exclude element unit could be clip or in/out time pairs, rather than playlist. @@ -239,12 +245,18 @@ class Engine: )[:16 - channels['userKeywords'] - channels['globalKeywords']] # Shuffle playlists (randomize layout) and shift clips (randomize start) random.shuffle(videos) - return [{ + videos_ = [{ '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):