-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathscorechart.py
47 lines (35 loc) · 1.31 KB
/
scorechart.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
import csv
import collections
__author__ = 'Anderson Tavares'
def from_file(chart_file, scale=1):
"""
Reads a scorechart from a .csv file with choice names in first line and scorechart in the following.
Example: for the following scorechart with probabilities of victories:
Bot Xeln Cruz NUSB Aiur Skyn
Xelnaga 50% 26% 86% 73% 73%
CruzBot 74% 50% 80% 67% 16%
NUSBot 14% 20% 50% 74% 97%
Aiur 27% 33% 26% 50% 79%
Skynet 27% 84% 3% 21% 50%
The file could be:
Xelnaga,CruzBot,NUSBot,Aiur,Skynet
50,26,86,73,73
74,50,80,67,16
14,20,50,74,97
27,33,26,50,79
27,84,3,21,50
(if decimals are desired instead of percents, one can apply a scaling transform)
:param chart_file:path to scorechart.csv file
:param scale: factor to scale file values
:return:
"""
chart = {}
with open(chart_file, 'rb') as csv_file:
reader = csv.reader(csv_file)
rows = list(reader)
# first line has the names
names = rows[0]
# remaining rows have the scores in order
for row_num, row in enumerate(rows[1:]):
chart[names[row_num]] = {names[col_num]: scale*float(col) for col_num, col in enumerate(row)}
return chart