提交 4c42072c 编辑于 作者: 刘 玉河's avatar 刘 玉河
浏览文件

Merge branch 'feat_submission_status' into 'main'

Feat submission history

See merge request !3
加载中
加载中
加载中
加载中
+9 −0
原始行号 差异行号 差异行
@@ -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 <submission_id> -s <judge_server> -c <contest> -k <ticket>

由于评测服务器可能需要一段时间来处理提交,因此您可能需要等待一段时间才能获得结果。

## 历史提交结果查询

示例:

```bash
python submit.py -H -s <judge_server> -c <contest> -k <ticket>
```

## 编程方式提交

您还可以将 `submit` 函数导入到您的 Python 代码中,以便用编程方式提交数据。

submit.py

100755 → 100644
+42 −1
原始行号 差异行号 差异行
@@ -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:
        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()

@@ -117,9 +144,23 @@ if __name__ == "__main__":
        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)