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
cbed27b6
Commit
cbed27b6
authored
2 weeks ago
by
Martin Mareš
Browse files
Options
Downloads
Patches
Plain Diff
export-pion: Body
parent
33899392
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
bin/export-pion
+23
-2
23 additions, 2 deletions
bin/export-pion
with
23 additions
and
2 deletions
bin/export-pion
+
23
−
2
View file @
cbed27b6
#!/usr/bin/env python3
# Účast ve všech soutěžích ročníku (anonymně)
# Účast
a body
ve všech soutěžích ročníku (anonymně)
from
collections
import
defaultdict
from
dataclasses
import
dataclass
from
decimal
import
Decimal
from
sqlalchemy
import
and_
from
sqlalchemy.orm
import
joinedload
import
sys
from
typing
import
DefaultDict
,
Tuple
import
mo.csv
import
mo.db
as
db
from
mo.util
import
assert_not_none
from
mo.util_format
import
format_decimal
sess
=
db
.
get_session
()
points_by_uid_roundid
:
DefaultDict
[
Tuple
[
int
,
int
],
Decimal
]
=
defaultdict
(
Decimal
)
sols
=
(
sess
.
query
(
db
.
Solution
)
.
options
(
joinedload
(
db
.
Solution
.
task
))
.
all
())
for
sol
in
sols
:
if
sol
.
points
is
not
None
:
points_by_uid_roundid
[
sol
.
user_id
,
sol
.
task
.
round_id
]
+=
sol
.
points
res
=
(
sess
.
query
(
db
.
Participant
,
db
.
Participation
,
db
.
Contest
,
db
.
Round
)
.
select_from
(
db
.
Participant
)
.
join
(
db
.
Participation
,
db
.
Participation
.
user_id
==
db
.
Participant
.
user_id
)
...
...
@@ -24,7 +39,7 @@ res = (sess.query(db.Participant, db.Participation, db.Contest, db.Round)
@dataclass
class
Row
:
class
Row
(
mo
.
csv
.
Row
)
:
rocnik
:
str
=
""
kategorie
:
str
=
""
kolo_seq
:
str
=
""
...
...
@@ -41,11 +56,16 @@ class Row:
kraj_skoly
:
str
=
""
nuts_skoly
:
str
=
""
odhad_pohlavi
:
str
=
""
body
:
str
=
""
output
=
[]
for
pant
,
pion
,
ct
,
rnd
in
res
:
female_guess
=
pant
.
user
.
last_name
.
endswith
(
'
á
'
)
if
(
pion
.
user_id
,
rnd
.
round_id
)
in
points_by_uid_roundid
:
points
=
assert_not_none
(
format_decimal
(
points_by_uid_roundid
[
pion
.
user_id
,
rnd
.
round_id
]))
else
:
points
=
""
output
.
append
(
Row
(
rocnik
=
str
(
rnd
.
year
),
kategorie
=
rnd
.
category
,
...
...
@@ -63,6 +83,7 @@ for pant, pion, ct, rnd in res:
kraj_skoly
=
pant
.
school_place
.
parent_place
.
parent_place
.
parent_place
.
name
,
nuts_skoly
=
pant
.
school_place
.
parent_place
.
parent_place
.
nuts
,
odhad_pohlavi
=
"
Ž
"
if
female_guess
else
"
M
"
,
body
=
points
,
))
output
.
sort
(
key
=
lambda
o
:
(
o
.
rocnik
,
o
.
kategorie
,
o
.
kolo_seq
,
o
.
id_mista
,
o
.
id_ucastnika
))
...
...
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