forked from cms-dev/cms
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path__init__.py
More file actions
143 lines (113 loc) · 4.75 KB
/
__init__.py
File metadata and controls
143 lines (113 loc) · 4.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env python3
# Contest Management System - http://cms-dev.github.io/
# Copyright © 2010-2012 Giovanni Mascellani <mascellani@poisson.phc.unipi.it>
# Copyright © 2010-2018 Stefano Maggiolo <s.maggiolo@gmail.com>
# Copyright © 2010-2012 Matteo Boscariol <boscarim@hotmail.com>
# Copyright © 2013 Bernard Blackham <bernard@largestprime.net>
# Copyright © 2013-2018 Luca Wehrstedt <luca.wehrstedt@gmail.com>
# Copyright © 2016 Myungwoo Chun <mc.tamaki@gmail.com>
# Copyright © 2016 Masaki Hara <ackie.h.gmai@gmail.com>
# Copyright © 2016 Amir Keivan Mohtashami <akmohtashami97@gmail.com>
# Copyright © 2018 William Di Luigi <williamdiluigi@gmail.com>
# Copyright © 2026 Tobias Lenz <t_lenz94@web.de>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Utilities functions that interacts with the database.
"""
import logging
from sqlalchemy import create_engine, MetaData
from sqlalchemy.orm import configure_mappers, joinedload, subqueryload
from cms import config
logger = logging.getLogger(__name__)
# Define what this package will provide.
__all__ = [
"version", "engine",
# session
"Session", "ScopedSession", "SessionGen", "custom_psycopg2_connection",
# types
"CastingArray", "Codename", "Filename", "FilenameSchema",
"FilenameSchemaArray", "Digest",
# base
"metadata", "Base",
# fsobject
"FSObject", "LargeObject",
# contest
"Contest", "Announcement",
# user
"Group", "User", "Team", "Participation", "Message", "Question",
# admin
"Admin",
# task
"Task", "Statement", "Attachment", "Dataset", "Manager", "Testcase",
# submission
"Submission", "File", "Token", "SubmissionResult", "Executable",
"Evaluation",
# usertest
"UserTest", "UserTestFile", "UserTestManager", "UserTestResult",
"UserTestExecutable",
# init
"init_db",
# drop
"drop_db",
# util
"test_db_connection", "get_contest_list", "is_contest_id",
"ask_for_contest", "get_submissions", "get_submission_results",
"get_datasets_to_judge", "enumerate_files"
]
# Instantiate or import these objects.
version = 48
engine = create_engine(config.database.url, echo=config.database.debug,
pool_timeout=60, pool_recycle=120)
metadata = MetaData(engine)
from .session import Session, ScopedSession, SessionGen, \
custom_psycopg2_connection
from .types import CastingArray, Codename, Filename, FilenameSchema, \
FilenameSchemaArray, Digest
from .base import Base
from .fsobject import FSObject, LargeObject
from .admin import Admin
from .contest import Contest, Announcement
from .user import Group, User, Team, Participation, Message, Question
from .task import Task, Statement, Attachment, Dataset, Manager, Testcase
from .submission import Submission, File, Token, SubmissionResult, \
Executable, Evaluation
from .usertest import UserTest, UserTestFile, UserTestManager, \
UserTestResult, UserTestExecutable
from .init import init_db
from .drop import drop_db
from .util import test_db_connection, get_contest_list, is_contest_id, \
ask_for_contest, get_submissions, get_submission_results, \
get_datasets_to_judge, enumerate_files
configure_mappers()
# The following is a method of Dataset that cannot be put in the right
# file because of circular dependencies.
def get_submission_results_for_dataset(self, dataset) -> list[SubmissionResult]:
"""Return a list of all submission results against the specified
dataset.
Also preloads the executable and evaluation objects relative to
the submission results.
returns: list of submission results.
"""
# We issue this query manually to optimize it: we load all
# executables and evaluations at once instead of having SA
# lazy-load them when we access them for each SubmissionResult,
# one at a time.
return self.sa_session\
.query(SubmissionResult)\
.filter(SubmissionResult.dataset == dataset)\
.options(joinedload(SubmissionResult.submission))\
.options(subqueryload(SubmissionResult.executables))\
.options(subqueryload(SubmissionResult.evaluations))\
.all()
Dataset.get_submission_results = get_submission_results_for_dataset