-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathvote.py
44 lines (36 loc) · 1.1 KB
/
vote.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
import csv
import random
import argparse
from os import walk
from os.path import join
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-in', '--folder-path')
args = parser.parse_args()
files = []
for (dirpath, dirnames, filenames) in walk(args.folder_path):
for file in filenames:
if 'csv' in file:
files.append(file)
predictions = dict()
for file in files:
with open(join(args.folder_path, file), 'r') as f:
reader = csv.reader(f)
next(reader)
for row in reader:
try:
predictions[int(row[0])].append(int(row[1]))
except:
predictions[int(row[0])] = [int(row[1])]
with open(join(args.folder_path, 'vote.csv'), 'w') as file:
writer = csv.writer(file)
writer.writerow(['QuestionPairID', 'Prediction'])
for example in predictions:
ones = sum(predictions[example])
zeros = 5 - ones
if ones == zeros:
writer.writerow([example, random.randint(0, 1)])
elif ones > zeros:
writer.writerow([example, 1])
else:
writer.writerow([example, 0])