-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathgen.py
28 lines (22 loc) · 941 Bytes
/
gen.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
import json
raw_data = [[y for y in x.strip().split("\t") if y] for x in open("ratings.txt")]
title = [x.replace(" ", "") for x in raw_data[0]] + ["ContestID_en"] + ["ContestID_zh"]
body = raw_data[1:]
def contest_slug_to_id_en(contest_slug: str) -> str:
idx = contest_slug.split("-")[-1]
if contest_slug.startswith("bi"):
return f"Biweekly Contest {idx}"
else:
return f"Weekly Contest {idx}"
def contest_slug_to_id_zh(contest_slug: str) -> str:
idx = contest_slug.split("-")[-1]
if contest_slug.startswith("bi"):
return f"第 {idx} 场双周赛"
else:
return f"第 {idx} 场周赛"
obj = list()
for line in body:
line = [float(line[0]), int(line[1]), line[2], line[3], line[4], line[5], line[6], contest_slug_to_id_en(line[5]), contest_slug_to_id_zh(line[5])]
obj.append({k: v for k, v in zip(title, line)})
with open("data.json", "w") as fout:
json.dump(obj, fout)