-
Notifications
You must be signed in to change notification settings - Fork 0
/
datastore.py
66 lines (54 loc) · 2.32 KB
/
datastore.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
import json
import os
def update(contest, People_data, contestdata):
Users = {}
with open("data/users.json","r") as f:
Users = json.loads(f.read())
Contests = {}
with open("data/contests.json","r") as f:
Contests = json.loads(f.read())
Contests[contest['name']] = contest
with open("data/contests/"+contest['trello_id']+".json","w") as f:
f.write(json.dumps(contestdata))
for p in People_data:
personal_data = {}
if not p in Users:
Users[p] = {"username":p, "nickname":"", "rating": 0, "attend": 0}
else:
with open("data/users/"+p+".json","r") as f:
personal_data = json.loads(f.read())
if not contest['name'] in personal_data:
personal_data[contest['name']] = {"rating": 0.0,"attend":0, "score": 0, "attend_list": [], "score_list": {}}
Users[p]['rating'] -= personal_data[contest['name']]['rating']
Users[p]['attend'] -= personal_data[contest['name']]['attend']
personal_data[contest['name']] = People_data[p]
Users[p]['rating'] += personal_data[contest['name']]['rating']
Users[p]['rating'] = round(Users[p]['rating'], 2)
Users[p]['attend'] += personal_data[contest['name']]['attend']
Users[p]['attend_contests'] = len(personal_data)
if not 'last_event' in Users[p]:
Users[p]['last_event'] = ""
mtime = 0
for c in personal_data:
if Contests[c]['start_time'] > mtime:
mtime = Contests[c]['start_time']
Users[p]['last_event'] = c
with open("data/users/"+p+".json","w") as f:
f.write(json.dumps(personal_data))
with open("data/contests.json","w") as f:
f.write(json.dumps(Contests))
with open("data/users.json","w") as f:
f.write(json.dumps(Users))
def getStatisticsData():
Users = {}
with open("data/users.json","r") as f:
Users = json.loads(f.read())
Contests = {}
with open("data/contests.json","r") as f:
Contests = json.loads(f.read())
return {"users": Users, "contests": Contests}
def getUserDetail(username):
if not os.path.isfile("data/users/"+username+".json"):
return None
with open("data/users/"+username+".json","r") as f:
return json.loads(f.read())