-
Notifications
You must be signed in to change notification settings - Fork 62
/
result.py
39 lines (34 loc) · 1.39 KB
/
result.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
import os, json
files = os.listdir('results')
output = ["Model\tOverall\tEasy\tHard\tShort\tMedium\tLong"]
compensated = False
for file in files:
filename = os.path.join('results', file)
try:
pred_data = json.load(open(filename, encoding='utf-8'))
except Exception as e:
pred_data = [json.loads(line) for line in open(filename, encoding='utf-8')]
easy, hard, short, medium, long = 0, 0, 0, 0, 0
easy_acc, hard_acc, short_acc, medium_acc, long_acc = 0, 0, 0, 0, 0
for pred in pred_data:
acc = int(pred['judge'])
if compensated and pred["pred"] == None:
acc = 0.25
if pred["difficulty"] == "easy":
easy += 1
easy_acc += acc
else:
hard += 1
hard_acc += acc
if pred['length'] == "short":
short += 1
short_acc += acc
elif pred['length'] == "medium":
medium += 1
medium_acc += acc
else:
long += 1
long_acc += acc
name = '.'.join(file.split('.')[:-1])
output.append(name+'\t'+str(round(100*(easy_acc+hard_acc)/len(pred_data), 1))+'\t'+str(round(100*easy_acc/easy, 1))+'\t'+str(round(100*hard_acc/hard, 1))+'\t'+str(round(100*short_acc/short, 1))+'\t'+str(round(100*medium_acc/medium, 1))+'\t'+str(round(100*long_acc/long, 1)))
open('result.txt', 'w', encoding='utf-8').write('\n'.join(output))