Skip to content
Snippets Groups Projects
Commit 830c61e7 authored by Jiří Kalvoda's avatar Jiří Kalvoda
Browse files

Kostra exportu výsledkovky na web MO

parent 70c37552
Branches
No related tags found
1 merge request!117Publikace výsledkovky na web MO
...@@ -28,6 +28,7 @@ python-magic==0.4.24 ...@@ -28,6 +28,7 @@ python-magic==0.4.24
python-poppler==0.2.2 python-poppler==0.2.2
pytz==2020.5 pytz==2020.5
pyzbar==0.1.8 pyzbar==0.1.8
requests==2.28.1
six==1.15.0 six==1.15.0
SQLAlchemy==1.3.22 SQLAlchemy==1.3.22
typing-extensions==3.10.0.0 typing-extensions==3.10.0.0
... ...
......
...@@ -335,7 +335,8 @@ CREATE TYPE job_type AS ENUM ( ...@@ -335,7 +335,8 @@ CREATE TYPE job_type AS ENUM (
'process_scans', 'process_scans',
'fix_submits', 'fix_submits',
'send_grading_info', 'send_grading_info',
'snapshot_score' 'snapshot_score',
'export_score_to_mo_web'
); );
CREATE TYPE job_state AS ENUM ( CREATE TYPE job_state AS ENUM (
... ...
......
...@@ -13,3 +13,5 @@ CREATE TYPE round_type AS ENUM ( ...@@ -13,3 +13,5 @@ CREATE TYPE round_type AS ENUM (
ALTER TABLE rounds ADD COLUMN ALTER TABLE rounds ADD COLUMN
round_type round_type NOT NULL DEFAULT 'other'; round_type round_type NOT NULL DEFAULT 'other';
ALTER TYPE job_type ADD VALUE 'export_score_to_mo_web';
...@@ -64,3 +64,6 @@ CURRENT_YEAR = 71 ...@@ -64,3 +64,6 @@ CURRENT_YEAR = 71
# Pokud se neuvede nebo je None, praktické úlohy nejde odevzdávat. # Pokud se neuvede nebo je None, praktické úlohy nejde odevzdávat.
# CMS_ROOT = 'https://contest.kam.mff.cuni.cz/cms/' # CMS_ROOT = 'https://contest.kam.mff.cuni.cz/cms/'
# CMS_SSO_SECRET = 'BrumBrum' # CMS_SSO_SECRET = 'BrumBrum'
# Instance serveru Matematické olympiády, kam bude exportována výsledkovka
MO_WEB_SERVER = 'http://localhost:5001'
...@@ -754,6 +754,7 @@ class JobType(MOEnum): ...@@ -754,6 +754,7 @@ class JobType(MOEnum):
fix_submits = auto() fix_submits = auto()
send_grading_info = auto() send_grading_info = auto()
snapshot_score = auto() snapshot_score = auto()
export_score_to_mo_web = auto()
class JobState(MOEnum): class JobState(MOEnum):
... ...
......
...@@ -2,9 +2,11 @@ ...@@ -2,9 +2,11 @@
import decimal import decimal
import json import json
import requests
from typing import Iterable, List, Optional, Tuple from typing import Iterable, List, Optional, Tuple
import mo import mo
import mo.config as config
import mo.db as db import mo.db as db
from mo.jobs import TheJob, job_handler from mo.jobs import TheJob, job_handler
from mo.score import Score from mo.score import Score
...@@ -102,3 +104,61 @@ def handle_snapshot_score(the_job: TheJob): ...@@ -102,3 +104,61 @@ def handle_snapshot_score(the_job: TheJob):
sess.commit() sess.commit()
job.result = 'Zmrazení výsledkové listiny: Hotovo' job.result = 'Zmrazení výsledkové listiny: Hotovo'
#
# Job export_score_to_mo_web: Exportuje výsledkovou listinu na stránky matematické olympiády
#
# Běží pod systémovým uživatelem. (Například proto, aby nebylo možné job smazat před tím, než začne běžet.)
#
# Vstupní JSON:
# { 'scoretable_id': int,
# }
#
# Výstupní JSON:
# null
#
def schedule_export_score_to_mo_web(score_table: db.ScoreTable) -> None:
the_job = TheJob()
job = the_job.create(db.JobType.export_score_to_mo_web, db.get_system_user())
job.description = 'Publikování výsledkové listiny na webu MO'
job.in_json = {"scoretable_id": score_table.scoretable_id}
the_job.submit()
@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
json_tasks = [] # TODO
json_rows = [] # TODO
json = {
'osmo_id': scoretable_id,
'generated_at': score_table.created_at.strftime("%Y-%m-%d %H:%M:%S"),
'tasks': json_tasks,
'boundary': {'winner': None, 'successful': None},
'rows': json_rows,
}
params = {
'season': round.year,
'category': round.category,
'round': mo.util.assert_not_none(round.round_type.letter()),
'region': contest.place.nuts,
}
reply = requests.post(url=config.MO_WEB_SERVER + API_ENDPOINT_JSON, params=params, json=json)
job.result = 'Publikování výsledkové listiny na webu MO: Hotovo'
...@@ -297,6 +297,7 @@ def org_score_snapshots(ct_id: int): ...@@ -297,6 +297,7 @@ def org_score_snapshots(ct_id: int):
break break
if found and set_final_form.submit_set_final: if found and set_final_form.submit_set_final:
ctx.contest.scoretable_id = scoretable_id ctx.contest.scoretable_id = scoretable_id
mo.jobs.score.schedule_export_score_to_mo_web(scoretable)
mo.util.log( mo.util.log(
type=db.LogType.contest, type=db.LogType.contest,
what=ctx.contest.contest_id, what=ctx.contest.contest_id,
... ...
......
...@@ -44,6 +44,7 @@ setuptools.setup( ...@@ -44,6 +44,7 @@ setuptools.setup(
'python-magic', 'python-magic',
'python-poppler', 'python-poppler',
'pyzbar', 'pyzbar',
'requests',
'sqlalchemy', 'sqlalchemy',
'uwsgidecorators', 'uwsgidecorators',
], ],
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment