-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.py
54 lines (44 loc) · 1.96 KB
/
player.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
"""
Contains main player class.
"""
from typing import Dict, List
class Player:
def __init__(self, name: str, account_id: str, alias: str=""):
self.name = name
self.account_id = account_id
self.alias = alias if alias != "" else self.name
def get_rank_counts(self, all_pbs: Dict) -> None:
"""
Sets the attribute 'medal_count' which is a dict of:
{"gold": a, "silver": b, "bronze": c, "unfinished": d}
Note that unifinished refers to either unifinished or not in top 3.
"""
self.medal_count = {"gold":0, "silver": 0, "bronze": 0, "unfinished":0}
for pb_dict in all_pbs:
players = pb_dict.get("players", [])
if len(players) > 0 and players[0]["player"].account_id == self.account_id:
self.medal_count["gold"] += 1
elif len(players) > 1 and players[1]["player"].account_id == self.account_id:
self.medal_count["silver"] += 1
elif len(players) > 2 and players[2]["player"].account_id == self.account_id:
self.medal_count["bronze"] += 1
else:
self.medal_count["unfinished"] += 1
def get_total_rank_points(self, all_pbs: Dict) -> None:
"""
Sums up a player's rank points.
Sets attribute 'total_rank_points' which is an int.
"""
if not hasattr(self, "medal_count"):
self.get_rank_counts(all_pbs)
self.total_rank_points: int = (
1 * self.medal_count["gold"] +
2 * self.medal_count["silver"] +
3 * self.medal_count["bronze"] +
5 * self.medal_count["unfinished"]
)
PLAYERS: List[Player] = [
Player(name="EljayKay", account_id="7e468ff6-4558-43ce-ad23-591dd86291c0", alias="Eljay"),
Player(name="LryKo", account_id="f00ab19a-14e5-4e6e-9a45-78f1af8487e1", alias="Lry"),
Player(name="Timo._.o", account_id="b9b79f89-19e7-4f26-be01-03556b8890b9", alias="Timo")
]