forked from siggame/MegaMinerAI-Game-Ideas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame-voter.py
50 lines (40 loc) · 1.68 KB
/
game-voter.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
# This takes csv output from a Google Forms asking for game Rankings, and puts them into format for this website:
# http://www.cs.wustl.edu/~legrand/rbvote/calc.html
import csv
import re
import argparse
argparser = argparse.ArgumentParser(
description='Runs the game voter algorithm'
)
argparser.add_argument('input', nargs='?', action='store', help='the input file', default='data.csv')
args = argparser.parse_args()
games = []
first = True
ignore_columns = 2
regex = re.compile('[^a-zA-Z]')
with open(args.input, 'r') as csvfile:
reader = csv.reader(csvfile)
for row in reader:
ballot = None
if not first: # we have read the first row, time to make a ballot
ballot = [[] for game in games] # a list of list, nested list is for equal preference levels
for j, col in enumerate(row):
col = col.replace(" ", "")
if j < ignore_columns: # first two rows are timestamp, and email
continue
if first: # first column, which is the games
game = col[col.find("[") + 1:col.find("]")]
game = regex.sub('', game)
games.append(game)
else: # it's a ballot
without_end = col[:-2]
if without_end: # then there is a number chosen (not empty string)
place = int(without_end) - 1 # "1st" -> 0, , "2nd" -> 1, and so on
ballot[place].append(games[j - ignore_columns])
if ballot:
formatted = []
for choices in ballot:
if choices:
formatted.append(" = ".join(choices))
print(" > ".join(formatted))
first = False