Make ioi16 related files cleaner

This commit is contained in:
cuom1999 2023-01-02 17:22:45 -06:00
parent e10a8aca5c
commit 07d5ad2216
14 changed files with 145 additions and 92 deletions

View file

@ -16,6 +16,9 @@ class BaseContestFormat(metaclass=ABCMeta):
self.config = config
self.contest = contest
# Use in ioi16 to display ranking with hidden subtasks
self.has_hidden_subtasks = False
@abstractproperty
def name(self):
"""
@ -98,9 +101,9 @@ class BaseContestFormat(metaclass=ABCMeta):
return "partial-score"
def handle_frozen_state(self, participation, format_data):
frozen_subtasks = {}
if hasattr(self, "get_frozen_subtasks"):
frozen_subtasks = self.get_frozen_subtasks()
hidden_subtasks = {}
if hasattr(self, "get_hidden_subtasks"):
hidden_subtasks = self.get_hidden_subtasks()
queryset = participation.submissions.values("problem_id").annotate(
time=Max("submission__date")
@ -113,7 +116,7 @@ class BaseContestFormat(metaclass=ABCMeta):
and result["time"]
>= self.contest.freeze_after + participation.start
)
if is_after_freeze or frozen_subtasks.get(problem):
if is_after_freeze or hidden_subtasks.get(problem):
format_data[problem]["frozen"] = True
else:
format_data[problem] = {"time": 0, "points": 0, "frozen": True}

View file

@ -14,14 +14,18 @@ class NewIOIContestFormat(IOIContestFormat):
cumtime: Specify True if time penalties are to be computed. Defaults to False.
"""
def get_frozen_subtasks(self):
queryset = self.contest.contest_problems.values_list("id", "frozen_subtasks")
def __init__(self, contest, config):
super().__init__(contest, config)
self.has_hidden_subtasks = True
def get_hidden_subtasks(self):
queryset = self.contest.contest_problems.values_list("id", "hidden_subtasks")
res = {}
for problem_id, frozen_subtasks in queryset:
for problem_id, hidden_subtasks in queryset:
subtasks = set()
if frozen_subtasks:
frozen_subtasks = frozen_subtasks.split(",")
for i in frozen_subtasks:
if hidden_subtasks:
hidden_subtasks = hidden_subtasks.split(",")
for i in hidden_subtasks:
try:
subtasks.add(int(i))
except Exception as e:
@ -100,7 +104,7 @@ class NewIOIContestFormat(IOIContestFormat):
return cursor.fetchall()
def update_participation(self, participation):
frozen_subtasks = self.get_frozen_subtasks()
hidden_subtasks = self.get_hidden_subtasks()
def calculate_format_data(participation, include_frozen):
format_data = {}
@ -127,7 +131,7 @@ class NewIOIContestFormat(IOIContestFormat):
"total_points": 0,
}
if (
subtask not in frozen_subtasks.get(problem_id, set())
subtask not in hidden_subtasks.get(problem_id, set())
or include_frozen
):
format_data[problem_id]["points"] += subtask_points