-
Notifications
You must be signed in to change notification settings - Fork 0
/
profLib.py
109 lines (105 loc) · 4.28 KB
/
profLib.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
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#profLib.py
import json
import pprofile
def create_next_id():
with open('profFile.json') as json_file:
data = json.load(json_file)
final_key = -1
for key in data:
final_key = key
next_key = str(int(final_key)+1)
data[next_key] = {}
with open('profFile.json', 'w') as outfile:
json.dump(data, outfile)
return(next_key)
def createBlank():
data = {}
with open('profFile.json', 'w') as outfile:
json.dump(data, outfile)
def load_file():
with open('profFile.json') as json_file:
data = json.load(json_file)
return(data)
def fillbykey(key0, key1, param):
data = load_file()
data[key0][key1] = param
with open('profFile.json', 'w') as outfile:
json.dump(data, outfile)
def returnbykey(key0,key1):
data = load_file()
return(data[key0][key1])
def updateprofilefile(updated_list):
data = {}
for x in range(0, len(updated_list)):
ckey = str(updated_list[x].ID)
data[ckey] = {}
data[ckey]['name'] = updated_list[x].namefirst
data[ckey]['last_name'] = updated_list[x].namelast
data[ckey]['pronouns'] = updated_list[x].pronouns
data[ckey]['face'] = updated_list[x].face
data[ckey]['trust'] = updated_list[x].trust
data[ckey]['phone_number'] = updated_list[x].phonenumber
data[ckey]['email'] = updated_list[x].email
data[ckey]['date_met'] = updated_list[x].dateMet
data[ckey]['clusterID'] = updated_list[x].clusterID
data[ckey]['pes'] = updated_list[x].pes
data[ckey]['previous_conv_pointer'] = updated_list[x].prevConv
with open('profFile.json', 'w') as outfile:
json.dump(data, outfile)
def load_profiles_from_file():
with open('profFile.json') as json_file:
data = json.load(json_file)
profile_list = []
for key in data:
cdata = data[key]
currently_loaded = pprofile.profile(int(key))
if('name' in cdata):
currently_loaded.namefirst = cdata['name']
if('pronouns' in cdata and cdata['pronouns']!=None):
currently_loaded.pronouns = int(cdata['pronouns'])
if('last_name' in cdata):
currently_loaded.namelast = cdata['last_name']
if('trust' in cdata and cdata['trust']!=None):
currently_loaded.trust = int(cdata['trust'])
if('phone_number' in cdata):
currently_loaded.phonenumber = cdata['phone_number']
if('email' in cdata):
currently_loaded.email = cdata['email']
if('face' in cdata):
currently_loaded.face = cdata['face']
if('date_met' in cdata):
currently_loaded.dateMet = cdata['date_met']
profile_list.append(currently_loaded)
return(profile_list)
class profiles:
def __init__(self):
self.profiles = load_profiles_from_file()
def piece_to_id(self, piece):
self.profiles = load_profiles_from_file()
resolved_id = -1
for x in range(0, len(self.profiles)):
pilist = {'name': self.profiles[x].namefirst, 'last_name': self.profiles[x].namelast, 'phone_number': self.profiles[x].phonenumber,
'email': self.profiles[x].email}
for key in pilist:
if(pilist[key] == piece):
print("Profile for " + self.profiles[x].namefirst + " ("+str(x)+") " + "resolved exactly " + str(piece)+".")
resolved_id = x
if(resolved_id ==-1):
print("Profile for speaker could not be resolved.")
def piece_to_id_pair(self, piece):
self.profiles = load_profiles_from_file()
resolved_id = -1
resolved_pair = None
pairings = []
for x in range(0, len(self.profiles)):
pilist = {'name': self.profiles[x].namefirst, 'last_name': self.profiles[x].namelast, 'phone_number': self.profiles[x].phonenumber,
'email': self.profiles[x].email}
for key in pilist:
if(pilist[key] == piece):
print("Profile for " + self.profiles[x].namefirst + " ("+str(x)+") " + "resolved exactly " + str(piece)+".")
resolved_id = x
resolved_pair = key
pairings.append([resolved_id, resolved_pair])
#resolved_id = create_next_id()
return(pairings)
#return(data)