forked from jw995/AIML-recommanding-system-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UserAnalyzer.py
27 lines (24 loc) · 940 Bytes
/
UserAnalyzer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# User Type Analyzer
# Determine different type of user, send different user to different recommendation module
class UserAnalyzer(object):
def __init__(self):
pass
def analyze(self, request, userActivityDB):
# should return an identifier such that the recommender engine knows what to do
# userActitivyDB is defined in DatabaseInterface, to count user's total amount of activity
if isinstance(request.userId,str):
# it is an anonymous request
return ["anonymous", -1, request]
elif request.userId in userActivityDB.index:
if userActivityDB[request.userId] >= 30:
# if the user has already rated more than 30 items, we call it an old user
return ["old", request.userId, request]
else:
return ["new", request.userId, request]
else:
return ["new", request.userId, request]
def analyzeAction(self, action):
if isinstance(action.userId, str):
return "anonymous"
else:
return "registered"