-
Notifications
You must be signed in to change notification settings - Fork 0
/
20_top_players.py
69 lines (51 loc) · 1.97 KB
/
20_top_players.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
import csv
import sys
import pandas as pd
import bar_chart_race as bcr
from devgoldyutils import Colours
from novauniverse import MCF, TournamentPlayer
from typing import Dict
mcf = MCF()
print(Colours.ORANGE.apply_to_string("Getting all mcf data..."))
all_mcfs = mcf.get_all()
print(Colours.BLUE.apply_to_string("Getting information on top mcf players..."))
relevant_players = mcf.get_top_players(max_players = 20)
score_count:Dict[str, TournamentPlayer] = {}
for player in relevant_players:
player.score = 0 # Zero all scores.
score_count[player.uuid] = player
# Create csv file.
# ------------------
with open("./temp.csv", "w", newline="") as file:
writer = csv.writer(file)
writer.writerow(["Date"] + [player.name for player in relevant_players])
for mcf in all_mcfs:
player_scores = []
for relevant_player_uuid in score_count:
player_found = False
for player in mcf.players:
if player.uuid == relevant_player_uuid:
player_found = True
score_count[relevant_player_uuid].score += player.score
player_scores.append(
score_count[relevant_player_uuid].score
)
break
if not player_found:
player_scores.append(score_count[relevant_player_uuid].score)
sys.stdout.write(Colours.PINK_GREY.apply_to_string(f"Done player '{relevant_player_uuid}'.") + "\n")
writer.writerow([mcf.display_name] + player_scores)
print(Colours.GREEN.apply_to_string(f"Done mcf '{mcf.display_name}'."))
# Generate bar chart race
# -------------------------
df = pd.read_csv("./temp.csv", index_col="Date")
print(Colours.PURPLE.apply_to_string("Generating bar chart race..."))
bcr.bar_chart_race(
df = df,
bar_label_size = 19,
tick_label_size = 20,
steps_per_period = 30,
period_length = 1000,
filename = "video.mp4",
figsize = (18, 10.5)
)