use activities for screenings

This commit is contained in:
j 2018-01-24 16:48:50 +01:00
parent a44e619d09
commit d856138e3a

View file

@ -3,6 +3,7 @@ Recommendation Engine Example
1 Nov 2017, 0x2620 1 Nov 2017, 0x2620
''' '''
from collections import defaultdict
import json import json
import os import os
import random import random
@ -48,17 +49,18 @@ class Engine:
videos = playlists[:channels['keywords']] videos = playlists[:channels['keywords']]
playlists = playlists[channels['keywords']:] playlists = playlists[channels['keywords']:]
# Count tags for the user # Count tags for the user
count = {} count = defaultdict(lambda: 0)
for event in user.get('events', []): for activity in user.get('activities', []):
if 'product' in event['data']: if activity.get('type') == 'SCREENING_CHECK_IN':
count[event['data']['product']] = count.get( product = activity.get('extras', {}).get('event', {}).get('alias')
event['data']['product'], 0 if product:
) + 1 product = product.replace('_', ' ')
count[product] += 1
# For each tag in playlist, increment score by count # For each tag in playlist, increment score by count
for playlist in playlists: for playlist in playlists:
score[playlist['name']] = random.random() score[playlist['name']] = random.random()
for tag in [tag for tag in playlist['tags'] if tag not in sliders]: for tag in [tag for tag in playlist['tags'] if tag not in sliders]:
score[playlist['name']] += count.get(tag, 0) score[playlist['name']] += count[tag]
# Select highest scoring playlists # Select highest scoring playlists
videos += sorted( videos += sorted(
playlists, playlists,