forked from 397179459/iMaoTai-reserve
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstatistics.py
35 lines (33 loc) · 1.28 KB
/
statistics.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
class UserResult:
def __init__(self, name, success=0, failure=0):
self.success = success
self.failure = failure
self.name = name
self.text_results = []
def add_success(self, count=1, *reasons):
self.success += count
self.text_results.extend(reasons)
def add_failure(self, count=1, *reasons):
self.failure += count
self.text_results.extend(reasons)
def __str__(self) -> str:
return f"{self.name}: {self.success}/{self.failure+self.success}"
def __repr__(self) -> str:
return f"{self.name}: {self.success}/{self.failure+self.success}"
class Statistics:
def __init__(self, **users):
self.details = {}
self.details.update(users)
self.total_success = 0
self.total_failure = 0
for user in users:
self.total_success += users[user].success
self.total_failure += users[user].failure
def update(self, result: UserResult):
if result.name not in self.details:
self.details[result.name] = result
else:
self.details[result.name].add_success(result.success)
self.details[result.name].add_failure(result.failure)
self.total_success += result.success
self.total_failure += result.failure