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
'''
from collections import defaultdict
import json
import os
import random
@ -48,17 +49,18 @@ class Engine:
videos = playlists[:channels['keywords']]
playlists = playlists[channels['keywords']:]
# Count tags for the user
count = {}
for event in user.get('events', []):
if 'product' in event['data']:
count[event['data']['product']] = count.get(
event['data']['product'], 0
) + 1
count = defaultdict(lambda: 0)
for activity in user.get('activities', []):
if activity.get('type') == 'SCREENING_CHECK_IN':
product = activity.get('extras', {}).get('event', {}).get('alias')
if product:
product = product.replace('_', ' ')
count[product] += 1
# For each tag in playlist, increment score by count
for playlist in playlists:
score[playlist['name']] = random.random()
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
videos += sorted(
playlists,