Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Odevzdávací Systém MO
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Martin Mareš
Odevzdávací Systém MO
Commits
374a889a
Commit
374a889a
authored
8 months ago
by
Martin Mareš
Browse files
Options
Downloads
Patches
Plain Diff
Oddělena funkce na generování exportního JSONu
parent
cea9252d
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
mo/jobs/score.py
+37
-33
37 additions, 33 deletions
mo/jobs/score.py
with
37 additions
and
33 deletions
mo/jobs/score.py
+
37
−
33
View file @
374a889a
...
...
@@ -308,37 +308,8 @@ class ExportScoreToMOWebError(SoftJobError):
pass
@job_handler
(
db
.
JobType
.
export_score_to_mo_web
)
def
handle_export_score_to_mo_web
(
the_job
:
TheJob
):
API_ENDPOINT_JSON
=
"
/Redakce/Api/ScoreboardImporterApi/RawData
"
API_ENDPOINT_PDF
=
"
/Redakce/Api/ScoreboardImporterApi/PdfData
"
job
=
mo
.
util
.
assert_not_none
(
the_job
.
job
)
sess
=
db
.
get_session
()
scoretable_id
:
int
=
job
.
in_json
[
"
scoretable_id
"
]
# type: ignore
score_table
:
db
.
ScoreTable
=
mo
.
util
.
assert_not_none
(
sess
.
query
(
db
.
ScoreTable
).
get
(
scoretable_id
))
contest
:
db
.
Contest
=
mo
.
util
.
assert_not_none
(
sess
.
query
(
db
.
Contest
).
get
(
score_table
.
contest_id
))
round
=
contest
.
round
if
not
round
.
export_score_to_mo_web
:
return
None
def
error
(
err_text
:
str
,
data_format
:
str
,
more_details
=
{}):
mo
.
util
.
log
(
type
=
db
.
LogType
.
contest
,
what
=
contest
.
contest_id
,
details
=
{
'
action
'
:
'
score-export-to-mo-web
'
,
'
scoretable_id
'
:
score_table
.
scoretable_id
,
'
status
'
:
'
fail
'
,
'
format
'
:
data_format
,
**
more_details
},
)
sess
.
commit
()
raise
ExportScoreToMOWebError
(
f
"
Publikování výsledkové listiny (
{
data_format
}
) na webu MO:
{
err_text
}
"
)
# Také voláme z bin/freeze-score
def
get_web_json
(
score_table
:
mo
.
db
.
ScoreTable
):
json_tasks
=
[{
"
code
"
:
t
[
'
code
'
],
"
name
"
:
t
.
get
(
"
name
"
,
None
)
or
None
,
...
...
@@ -365,8 +336,8 @@ def handle_export_score_to_mo_web(the_job: TheJob):
'
status
'
:
"
winner
"
if
c
[
'
winner
'
]
else
"
successful
"
if
c
[
'
successful
'
]
else
None
,
}
for
c
in
score_table
.
rows
]
json
=
{
'
osmo_id
'
:
scoretable_id
,
return
{
'
osmo_id
'
:
score_table
.
scoretable_id
,
'
generated_at
'
:
score_table
.
created_at
.
strftime
(
"
%Y-%m-%d %H:%M:%S
"
),
'
tasks
'
:
json_tasks
,
'
boundary
'
:
{
...
...
@@ -376,6 +347,39 @@ def handle_export_score_to_mo_web(the_job: TheJob):
'
rows
'
:
json_rows
,
}
@job_handler
(
db
.
JobType
.
export_score_to_mo_web
)
def
handle_export_score_to_mo_web
(
the_job
:
TheJob
):
API_ENDPOINT_JSON
=
"
/Redakce/Api/ScoreboardImporterApi/RawData
"
API_ENDPOINT_PDF
=
"
/Redakce/Api/ScoreboardImporterApi/PdfData
"
job
=
mo
.
util
.
assert_not_none
(
the_job
.
job
)
sess
=
db
.
get_session
()
scoretable_id
:
int
=
job
.
in_json
[
"
scoretable_id
"
]
# type: ignore
score_table
:
db
.
ScoreTable
=
mo
.
util
.
assert_not_none
(
sess
.
query
(
db
.
ScoreTable
).
get
(
scoretable_id
))
contest
:
db
.
Contest
=
mo
.
util
.
assert_not_none
(
sess
.
query
(
db
.
Contest
).
get
(
score_table
.
contest_id
))
round
=
contest
.
round
if
not
round
.
export_score_to_mo_web
:
return
None
def
error
(
err_text
:
str
,
data_format
:
str
,
more_details
=
{}):
mo
.
util
.
log
(
type
=
db
.
LogType
.
contest
,
what
=
contest
.
contest_id
,
details
=
{
'
action
'
:
'
score-export-to-mo-web
'
,
'
scoretable_id
'
:
score_table
.
scoretable_id
,
'
status
'
:
'
fail
'
,
'
format
'
:
data_format
,
**
more_details
},
)
sess
.
commit
()
raise
ExportScoreToMOWebError
(
f
"
Publikování výsledkové listiny (
{
data_format
}
) na webu MO:
{
err_text
}
"
)
json
=
get_web_json
(
score_table
)
auth
=
requests
.
auth
.
HTTPBasicAuth
(
config
.
MO_WEB_LOGIN
,
config
.
MO_WEB_PASSWD
)
params
=
api_params
(
contest
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment