This repository has been archived by the owner on Jun 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathRoleUpdater.py
executable file
·55 lines (47 loc) · 2.01 KB
/
RoleUpdater.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
#!python
import os
import pandas as pd
import sys
import Modes
def run(mode):
print('-- Updating roles --')
extracted_files = [f for f in os.listdir(mode.EXTRACTED_DIR)]
champ_roles = [[champ, {'N': 0, 'T': 0, 'J': 0, 'M': 0, 'C': 0, 'S': 0}] for champ in mode.CHAMPIONS_LABEL]
for file in extracted_files:
print(file, file=sys.stderr)
csv_file = os.path.join(mode.EXTRACTED_DIR, file)
data = pd.read_csv(csv_file, names=mode.COLUMNS, skiprows=1)
for [champ, role_count] in champ_roles:
counted_roles = data['p_' + champ].value_counts()
# noinspection PyCompatibility
for (r, n) in counted_roles.iteritems():
role_count[r] += n
# updating list of champions for each role
ROLES = {'TOP': [], 'JUNGLE': [], 'MID': [], 'CARRY': [], 'SUPPORT': []}
POSSIBLE_ROLES = ['TOP', 'JUNGLE', 'MID', 'CARRY', 'SUPPORT']
for [champ, role_count] in champ_roles:
s = 0
for role in POSSIBLE_ROLES:
s += role_count[role[0]]
role_ratio = {}
for role in POSSIBLE_ROLES:
role_ratio[role] = 0 if s == 0 else role_count[role[0]] / s
rr = role_ratio.items()
print(champ, sorted(rr, key=lambda t: t[1], reverse=True))
for role in role_ratio:
if role_ratio[role] > 0.1:
ROLES[role].append(champ)
for role in ROLES:
mode.config['ROLES'][role] = ','.join(ROLES[role])
# now we update the popularity of the champ for the role (reversed pov)
for role in POSSIBLE_ROLES:
s = 0
for [_, role_count] in champ_roles:
s += role_count[role[0]]
for [champ, role_count] in champ_roles:
mode.config[role][champ] = str('{:.2f}'.format(100 * role_count[role[0]] / s)) # % of popularity of the champ
with open('config.ini', 'w') as configfile:
mode.config.write(configfile)
if __name__ == '__main__':
m = Modes.ABR_TJMCS_Mode(['9.1','9.2','9.3','9.4','9.5','9.6','9.7'])
run(m)