-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
plot-game-points-by-match.py
executable file
·124 lines (102 loc) · 3.04 KB
/
plot-game-points-by-match.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
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
#!/usr/bin/env python3
import argparse
import matplotlib.pyplot as plt
from colour import Color
from sr.comp.comp import SRComp
import plot_utils
comp = SRComp('.')
def game_point_by_match(tla, start_match_num):
for (_, num), points in {**comp.scores.league.game_points, **comp.scores.knockout.game_points}.items():
if num < start_match_num:
continue
if tla in points:
yield num, points[tla]
else:
yield num, 0
def plot(start_match_num, final_match_num, tlas, highlight, output):
if tlas is None:
tlas = comp.teams.keys()
if highlight is None:
highlight = tlas
fig, ax = plt.subplots()
fig.set_size_inches(*plot_utils.SIZE_INCHES)
final_val_order = []
i = 0
teams_and_hues = plot_utils.get_teams_with_hues(
comp,
final_match_num,
tlas,
highlight,
)
teams_and_colours = [
(t, Color(hsl=(x, 1., .5)))
for t, x in teams_and_hues
]
for idx, (team, colour) in enumerate(teams_and_colours):
z_order = 10
if team.tla not in highlight:
colour.luminance = 0.9
z_order = 0
score_list = sorted(game_point_by_match(team.tla, start_match_num))
score_only = [score for (_, score) in score_list]
score_cum = 0
score_cum_list = []
for score in score_only:
score_cum += score
score_cum_list.append(score_cum)
ax.plot(
score_cum_list,
label=team.tla,
color=colour.hex,
zorder=z_order,
)
final_val_order.append((score_cum, idx))
final_val_order.sort()
final_val_order.reverse()
order = [i for (_, i) in final_val_order]
handles, labels = plt.gca().get_legend_handles_labels()
plt.legend(
[handles[idx] for idx in order],
[labels[idx] for idx in order],
loc='upper left',
)
plt.xlabel("Match Number")
locs, labels = plt.xticks()
locs = [x for x in locs if x >= 0][:-1]
plt.xticks(
locs,
[f'{x + start_match_num:g}' for x in locs],
)
plt.ylabel("Game Points")
plt.savefig(output)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
'--start-match-num',
help="Start from the given match number (inclusive, default: %(default)s)",
type=int,
default=0,
)
parser.add_argument(
'--final-match-num',
help='Exclude Teams not present at this match number',
type=int,
default=144,
)
parser.add_argument(
'--teams',
help='list of TLAs of teams to plot',
nargs='+',
)
parser.add_argument(
'--highlight',
help='list of TLAs of teams to highlight in plot',
nargs='+',
)
parser.add_argument(
'--output',
required=True,
help='Where to save the plot',
)
args = parser.parse_args()
plot(args.start_match_num, args.final_match_num, args.teams, args.highlight, args.output)