From 81cfe9c9d82b699a055534d874252149a7c8bd80 Mon Sep 17 00:00:00 2001 From: pythagoraswitch Date: Wed, 26 Sep 2018 23:56:29 +0200 Subject: [PATCH] removed the outdated portion: screening parameter etc --- recommendation_engine.py | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/recommendation_engine.py b/recommendation_engine.py index 173550f..b3d9e4f 100644 --- a/recommendation_engine.py +++ b/recommendation_engine.py @@ -45,7 +45,6 @@ class Engine: 'channels': { 'globalKeywords': {'locked': False, 'value': 8}, 'userKeywords': {'locked': False, 'value': 8} - # 'screenings': {'locked': True, 'value': 2} }, 'globalKeywords': {}, } @@ -202,8 +201,7 @@ class Engine: } -# NOTE for future improvement: vids_exclude element unit could be clip or in/out time pairs, rather than playlist. -# The same playlist could be played in the grid view as long as these are differenct clips or separate times. + def get_recommendations(self, user, vids_exclude = []): 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()} @@ -255,23 +253,7 @@ class Engine: playlists, key=lambda playlist: -score[playlist['name']] ) - videos += playlists[:channels['globalKeywords']] - playlists = playlists[channels['globalKeywords']:] - # Count products the user has seen - count = defaultdict(lambda: 0) - for event in user.get('events', []): - if event.get('data', {}).get('product'): - count[event['data']['product']] += 1 - # For each product in playlist tags, increment score by count - for playlist in playlists: - score[playlist['name']] = random.random() - for tag in set(playlist['tags']) & set(count): - score[playlist['name']] += count[tag] - # Select highest scoring playlists - videos += sorted( - playlists, - key=lambda playlist: -score[playlist['name']] - )[:16 - channels['userKeywords'] - channels['globalKeywords']] + videos += playlists[:16 - channels['userKeywords']] # Shuffle playlists (randomize layout) and shift clips (randomize start) random.shuffle(videos) return [{