From e5ebf68fdbaa982dcd8f134e710a3347b02215ff Mon Sep 17 00:00:00 2001 From: river Date: Fri, 21 Jun 2024 10:40:17 +0800 Subject: [PATCH 1/4] feat: history --- submit.py | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) mode change 100755 => 100644 submit.py diff --git a/submit.py b/submit.py old mode 100755 new mode 100644 index 0daebbd..93476c5 --- a/submit.py +++ b/submit.py @@ -51,6 +51,32 @@ def submit(data, judge_server=None, contest=None, ticket=None): print(e.reason) return None +def get_history(judge_server=None, contest=None, ticket=None): + judge_server = judge_server or JUDGE_SERVER + contest = contest or CONTEST + ticket = ticket or TICKET + + if not judge_server or not contest or not ticket or not submission_id: + missing = [ + "judge_server" if not judge_server else "", + "contest" if not contest else "", + "ticket" if not ticket else "", + ] + missing = [m for m in missing if m] + print("Required fields must be provided: %s" % ', '.join(missing)) + return None + + req = request.Request(judge_server + "/history/", headers={'ticket': ticket, 'contest': contest, 'Content-Type': 'application/json'}) + + try: + with request.urlopen(req) as response: + response_body = response.read().decode('utf-8') + history = json.loads(response_body) + return history + except: + print("Failed to get submission history.") + return None + def check_status(submission_id, judge_server=None, contest=None, ticket=None): judge_server = judge_server or JUDGE_SERVER contest = contest or CONTEST @@ -95,6 +121,7 @@ if __name__ == "__main__": parser.add_argument('-c', '--contest', help='Contest ID, if not specified, the global CONTEST variable will be used') parser.add_argument('-k', '--ticket', help='Submission ticket, if not specified, the global TICKET variable will be used') parser.add_argument('-i', '--submission_id', help='Submission ID, specified if you want to check the submission status', default=None) + parser.add_argument('-H', '--history', help='Get submission history', action='store_true') args = parser.parse_args() @@ -109,17 +136,28 @@ if __name__ == "__main__": if not judge_time: print("Submission %s is still in queue." % submission_id) else: - if score < 0: - print("Submission %s for evaluation has failed. We are currently experiencing issues with the evaluation system. Please check official updates and try again later. This submission will not be counted into your quota." % submission_id) - exit(0) print("Submission %s score: %s" % (submission_id, score)) exit(0) else: print("Failed to check submission status.") exit(1) + elif args.history: + history = get_history(judge_server=args.server, contest=args.contest, ticket=args.ticket) + if history: + print("="*16) + for submission in history: + print(f"Submission {submission['submission_id']}:") + print(f" - Create time: {submission['create_time']}") + print(f" - Judge time: {submission['judge_time']}") + print(f" - Score: {submission['score']}") + print("="*16) + exit(0) + else: + print("Failed to get submission history.") + exit(1) try: - with open(args.result_path, 'r') as file: + with open(args.result_path, 'r', encoding='utf-8') as file: data = [json.loads(line.strip()) for line in file if line.strip()] except Exception as e: print(e) -- GitLab From 42ee22623bbb6db87f3f449abb313ee2a9203092 Mon Sep 17 00:00:00 2001 From: river Date: Fri, 21 Jun 2024 10:45:37 +0800 Subject: [PATCH 2/4] fix: remove submission_id check in get_history --- submit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/submit.py b/submit.py index 93476c5..2a2e68a 100644 --- a/submit.py +++ b/submit.py @@ -56,7 +56,7 @@ def get_history(judge_server=None, contest=None, ticket=None): contest = contest or CONTEST ticket = ticket or TICKET - if not judge_server or not contest or not ticket or not submission_id: + if not judge_server or not contest or not ticket: missing = [ "judge_server" if not judge_server else "", "contest" if not contest else "", -- GitLab From 28faa40a7e61696fee0d61d0df6e1f5ea055202c Mon Sep 17 00:00:00 2001 From: river Date: Fri, 21 Jun 2024 11:05:32 +0800 Subject: [PATCH 3/4] add README --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 242489a..d780d31 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ python submit.py [-h] [-s SERVER] [-c CONTEST] [-k TICKET] [-i SUBMISSION_ID] [r * `-c, --contest`:比赛标识。如果未提供,将使用脚本中定义的 `CONTEST` 变量。 * `-k, --ticket`:团队标识。如果未提供,将使用脚本中定义的 `TICKET` 变量。 * `-i, --submission_id` :提交ID,当指定这一参数时,该脚本将不会提交结果文件,而是会查询该提交ID的结果。 +* `-H, --history`:查询历史提交记录,当指定这一参数时,该脚本将不会提交结果文件,而是会查询给定赛道和团队的历史提交评测结果。 ## 单次提交结果查询 @@ -36,6 +37,14 @@ python submit.py -i -s -c -k 由于评测服务器可能需要一段时间来处理提交,因此您可能需要等待一段时间才能获得结果。 +## 历史提交结果查询 + +示例: + +```bash +python submit.py -H -s -c -k +``` + ## 编程方式提交 您还可以将 `submit` 函数导入到您的 Python 代码中,以便用编程方式提交数据。 -- GitLab From 05dea2fc7ef41722e40b4ed206670112eb93b7ef Mon Sep 17 00:00:00 2001 From: river Date: Fri, 21 Jun 2024 11:09:12 +0800 Subject: [PATCH 4/4] fix: re-add comment --- submit.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/submit.py b/submit.py index 2a2e68a..df8179e 100644 --- a/submit.py +++ b/submit.py @@ -136,6 +136,9 @@ if __name__ == "__main__": if not judge_time: print("Submission %s is still in queue." % submission_id) else: + if score < 0: + print("Submission %s for evaluation has failed. We are currently experiencing issues with the evaluation system. Please check official updates and try again later. This submission will not be counted into your quota." % submission_id) + exit(0) print("Submission %s score: %s" % (submission_id, score)) exit(0) else: -- GitLab