Reformat using black

This commit is contained in:
cuom1999 2022-05-14 12:57:27 -05:00
parent efee4ad081
commit a87fb49918
221 changed files with 19127 additions and 7310 deletions

View file

@ -14,13 +14,13 @@ from judge.timezone import from_database_time
from judge.utils.timedelta import nice_repr
@register_contest_format('ioi')
@register_contest_format("ioi")
class IOIContestFormat(DefaultContestFormat):
name = gettext_lazy('IOI')
config_defaults = {'cumtime': False}
'''
name = gettext_lazy("IOI")
config_defaults = {"cumtime": False}
"""
cumtime: Specify True if time penalties are to be computed. Defaults to False.
'''
"""
@classmethod
def validate(cls, config):
@ -28,7 +28,9 @@ class IOIContestFormat(DefaultContestFormat):
return
if not isinstance(config, dict):
raise ValidationError('IOI-styled contest expects no config or dict as config')
raise ValidationError(
"IOI-styled contest expects no config or dict as config"
)
for key, value in config.items():
if key not in cls.config_defaults:
@ -47,7 +49,8 @@ class IOIContestFormat(DefaultContestFormat):
format_data = {}
with connection.cursor() as cursor:
cursor.execute('''
cursor.execute(
"""
SELECT MAX(cs.points) as `score`, (
SELECT MIN(csub.date)
FROM judge_contestsubmission ccs LEFT OUTER JOIN
@ -58,17 +61,21 @@ class IOIContestFormat(DefaultContestFormat):
judge_contestsubmission cs ON (cs.problem_id = cp.id AND cs.participation_id = %s) LEFT OUTER JOIN
judge_submission sub ON (sub.id = cs.submission_id)
GROUP BY cp.id
''', (participation.id, participation.id))
""",
(participation.id, participation.id),
)
for score, time, prob in cursor.fetchall():
if self.config['cumtime']:
dt = (from_database_time(time) - participation.start).total_seconds()
if self.config["cumtime"]:
dt = (
from_database_time(time) - participation.start
).total_seconds()
if score:
cumtime += dt
else:
dt = 0
format_data[str(prob)] = {'time': dt, 'points': score}
format_data[str(prob)] = {"time": dt, "points": score}
points += score
participation.cumtime = max(cumtime, 0)
@ -82,12 +89,29 @@ class IOIContestFormat(DefaultContestFormat):
if format_data:
return format_html(
'<td class="{state} problem-score-col"><a href="{url}">{points}<div class="solving-time">{time}</div></a></td>',
state=(('pretest-' if self.contest.run_pretests_only and contest_problem.is_pretested else '') +
self.best_solution_state(format_data['points'], contest_problem.points)),
url=reverse('contest_user_submissions',
args=[self.contest.key, participation.user.user.username, contest_problem.problem.code]),
points=floatformat(format_data['points']),
time=nice_repr(timedelta(seconds=format_data['time']), 'noday') if self.config['cumtime'] else '',
state=(
(
"pretest-"
if self.contest.run_pretests_only
and contest_problem.is_pretested
else ""
)
+ self.best_solution_state(
format_data["points"], contest_problem.points
)
),
url=reverse(
"contest_user_submissions",
args=[
self.contest.key,
participation.user.user.username,
contest_problem.problem.code,
],
),
points=floatformat(format_data["points"]),
time=nice_repr(timedelta(seconds=format_data["time"]), "noday")
if self.config["cumtime"]
else "",
)
else:
return mark_safe('<td class="problem-score-col"></td>')
@ -96,5 +120,7 @@ class IOIContestFormat(DefaultContestFormat):
return format_html(
'<td class="user-points">{points}<div class="solving-time">{cumtime}</div></td>',
points=floatformat(participation.score),
cumtime=nice_repr(timedelta(seconds=participation.cumtime), 'noday') if self.config['cumtime'] else '',
cumtime=nice_repr(timedelta(seconds=participation.cumtime), "noday")
if self.config["cumtime"]
else "",
)