Skip to content
GitLab
探索
登录
注册
主导航
搜索或转到…
项目
A
aiops-2024-submit
管理
动态
成员
标记
计划
议题
0
议题看板
里程碑
代码
合并请求
0
仓库
分支
提交
标签
仓库图
比较修订版本
代码片段
部署
发布
软件包库
运维
Terraform 模块
监控
事件
服务台
分析
价值流分析
Contributor analytics
仓库分析
模型实验
帮助
帮助
支持
GitLab 文档
比较 GitLab 各版本
社区论坛
为极狐GitLab 提交贡献
提交反馈
快捷键
?
支持
扫码加入微信群
1. 获取企业级DevOps解决方案
2. 免费或优惠考取极狐GitLab官方培训认证
代码片段
群组
项目
aiops-challenge
aiops-2024-submit
提交
c031678e
提交
c031678e
编辑于
9个月前
作者:
刘 玉河
浏览文件
操作
下载
差异文件
Merge branch 'feat_submission_status' into 'main'
Feat submission status See merge request
!1
上级
d2ab5236
cc4463e2
分支
分支 包含提交
1 合并请求
!1
Feat submission status
变更
2
隐藏空白变更内容
行内
左右并排
显示
2 个更改的文件
README.md
+15
-2
15 个添加, 2 个删除
README.md
submit.py
+63
-3
63 个添加, 3 个删除
submit.py
有
78 个添加
和
5 个删除
README.md
+
15
−
2
浏览文件 @
c031678e
...
...
@@ -15,13 +15,26 @@
要从命令行使用该脚本,请切换到该脚本所在目录,用 Python 运行该脚本:
```
bash
python submit.py
[
-h
]
[
-s
SERVER]
[
-c
CONTEST]
[
-k
TICKET]
[
result_path]
python submit.py
[
-h
]
[
-s
SERVER]
[
-c
CONTEST]
[
-k
TICKET]
[
-i
SUBMISSION_ID]
[
result_path]
```
*
`[result_path]`
:提交的结果文件路径。如果未指定,默认使用当前目录下的
`result.jsonl`
。
*
`-s, --server`
:指定评测服务器的 URL。如果未提供,将使用脚本中定义的
`JUDGE_SERVER`
变量。
*
`-c, --contest`
:比赛标识。如果未提供,将使用脚本中定义的
`CONTEST`
变量。
*
`-k, --ticket`
:团队标识。如果未提供,将使用脚本中定义的
`TICKET`
变量。
*
`-i, --submission_id`
:提交ID,当指定这一参数时,该脚本将不会提交结果文件,而是会查询该提交ID的结果。
## 单次提交结果查询
未指定
`-i`
参数时,脚本将提交结果文件并返回提交 ID。
提交结果文件的一段时间后,您可以通过指定
`-i`
参数来查询单次提交的结果。
```
bash
python submit.py
-i
<submission_id>
-s
<judge_server>
-c
<contest>
-k
<ticket>
```
由于评测服务器可能需要一段时间来处理提交,因此您可能需要等待一段时间才能获得结果。
## 编程方式提交
...
...
@@ -45,7 +58,7 @@ python submit.py [-h] [-s SERVER] [-c CONTEST] [-k TICKET] [result_path]
{"id": 3, "query": "问题 3", "answer": "答案 3"},
# 根据需要添加更多项
]
submission_id = submit(data, judge_server='http://judge.aiops-challenge.com', contest='YOUR_CONTEST_ID', ticket='YOUR_TEAM_TICKET')
if submission_id:
print("提交成功!提交 ID: ", submission_id)
...
...
This diff is collapsed.
Click to expand it.
submit.py
+
63
−
3
浏览文件 @
c031678e
...
...
@@ -34,7 +34,46 @@ def submit(data, judge_server=None, contest=None, ticket=None):
try
:
with
request
.
urlopen
(
req
)
as
response
:
response_body
=
response
.
read
().
decode
(
'
utf-8
'
)
return
json
.
loads
(
response_body
)[
'
submission_id
'
]
submission_id
=
json
.
loads
(
response_body
)[
'
submission_id
'
]
remaining_attempts
=
json
.
loads
(
response_body
).
get
(
'
remaining_attempts
'
,
-
1
)
return
submission_id
,
remaining_attempts
except
error
.
HTTPError
as
e
:
msg
=
e
.
reason
response_body
=
e
.
read
().
decode
(
'
utf-8
'
)
if
response_body
:
try
:
msg
=
json
.
loads
(
response_body
)[
'
detail
'
]
except
:
pass
print
(
"
[Error %s] %s
"
%
(
e
.
code
,
msg
))
except
error
.
URLError
as
e
:
print
(
e
.
reason
)
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
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
""
,
"
submission_id
"
if
not
submission_id
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
+
"
/status/
"
,
headers
=
{
'
ticket
'
:
ticket
,
'
contest
'
:
contest
,
'
submission_id
'
:
submission_id
,
'
Content-Type
'
:
'
application/json
'
})
try
:
with
request
.
urlopen
(
req
)
as
response
:
response_body
=
response
.
read
().
decode
(
'
utf-8
'
)
status
=
json
.
loads
(
response_body
)
return
status
except
error
.
HTTPError
as
e
:
msg
=
e
.
reason
response_body
=
e
.
read
().
decode
(
'
utf-8
'
)
...
...
@@ -55,9 +94,27 @@ if __name__ == "__main__":
parser
.
add_argument
(
'
-s
'
,
'
--server
'
,
help
=
'
Judge server URL, if not specified, the global JUDGE_SERVER variable will be used
'
)
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
)
args
=
parser
.
parse_args
()
if
args
.
submission_id
:
status
=
check_status
(
args
.
submission_id
,
judge_server
=
args
.
server
,
contest
=
args
.
contest
,
ticket
=
args
.
ticket
)
if
status
:
submission_id
=
status
.
get
(
'
submission_id
'
)
score
=
status
.
get
(
'
score
'
)
create_time
=
status
.
get
(
'
create_time
'
)
judge_time
=
status
.
get
(
'
judge_time
'
)
if
not
judge_time
:
print
(
"
Submission %s is still in queue.
"
%
submission_id
)
else
:
print
(
"
Submission %s score: %s
"
%
(
submission_id
,
score
))
exit
(
0
)
else
:
print
(
"
Failed to check submission status.
"
)
exit
(
1
)
try
:
with
open
(
args
.
result_path
,
'
r
'
)
as
file
:
data
=
[
json
.
loads
(
line
.
strip
())
for
line
in
file
if
line
.
strip
()]
...
...
@@ -65,9 +122,12 @@ if __name__ == "__main__":
print
(
e
)
exit
(
1
)
submission_id
=
submit
(
data
,
judge_server
=
args
.
server
,
contest
=
args
.
contest
,
ticket
=
args
.
ticket
)
if
submission_id
:
return_data
=
submit
(
data
,
judge_server
=
args
.
server
,
contest
=
args
.
contest
,
ticket
=
args
.
ticket
)
if
return_data
:
submission_id
,
remaining_attempts
=
return_data
print
(
"
Success! Your submission ID is %s.
"
%
submission_id
)
if
remaining_attempts
>=
0
:
print
(
"
You have %d remaining evaluation attempt(s).
"
%
remaining_attempts
)
exit
(
0
)
else
:
exit
(
1
)
This diff is collapsed.
Click to expand it.
预览
0%
请重试
或
添加新附件
.
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
保存评论
取消
想要评论请
注册
或
登录