-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreport.py
89 lines (69 loc) · 2.6 KB
/
report.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import csv
import requests
results = {}
def process_submission(id):
print('Processing submission {}'.format(id), flush=True)
url = 'https://api.judgels/v2/contests/submissions/programming/id/{}'.format(id)
headers = {
'Authorization': 'Bearer xxx'
}
response = requests.get(url, headers=headers)
if response.status_code != 200:
print(vars(response))
return
data = response.json()
username = data['profile']['username']
problemAlias = data['problemAlias']
latestGrading = data['data']['submission']['latestGrading']
results[username][problemAlias]['score'] = latestGrading['score']
details = latestGrading['details']
if details:
for result in details['subtaskResults']:
results[username][problemAlias]['subtask{}_score'.format(result['id'])] = min(1, int(result['score']))
for tgResult in details['testDataResults']:
for tcResult in tgResult['testCaseResults']:
if tcResult['score'] == '*':
for subtaskId in tcResult['subtaskIds']:
if subtaskId > 0:
results[username][problemAlias]['subtask{}_correct_cases'.format(subtaskId)] += 1
usernames = []
with open('contestants.csv', 'r') as file:
reader = csv.reader(file)
header = next(reader)
for row in reader:
usernames.append(row[0])
for username in usernames:
results[username] = {}
for problemAlias in ['A', 'B', 'C', 'D', 'E', 'F']:
results[username][problemAlias] = {
'score': 0,
'subtask1_score': 0,
'subtask1_correct_cases': 0,
'subtask2_score': 0,
'subtask2_correct_cases': 0
}
# TODO fill the submission ID range here
for id in range(1, 5825+1):
process_submission(id)
with open('results.csv', 'w') as file:
writer = csv.writer(file)
for username in usernames:
row = [username]
for problemAlias in ['A', 'B', 'C', 'D', 'E', 'F']:
res = results[username][problemAlias]
row.extend([
res['subtask1_score'],
res['subtask2_score']
])
writer.writerow(row)
with open('results_detailed.csv', 'w') as file:
writer = csv.writer(file)
for username in usernames:
row = [username]
for problemAlias in ['A', 'B', 'C', 'D', 'E', 'F']:
res = results[username][problemAlias]
row.extend([
res['subtask1_correct_cases'],
res['subtask2_correct_cases']
])
writer.writerow(row)