Skip to content

Commit

Permalink
Merge pull request #18 from xcpcio/feat-update-time-for-csg
Browse files Browse the repository at this point in the history
feat: update time for csg
  • Loading branch information
Dup4 authored Nov 11, 2023
2 parents 0d37988 + 8dbb3e0 commit 2b05482
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tests/spider/csg_cpc/v1/csg_cpc_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ def test_spider_csg_cpc_v1_2023_hncpc(snapshot):
fetch_uri = os.path.join(current_dir_path, "test_data/2023_hncpc")

csg_cpc = CSG_CPC(c, fetch_uri)
csg_cpc.fetch().parse_teams().parse_runs()
csg_cpc.fetch().parse_teams().parse_runs().update_contest()

assert len(csg_cpc.teams) == 180
assert len(csg_cpc.runs) == 2336

snapshot.assert_match(csg_cpc.contest.get_json, "contest")
snapshot.assert_match(csg_cpc.teams.get_json, "teams")
snapshot.assert_match(csg_cpc.runs.get_json, "runs")
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"contest_name": "", "start_time": "2023-11-11T15:30:00+08:00", "end_time": "2023-11-11T17:30:00+08:00", "frozen_time": 3600, "penalty": 1200, "problem_quantity": 0, "problem_id": [], "group": {"official": "\u6b63\u5f0f\u961f\u4f0d", "unofficial": "\u6253\u661f\u961f\u4f0d"}, "organization": "School", "status_time_display": {"correct": true, "incorrect": true, "pending": true}, "medal": {}, "options": {}}
16 changes: 16 additions & 0 deletions tests/spider/csg_cpc/v1/test_data/2023_hncpc/contest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"contest_id": 1001,
"title": "第九届中国大学生程序设计竞赛(深圳)- 热身赛",
"start_time": "2023-11-11 15:30:00",
"end_time": "2023-11-11 17:30:00",
"defunct": "0",
"description": "",
"private": 2,
"langmask": 75,
"password": "",
"attach": "2023-11-11_F0EA3F56319521FA",
"topteam": 1,
"award_ratio": 30020010,
"frozen_minute": 60,
"frozen_after": 0
}
13 changes: 13 additions & 0 deletions xcpcio_board_spider/spider/csg_cpc/v1/csg_cpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def __init__(self, contest: Contest,

self.raw_problem_data = []
self.raw_problem_map = {}
self.raw_contest_data = {}
self.raw_team_data = []
self.raw_run_data = []

Expand All @@ -40,6 +41,9 @@ def fetch(self):
raw_team_data = []
raw_run_data = []

resp_obj = self.fetch_resp_obj(self.fetch_uri + "/contest.json")
self.raw_contest_data = resp_obj

resp_obj = self.fetch_resp_obj(self.fetch_uri + "/problem.json")
raw_problem_data.extend(resp_obj)

Expand Down Expand Up @@ -216,3 +220,12 @@ def parse_runs(self):
self.runs = runs

return self

def update_contest(self):
start_time = self.raw_contest_data["start_time"]
end_time = self.raw_contest_data["end_time"]
frozen_minute = self.raw_contest_data["frozen_minute"]

self.contest.start_time = start_time.replace(" ", "T") + "+08:00"
self.contest.end_time = end_time.replace(" ", "T") + "+08:00"
self.contest.frozen_time = int(frozen_minute) * 60

0 comments on commit 2b05482

Please sign in to comment.