-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathStatisticsReader.py
More file actions
147 lines (120 loc) · 4.55 KB
/
Copy pathStatisticsReader.py
File metadata and controls
147 lines (120 loc) · 4.55 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import datetime
import json
import pygame
from typing import Union
from Settings import *
def update_win_count(path: str, mapId: str) -> None:
try:
with open(path, 'r+') as jsonObject:
content = json.load(jsonObject)
content[mapId][1]['winCount'] += 1
jsonObject.seek(0, 0)
jsonObject.truncate()
json.dump(content, jsonObject)
except Exception as errorMessage:
print(errorMessage)
finally:
jsonObject.close()
def update_lose_count(path: str, mapId: str) -> None:
try:
with open(path, 'r+') as jsonObject:
content = json.load(jsonObject)
content[mapId][1]['loseCount'] += 1
jsonObject.seek(0, 0)
jsonObject.truncate()
json.dump(content, jsonObject)
except Exception as errorMessage:
print(errorMessage)
finally:
jsonObject.close()
def check_win_count(path: str) -> list:
winCountList = []
try:
with open(path, 'r') as jsonObject:
content = json.load(jsonObject)
for i in range(1, len(content)+1):
mapId = "Map" + str(i)
winCount = content[mapId][1]["winCount"]
winCountList.append(winCount)
except Exception as errorMessage:
print(errorMessage)
finally:
jsonObject.close()
return winCountList
def check_lose_count(path: str) -> list:
loseCountList = []
try:
with open(path, 'r') as jsonObject:
content = json.load(jsonObject)
for i in range(1, len(content)+1):
mapId = "Map" + str(i)
loseCount = content[mapId][1]["loseCount"]
loseCountList.append(loseCount)
except Exception as errorMessage:
print(errorMessage)
finally:
jsonObject.close()
return loseCountList
def update_first_win_time(path: str, mapId: str) -> None:
try:
with open(path, 'r+') as jsonObject:
content = json.load(jsonObject)
currentTime = str(datetime.datetime.today()).split('.')[0]
content[mapId][2]["firstWinTime"] = currentTime
jsonObject.seek(0, 0)
jsonObject.truncate()
json.dump(content, jsonObject)
except Exception as errorMessage:
print(errorMessage)
finally:
jsonObject.close()
def check_first_win_time(path: str, mapId: str) -> Union[str, None]:
try:
with open(path, 'r') as jsonObject:
content = json.load(jsonObject)
lastWinTime = content[mapId][2]["firstWinTime"]
if lastWinTime != '':
return lastWinTime
else:
return None
except Exception as errorMessage:
print(errorMessage)
finally:
jsonObject.close()
def adjust(cnt: int) -> list:
numberPathList = []
for num in str(cnt):
numberPath = "pics/number_" + num + ".png"
numberPathList.append(numberPath)
return numberPathList
def statistics_display(window, id: int) -> None:
winCountList = check_win_count(STATISTICS_FILE_PATH)
loseCountList = check_lose_count(STATISTICS_FILE_PATH)
winCount = winCountList[id]
loseCount = loseCountList[id]
defaultWinCountLocationX = 150
defaultLoseCountLocationX = 150
defaultWinTimeLocationX = 150
winCountNumberPathList = adjust(winCount)
loseCountNumberPathList = adjust(loseCount)
firstWintTimeNumberPathList = []
for i in range(len(str(winCount))):
window.blit(pygame.image.load(winCountNumberPathList[i]), Vector2(defaultWinCountLocationX, 0))
defaultWinCountLocationX += 30
for i in range(len(str(loseCount))):
window.blit(pygame.image.load(loseCountNumberPathList[i]), Vector2(defaultLoseCountLocationX, 30))
defaultLoseCountLocationX += 30
firstWintTime = check_first_win_time(STATISTICS_FILE_PATH, "Map" + str(id+1))
if firstWintTime is not None:
for number in firstWintTime:
if number == '-':
firstWintTimeNumberPathList.append("pics/number_hyphen.png")
elif number == ':':
firstWintTimeNumberPathList.append("pics/number_colon.png")
elif number == ' ':
firstWintTimeNumberPathList.append("pics/number_null.png")
else:
firstWintTimeNumberPathList.extend(adjust(int(number)))
for i in range(len(firstWintTime)):
window.blit(pygame.image.load(firstWintTimeNumberPathList[i]), Vector2(defaultWinTimeLocationX, 60))
defaultWinTimeLocationX += 30