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
|
||||
|
|
|
@ -842,7 +842,7 @@ select {
|
|||
}
|
||||
|
||||
.background-d6e8f7 {
|
||||
background-color: d6e8f7;
|
||||
background-color: #d6e8f7;
|
||||
}
|
||||
|
||||
.background-bisque {
|
||||
|
|
|
@ -1786,6 +1786,9 @@ noscript #noscript {
|
|||
.blue {
|
||||
color: rgb(51, 125, 255);
|
||||
}
|
||||
.background-d6e8f7 {
|
||||
background-color: rgb(38, 41, 43);
|
||||
}
|
||||
.background-bisque {
|
||||
background-color: rgb(86, 47, 0);
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
{% include "problem/left-sidebar.html" %}
|
||||
{% endblock %}
|
||||
|
||||
{% set in_ioi16 = request.in_contest_mode and request.participation.contest.format_name == "ioi16" %}
|
||||
{% set has_hidden_subtasks = request.in_contest_mode and request.participation.contest.format.has_hidden_subtasks %}
|
||||
|
||||
{% block middle_content %}
|
||||
<div id="content-left" class="problems">
|
||||
|
@ -11,7 +11,7 @@
|
|||
<thead>
|
||||
<tr>
|
||||
{% if request.in_contest_mode %}
|
||||
{% if request.user.is_authenticated and not in_ioi16 %}
|
||||
{% if request.user.is_authenticated and not has_hidden_subtasks %}
|
||||
<th class="solved"><i class="fa fa-check"></i></th>
|
||||
{% endif %}
|
||||
<th class="problem">{{ _('Problem') }}</th>
|
||||
|
@ -20,7 +20,7 @@
|
|||
<th>{{ _('Types') }}</th>
|
||||
{% endif %}
|
||||
<th class="points">{{ _('Points') }}</th>
|
||||
{% if not in_ioi16 %}
|
||||
{% if not has_hidden_subtasks %}
|
||||
<th class="users">{{ _('Users') }}</th>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
|
@ -64,7 +64,7 @@
|
|||
<tbody>
|
||||
{% for problem in object_list %}
|
||||
<tr>
|
||||
{% if request.user.is_authenticated and not in_ioi16 %}
|
||||
{% if request.user.is_authenticated and not has_hidden_subtasks %}
|
||||
{% if problem.id in completed_problem_ids %}
|
||||
<td solved="1">
|
||||
<a href="{{ url('user_submissions', problem.code, request.user.username) }}">
|
||||
|
@ -115,7 +115,7 @@
|
|||
{% if not request.in_contest_mode %}
|
||||
<td class="ac-rate">{{ problem.ac_rate|floatformat(0) }}%</td>
|
||||
{% endif %}
|
||||
{% if not in_ioi16 %}
|
||||
{% if not has_hidden_subtasks %}
|
||||
<td class="users">
|
||||
<a href="{{ url('ranked_submissions', problem.code) }}">
|
||||
{% if not request.in_contest_mode or not hide_contest_scoreboard %}
|
||||
|
|
|
@ -23,7 +23,9 @@
|
|||
window.show_problem = 0;
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
window.results_json = {{ results_json }};
|
||||
{% if results_json %}
|
||||
window.results_json = {{ results_json }};
|
||||
{% endif %}
|
||||
</script>
|
||||
|
||||
{% compress js %}
|
||||
|
@ -85,49 +87,51 @@
|
|||
});
|
||||
|
||||
// Draw the statistics graph.
|
||||
var chart = null;
|
||||
function stats_graph(raw_data) {
|
||||
var colors = {{ results_colors_json }};
|
||||
{% if results_json %}
|
||||
var chart = null;
|
||||
function stats_graph(raw_data) {
|
||||
var colors = {{ results_colors_json }};
|
||||
|
||||
var ctx = $('#status-graph').find('canvas')[0].getContext('2d');
|
||||
var font = $('body').css('font-family');
|
||||
if (chart !== null) {
|
||||
chart.destroy();
|
||||
var ctx = $('#status-graph').find('canvas')[0].getContext('2d');
|
||||
var font = $('body').css('font-family');
|
||||
if (chart !== null) {
|
||||
chart.destroy();
|
||||
}
|
||||
chart = new Chart(ctx, {
|
||||
type: 'pie',
|
||||
data: {
|
||||
datasets: [{
|
||||
data: raw_data.categories.map(function(entry) {
|
||||
return entry.count;
|
||||
}),
|
||||
backgroundColor: raw_data.categories.map(function(entry) {
|
||||
return colors[entry.code];
|
||||
}),
|
||||
}],
|
||||
labels: raw_data.categories.map(function(entry) {
|
||||
return entry.name;
|
||||
}),
|
||||
},
|
||||
options: {
|
||||
animation: false,
|
||||
scaleFontFamily: font,
|
||||
tooltips: {
|
||||
titleFontFamily: font,
|
||||
bodyFontFamily: font,
|
||||
},
|
||||
legend: {
|
||||
display: false,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
$('#total-submission-count').text(raw_data.total);
|
||||
}
|
||||
chart = new Chart(ctx, {
|
||||
type: 'pie',
|
||||
data: {
|
||||
datasets: [{
|
||||
data: raw_data.categories.map(function(entry) {
|
||||
return entry.count;
|
||||
}),
|
||||
backgroundColor: raw_data.categories.map(function(entry) {
|
||||
return colors[entry.code];
|
||||
}),
|
||||
}],
|
||||
labels: raw_data.categories.map(function(entry) {
|
||||
return entry.name;
|
||||
}),
|
||||
},
|
||||
options: {
|
||||
animation: false,
|
||||
scaleFontFamily: font,
|
||||
tooltips: {
|
||||
titleFontFamily: font,
|
||||
bodyFontFamily: font,
|
||||
},
|
||||
legend: {
|
||||
display: false,
|
||||
},
|
||||
},
|
||||
|
||||
$(function () {
|
||||
stats_graph(window.results_json);
|
||||
});
|
||||
|
||||
$('#total-submission-count').text(raw_data.total);
|
||||
}
|
||||
|
||||
$(function () {
|
||||
stats_graph(window.results_json);
|
||||
});
|
||||
{% endif %}
|
||||
|
||||
function load_dynamic_update(last_msg) {
|
||||
var _collect = function (e) {
|
||||
|
@ -323,8 +327,7 @@
|
|||
{% endblock %}
|
||||
|
||||
{% block right_sidebar %}
|
||||
{% set hide_sidebar = request.in_contest_mode and request.participation.contest.format_name == "ioi16" and not request.user.is_superuser %}
|
||||
{% if not hide_sidebar %}
|
||||
{% if results_json %}
|
||||
<div class="right-sidebar">
|
||||
<div class="submission">
|
||||
<div class="sidebox">
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{% set can_view = submission_layout(submission, profile_id, request.user, editable_problem_ids, completed_problem_ids) %}
|
||||
{% set hidden = submission.contest_object and submission.contest_object.format_name == "ioi16" and not request.user.is_superuser %}
|
||||
{% set hidden = submission.contest_object and submission.contest_object.format.has_hidden_subtasks and not request.user.is_superuser %}
|
||||
{% if hidden %}
|
||||
<div class="sub-result TLE">
|
||||
<div class="score">
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
{% endif %}
|
||||
|
||||
{% for batch in batches %}
|
||||
{% if batch.id not in frozen_subtasks %}
|
||||
{% if batch.id not in hidden_subtasks %}
|
||||
<div style="margin-top: 0.5em;">
|
||||
{% if batch.id %}
|
||||
<b>{{ _('Batch ') }}#{{ batch.id }} ({{batch.points|floatformat}} / {{batch.total|floatformat}}): </b>
|
||||
|
@ -52,7 +52,7 @@
|
|||
<br>
|
||||
|
||||
<table class="testcases-table">
|
||||
{% if submission.is_graded and submission.result != 'AB' and not frozen_subtasks %}
|
||||
{% if submission.is_graded and submission.result != 'AB' and not hidden_subtasks %}
|
||||
<thead>
|
||||
<tr id="overall-row" class="case-row overall-result-{{submission.result}}">
|
||||
<td><span class="col-title">{{_('Overall: ')}}</span>
|
||||
|
@ -90,7 +90,7 @@
|
|||
|
||||
<tbody>
|
||||
{% for batch in batches %}
|
||||
{% if batch.id not in frozen_subtasks %}
|
||||
{% if batch.id not in hidden_subtasks %}
|
||||
{% if batch.id %}
|
||||
{% set batch_AC = (batch.points == batch.total) %}
|
||||
<tr class="case-row background-{{'d6e8f7' if batch.points == batch.total else 'bisque'}}">
|
||||
|
|
Loading…
Reference in a new issue