From 49e045daf41add92cb42dcb572ae5e06277828a9 Mon Sep 17 00:00:00 2001 From: j Date: Sun, 4 Feb 2018 16:05:55 +0100 Subject: [PATCH] only count events with product --- recommendation_engine.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/recommendation_engine.py b/recommendation_engine.py index c2d921a..bb99180 100644 --- a/recommendation_engine.py +++ b/recommendation_engine.py @@ -65,7 +65,8 @@ class Engine: # Count tags for the user count = defaultdict(lambda: 0) for event in user.get('events', []): - count[event['data']['product']] += 1 + if event.get('data', {}).get('product'): + count[event['data']['product']] += 1 # For each tag in playlist, increment score by count for playlist in playlists: score[playlist['name']] = random.random()