-
Notifications
You must be signed in to change notification settings - Fork 6
/
run.py
139 lines (115 loc) · 3.33 KB
/
run.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import api_request as api
import matplotlib.pyplot as plt
import numpy as np
import time
plt.style.use('ggplot')
REGIONS = {
"br": "br1",
"eune": "eun1",
"euw": "euw1",
"jp": "jp1",
"kr": "kr",
"lan": "la1",
"las": "la2",
"na": "na1",
"oce": "oc1",
"tr": "tr1",
"ru": "ru"
}
# Queue codes:
# 400 - 5v5 Draft Pick
# 420 - 5v5 Ranked Solo
# 430 - 5v5 Blind Pick
# 440 - 5v5 Ranked Flex
# 450 - 5v5 ARAM
QUEUES = {
'draft': 400,
'solo': 420,
'blind': 430,
'flex': 440,
'aram': 450
}
def routingSelector(region):
"""
Match history data uses routing regions instead
"""
if region in ["na", "br", "lan", "las", "oce"]:
return "americas"
if region in ["kr", "jp"]:
return "asia"
if region in ["eune", "euw", "tr", "ru"]:
return "europe"
assert False, "not matched"
if __name__ == "__main__":
# Prompt user for inputs
region = ""
while region not in REGIONS:
print("Region? (i.e. NA)")
region = input().lower()
routing = routingSelector(region)
region = REGIONS[region]
# Does not verify input for summoner name
print("Summoner Name?")
summonerName = input()
queue = ""
# Verify queue input validation
while queue not in QUEUES:
print("Which queue?")
queue = input().lower()
queueCode = QUEUES[queue]
print("Loading...")
# Gets start and end time for the function
start = time.time()
# Gets list of champions & their winrates as a pair of lists, in order of number of games played
summonerId = api.getSummonerId(summonerName, region)
matchlist = api.getMatchList(summonerId, queueCode, routing)
x, y = api.displayWinrates(summonerId, matchlist, routing)
end = time.time()
print(f"Data acquired in {end-start:.2f} seconds.")
fig, ax = plt.subplots()
# Plots bar graph
x_pos = np.arange(len(x))
bar_plot = plt.bar(x_pos, y)
# Set bar colors for different winrates
for i, bar in enumerate(bar_plot):
if y[i] >= 70:
bar.set_color("#E19205")
elif y[i] >= 60 and y[i] < 70:
bar.set_color("#1F8ECD")
elif y[i] >= 50 and y[i] < 60:
bar.set_color("#2DAF7F")
else:
bar.set_color("grey")
# Creates labels for each bar
for champion, rect in enumerate(bar_plot):
# Label in white, inside the bar if the winrate is greater than 90%
if y[champion] > 90:
height = y[champion] - 5
color = 'white'
else:
height = y[champion] + 0.5
color = 'black'
text = f"{y[champion]}%"
ax.text(
rect.get_x() + rect.get_width()/2., height, text,
ha='center', va='bottom', rotation=0, fontsize='9', color=color
)
# X and Y axis labels
plt.xlabel('Champion')
plt.ylabel('Winrate')
plt.ylim(0, 100)
# Rotated X axis label for each champion
plt.xticks(
x_pos, x,
rotation=45, fontsize='10', horizontalalignment='right'
)
# Displays title
if queue == 'blind' or queue == 'draft':
queue += ' pick'
else:
queue = 'ranked ' + queue
title = f'Winrates per champion for {summonerName} in {queue}'
plt.title(title)
# Prevent labels from being cut off
plt.tight_layout()
plt.show()