Make ioi16 related files cleaner
This commit is contained in:
parent
e10a8aca5c
commit
07d5ad2216
14 changed files with 145 additions and 92 deletions
|
@ -68,7 +68,7 @@ class ContestProblemInlineForm(ModelForm):
|
|||
class Meta:
|
||||
widgets = {
|
||||
"problem": AdminHeavySelect2Widget(data_view="problem_select2"),
|
||||
"frozen_subtasks": TextInput(attrs={"size": "3"}),
|
||||
"hidden_subtasks": TextInput(attrs={"size": "3"}),
|
||||
"points": TextInput(attrs={"size": "1"}),
|
||||
"order": TextInput(attrs={"size": "1"}),
|
||||
"output_prefix_override": TextInput(attrs={"size": "1"}),
|
||||
|
@ -85,7 +85,7 @@ class ContestProblemInline(admin.TabularInline):
|
|||
"partial",
|
||||
"is_pretested",
|
||||
"max_submissions",
|
||||
"frozen_subtasks",
|
||||
"hidden_subtasks",
|
||||
"output_prefix_override",
|
||||
"order",
|
||||
"rejudge_column",
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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
|
||||
|
|
28
judge/migrations/0144_auto_20230103_0523.py
Normal file
28
judge/migrations/0144_auto_20230103_0523.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
# Generated by Django 3.2.16 on 2023-01-02 22:23
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("judge", "0143_auto_20221229_0153"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name="contestproblem",
|
||||
name="frozen_subtasks",
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="contestproblem",
|
||||
name="hidden_subtasks",
|
||||
field=models.CharField(
|
||||
blank=True,
|
||||
help_text="Separated by commas, e.g: 2, 3",
|
||||
max_length=20,
|
||||
null=True,
|
||||
verbose_name="hidden subtasks",
|
||||
),
|
||||
),
|
||||
]
|
|
@ -786,9 +786,9 @@ class ContestProblem(models.Model):
|
|||
MinValueValidator(0, _("Why include a problem you " "can't submit to?"))
|
||||
],
|
||||
)
|
||||
frozen_subtasks = models.CharField(
|
||||
help_text=_("Only for format new IOI. Separated by commas, e.g: 2, 3"),
|
||||
verbose_name=_("frozen subtasks"),
|
||||
hidden_subtasks = models.CharField(
|
||||
help_text=_("Separated by commas, e.g: 2, 3"),
|
||||
verbose_name=_("hidden subtasks"),
|
||||
null=True,
|
||||
blank=True,
|
||||
max_length=20,
|
||||
|
|
|
@ -295,7 +295,7 @@ class ContestMixin(object):
|
|||
context["meta_description"] = self.object.summary or metadata[0]
|
||||
context["og_image"] = self.object.og_image or metadata[1]
|
||||
context["has_moss_api_key"] = settings.MOSS_API_KEY is not None
|
||||
context["can_use_resolver"] = self.object.format_name == "ioi16"
|
||||
context["can_use_resolver"] = self.object.format.has_hidden_subtasks
|
||||
context["logo_override_image"] = self.object.logo_override_image
|
||||
if (
|
||||
not context["logo_override_image"]
|
||||
|
@ -989,7 +989,7 @@ def contest_ranking_ajax(request, contest, participation=None):
|
|||
raise Http404()
|
||||
|
||||
if show_final:
|
||||
if not request.user.is_superuser or contest.format_name != "ioi16":
|
||||
if not request.user.is_superuser or not contest.format.has_hidden_subtasks:
|
||||
raise Http404()
|
||||
|
||||
queryset = contest.users.filter(virtual__gte=0)
|
||||
|
|
|
@ -18,7 +18,7 @@ class Resolver(TemplateView):
|
|||
for order, problem_id in problems:
|
||||
id_to_order[str(problem_id)] = order
|
||||
|
||||
frozen_subtasks = self.contest.format.get_frozen_subtasks()
|
||||
hidden_subtasks = self.contest.format.get_hidden_subtasks()
|
||||
num_problems = len(problems)
|
||||
problem_sub = [0] * num_problems
|
||||
sub_frozen = [0] * num_problems
|
||||
|
@ -122,10 +122,10 @@ class Resolver(TemplateView):
|
|||
self.contest.points_precision,
|
||||
)
|
||||
|
||||
for i in frozen_subtasks:
|
||||
for i in hidden_subtasks:
|
||||
order = id_to_order[i]
|
||||
if frozen_subtasks[i]:
|
||||
sub_frozen[order - 1] = min(frozen_subtasks[i])
|
||||
if hidden_subtasks[i]:
|
||||
sub_frozen[order - 1] = min(hidden_subtasks[i])
|
||||
else:
|
||||
sub_frozen[order - 1] = problem_sub[order - 1] + 1
|
||||
return {
|
||||
|
@ -143,6 +143,6 @@ class Resolver(TemplateView):
|
|||
def get(self, request, *args, **kwargs):
|
||||
if request.user.is_superuser:
|
||||
self.contest = Contest.objects.get(key=kwargs.get("contest"))
|
||||
if self.contest.format_name == "ioi16":
|
||||
if self.contest.format.has_hidden_subtasks:
|
||||
return super(Resolver, self).get(request, *args, **kwargs)
|
||||
return HttpResponseForbidden()
|
||||
|
|
|
@ -226,16 +226,18 @@ class SubmissionStatus(SubmissionDetailBase):
|
|||
return True
|
||||
return False
|
||||
|
||||
def get_frozen_subtasks(self):
|
||||
def get_hidden_subtasks(self):
|
||||
if self.request.user.is_superuser:
|
||||
return set()
|
||||
submission = self.object
|
||||
contest = submission.contest_object
|
||||
if contest and contest.format_name == "ioi16":
|
||||
contest_problem = contest.contest_problems.get(problem=submission.problem)
|
||||
return contest.format.get_frozen_subtasks().get(
|
||||
str(contest_problem.id), set()
|
||||
)
|
||||
if contest and contest.format.has_hidden_subtasks:
|
||||
try:
|
||||
return contest.format.get_hidden_subtasks().get(
|
||||
str(submission.contest.problem.id), set()
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
return set()
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
|
@ -250,7 +252,7 @@ class SubmissionStatus(SubmissionDetailBase):
|
|||
context["highlighted_source"] = highlight_code(
|
||||
submission.source.source, submission.language.pygments, linenos=False
|
||||
)
|
||||
context["frozen_subtasks"] = self.get_frozen_subtasks()
|
||||
context["hidden_subtasks"] = self.get_hidden_subtasks()
|
||||
|
||||
contest = submission.contest_or_none
|
||||
prefix_length = 0
|
||||
|
@ -437,6 +439,13 @@ class SubmissionsListBase(DiggPaginatorMixin, TitleMixin, ListView):
|
|||
hidden_codes += ["IE"]
|
||||
return [(key, value) for key, value in all_statuses if key not in hidden_codes]
|
||||
|
||||
def should_show_result_data(self):
|
||||
return not (
|
||||
self.in_contest
|
||||
and self.contest.format.has_hidden_subtasks
|
||||
and not self.request.user.is_superuser
|
||||
)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(SubmissionsListBase, self).get_context_data(**kwargs)
|
||||
authenticated = self.request.user.is_authenticated
|
||||
|
@ -458,10 +467,13 @@ class SubmissionsListBase(DiggPaginatorMixin, TitleMixin, ListView):
|
|||
context["all_statuses"] = self.get_searchable_status_codes()
|
||||
context["selected_statuses"] = self.selected_statuses
|
||||
|
||||
context["results_json"] = mark_safe(json.dumps(self.get_result_data()))
|
||||
context["results_colors_json"] = mark_safe(
|
||||
json.dumps(settings.DMOJ_STATS_SUBMISSION_RESULT_COLORS)
|
||||
)
|
||||
if self.should_show_result_data():
|
||||
context["results_json"] = mark_safe(json.dumps(self.get_result_data()))
|
||||
context["results_colors_json"] = mark_safe(
|
||||
json.dumps(settings.DMOJ_STATS_SUBMISSION_RESULT_COLORS)
|
||||
)
|
||||
else:
|
||||
context["results_json"] = None
|
||||
|
||||
context["page_suffix"] = suffix = (
|
||||
("?" + self.request.GET.urlencode()) if self.request.GET else ""
|
||||
|
@ -856,13 +868,13 @@ class UserContestSubmissionsAjax(UserContestSubmissions):
|
|||
return None
|
||||
|
||||
def get_best_subtask_points(self):
|
||||
if self.contest.format_name == "ioi16":
|
||||
if self.contest.format.has_hidden_subtasks:
|
||||
contest_problem = self.contest.contest_problems.get(problem=self.problem)
|
||||
best_subtasks = {}
|
||||
total_points = 0
|
||||
problem_points = 0
|
||||
achieved_points = 0
|
||||
frozen_subtasks = self.contest.format.get_frozen_subtasks()
|
||||
hidden_subtasks = self.contest.format.get_hidden_subtasks()
|
||||
|
||||
for (
|
||||
problem_id,
|
||||
|
@ -882,7 +894,7 @@ class UserContestSubmissionsAjax(UserContestSubmissions):
|
|||
problem_points = pp
|
||||
submission = Submission.objects.get(id=sub_id)
|
||||
if (
|
||||
subtask in frozen_subtasks.get(str(problem_id), set())
|
||||
subtask in hidden_subtasks.get(str(problem_id), set())
|
||||
and not self.request.user.is_superuser
|
||||
):
|
||||
best_subtasks[subtask] = {
|
||||
|
@ -930,7 +942,7 @@ class UserContestSubmissionsAjax(UserContestSubmissions):
|
|||
filtered_submissions = []
|
||||
|
||||
# Only show this for some users when using ioi16
|
||||
if self.contest.format_name != "ioi16" or self.request.user.is_superuser:
|
||||
if self.contest.format.has_hidden_subtasks or self.request.user.is_superuser:
|
||||
for s in context["submissions"]:
|
||||
if not hasattr(s, "contest"):
|
||||
continue
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue