forked from SpinazieSin/UvA-Home
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuserprofile.py
More file actions
92 lines (83 loc) · 3.23 KB
/
Copy pathuserprofile.py
File metadata and controls
92 lines (83 loc) · 3.23 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# -*-coding:utf-8-*-
"""UserProfile class file for the media understanding 2017 project.
File name: userprofile.py
Author: Media Understanding 2017
Date created: 13/2/2017
Date last modified: 13/2/2017
Python Version: 3.5
"""
import os
import pickle
class UserProfile():
"""
Standarized format for user news preference profiles.
All standard news categories are initialized here, each category
has a interest rating between 0 and 1, with 1 being the most interesting
and 0 being not interesting. All values interests are stored in the
interests dict.
"""
def __init__(self, username="NAMELESS", facial_features="FILENAME"):
"""Initialize all values."""
self.keywords = []
self.username = username
self.interests = {}
self.facial_features = facial_features
self.interests["top_stories"] = 1.0
self.interests["world"] = 0.5
self.interests["africa"] = 0.5
self.interests["americas"] = 0.5
self.interests["asia"] = 0.5
self.interests["europe"] = 0.5
self.interests["middle_east"] = 0.5
self.interests["north_america"] = 0.5
self.interests["money"] = 0.5
self.interests["technology"] = 0.5
self.interests["science"] = 0.5
self.interests["entertainment"] = 0.5
self.interests["sport"] = 0.5
self.interests["football"] = 0.5
self.interests["american_football"] = 0.5
self.interests["golf"] = 0.5
self.interests["basketball"] = 0.5
self.interests["motorsport"] = 0.5
self.interests["tennis"] = 0.5
self.interests["travel"] = 0.5
self.interests["latest"] = 0.5
self.interests["latin_america"] = 0.5
self.interests["uk"] = 0.5
self.interests["england"] = 0.5
self.interests["northern_ireland"] = 0.5
self.interests["scotland"] = 0.5
self.interests["wales"] = 0.5
self.interests["business"] = 0.5
self.interests["politics"] = 0.5
self.interests["education"] = 0.5
self.interests["art"] = 0.5
self.interests["companies"] = 0.5
self.interests["media"] = 0.5
self.interests["economy"] = 0.5
self.interests["odd"] = 0.5
self.interests["lifestyle"] = 0.5
self.interests["health"] = 0.5
self.interests["baseball"] = 0.5
self.interests["environment"] = 0.5
def update_preferences(self, sentiment, article):
self.interests[article.category] += 0.1 * sentiment
if sentiment > 1:
self.keywords.append(article.keywords)
if sentiment < 0:
# self.keywords -= article.keywords
self.keywords = list(set(self.keywords) - set(article.keywords))
self.save_user()
return None, [None]
def save_user(self):
"""Save current user profile."""
PATH = "users/" + self.username + "/" + self.username + ".pickle"
# this makes it work in 2.7 idk why
ospath = os.path.join(os.path.dirname(__file__), '')
fullpath = ospath + PATH
with open(fullpath, 'wb') as handle:
pickle.dump(self, handle)
def __repr__(self):
"""Print user name."""
return "<Username: " + str(self.username) + ">"