Skip to content

Commit

Permalink
Add Notice task type
Browse files Browse the repository at this point in the history
  • Loading branch information
ranaldmiao authored and pobrn committed Aug 5, 2023
1 parent 8fad02d commit 2af71ca
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 15 deletions.
65 changes: 65 additions & 0 deletions cms/grading/tasktypes/Notice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# Contest Management System - http://cms-dev.github.io/
# Copyright © 2017 Amir Keivan Mohtashami <[email protected]>
#
# 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/>.

"""Task type for notice tasks.
"""
import logging

from . import TaskType

logger = logging.getLogger(__name__)


# Dummy function to mark translatable string.
def N_(message):
return message


class Notice(TaskType):

ACCEPTED_PARAMETERS = []
ALLOW_SUBMISSION = False

testable = False

def get_compilation_commands(self, unused_submission_format):
"""See TaskType.get_compilation_commands."""
return None

def get_user_managers(self, unused_submission_format):
"""See TaskType.get_user_managers."""
return []

def get_auto_managers(self):
"""See TaskType.get_auto_managers."""
return []

def compile(self, job, file_cacher):
"""See TaskType.compile."""
# No compilation needed.
job.success = True
job.compilation_success = True
job.text = [N_("No compilation needed")]
job.plus = {}

def evaluate(self, job, file_cacher):
job.success = True
job.outcome = "0.0"
job.text = ""
job.plus = {}
1 change: 1 addition & 0 deletions cms/grading/tasktypes/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class TaskType(metaclass=ABCMeta):
# submit only some of the required files; moreover, we try to fill
# the non-provided files with the one in the previous submission.
ALLOW_PARTIAL_SUBMISSION = False
ALLOW_SUBMISSION = True

# A list of all the accepted parameters for this task type.
# Each item is an instance of TaskTypeParameter.
Expand Down
4 changes: 4 additions & 0 deletions cms/server/contest/handlers/tasksubmission.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ def get(self, task_name):
if task is None:
raise tornado_web.HTTPError(404)

task_type = task.active_dataset.task_type_object
if not task_type.ALLOW_SUBMISSION:
raise tornado.web.HTTPError(404)

submissions = self.sql_session.query(Submission)\
.filter(Submission.participation == participation)\
.filter(Submission.task == task)\
Expand Down
2 changes: 2 additions & 0 deletions cms/server/contest/handlers/taskusertest.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ def get(self):
for task in self.contest.tasks:
if self.get_argument("task_name", None) == task.name:
default_task = task
if default_task is None and task.active_dataset.task_type_object.testable:
default_task = task
user_tests[task.id] = self.sql_session.query(UserTest)\
.filter(UserTest.participation == participation)\
.filter(UserTest.task == task)\
Expand Down
9 changes: 6 additions & 3 deletions cms/server/contest/templates/contest.html
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,12 @@ <h3 id="countdown_box">
<li{% if page == "task_description" and task == t_iter %} class="active"{% endif %}>
<a href="{{ contest_url("tasks", t_iter.name, "description") }}">{% trans %}Statement{% endtrans %}</a>
</li>
<li{% if page == "task_submissions" and task == t_iter %} class="active"{% endif %}>
<a href="{{ contest_url("tasks", t_iter.name, "submissions") }}">{% trans %}Submissions{% endtrans %}</a>
</li>
{% set task_type = get_task_type(dataset=t_iter.active_dataset) %}
{% if task_type.ALLOW_SUBMISSION %}
<li{% if page == "task_submissions" and task == t_iter %} class="active"{% endif %}>
<a href="{{ contest_url("tasks", t_iter.name, "submissions") }}">{% trans %}Submissions{% endtrans %}</a>
</li>
{% endif %}
{% endfor %}
{% endif %}
<li class="divider"></li>
Expand Down
11 changes: 9 additions & 2 deletions cms/server/contest/templates/overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,15 @@ <h2>{% trans %}Task overview{% endtrans %}</h2>
{% trans %}N/A{% endtrans %}
{% endif %}
</td>
<td>{{ get_task_type(dataset=t_iter.active_dataset).name }}</td>
<td>{{ t_iter.submission_format|map("replace", ".%l", extensions)|join(" ") }}</td>
{% set task_type = get_task_type(dataset=t_iter.active_dataset) %}
<td>{{ task_type.name }}</td>
<td>
{% if task_type.ALLOW_SUBMISSION %}
{{ t_iter.submission_format|map("replace", ".%l", extensions)|join(" ") }}
{% else %}
{% trans %}N/A{% endtrans %}
{% endif %}
</td>
{% if tokens_contest != TOKEN_MODE_DISABLED and tokens_tasks != TOKEN_MODE_DISABLED %}
<td>
{% if t_iter.token_mode == TOKEN_MODE_FINITE or t_iter.token_mode == TOKEN_MODE_INFINITE %}
Expand Down
3 changes: 3 additions & 0 deletions cms/service/ProxyService.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,9 @@ def initialize(self):
tasks = dict()

for task in contest.tasks:
task_type = task.active_dataset.task_type_object
if not task_type.ALLOW_SUBMISSION:
continue
score_type = task.active_dataset.score_type_object
tasks[encode_id(task.name)] = {
"short_name": task.name,
Expand Down
4 changes: 2 additions & 2 deletions cmstestsuite/unit_tests/cmscontrib/ImportTaskTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def test_task_exists_update_overwrite_dataset(self):
# check by looking at the task type.
new_title = "new_title"
new_task = self.get_task(name=self.task_name, title=new_title)
new_task_type = "Batch"
new_task_type = "OutputOnly"
self.get_dataset(task=new_task, description=self.dataset_description,
task_type=new_task_type)
self.assertNotEqual(new_task_type, self.dataset.task_type)
Expand All @@ -203,7 +203,7 @@ def test_task_exists_update_overwrite_dataset(self):
self.assertTaskInDb(self.task_name, new_title, self.contest_id,
task_id=self.task_id,
dataset_descriptions=[self.dataset_description],
dataset_task_types=["Batch"])
dataset_task_types=["OutputOnly"])

def test_task_exists_update_new_manager(self):
# Task exists, and we update it, attaching it to the same contest.
Expand Down
12 changes: 4 additions & 8 deletions cmstestsuite/unit_tests/databasemixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,10 @@ def get_dataset(cls, task=None, **kwargs):
args = {
"task": task,
"description": unique_unicode_id(),
"task_type": "",
# "None" won't work here as the column is defined as non
# nullable. As soon as we'll depend on SQLAlchemy 1.1 we
# will be able to put JSON.NULL here instead.
"task_type_parameters": {},
"score_type": "",
# Same here.
"score_type_parameters": {},
"task_type": "Batch",
"task_type_parameters": ["alone", ["", ""], "diff"],
"score_type": "Sum",
"score_type_parameters": 100,
}
args.update(kwargs)
dataset = Dataset(**args)
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ def run(self):
"Communication=cms.grading.tasktypes.Communication:Communication",
"OutputOnly=cms.grading.tasktypes.OutputOnly:OutputOnly",
"TwoSteps=cms.grading.tasktypes.TwoSteps:TwoSteps",
"Notice=cms.grading.tasktypes.Notice:Notice",
],
"cms.grading.scoretypes": [
"Sum=cms.grading.scoretypes.Sum:Sum",
Expand Down

0 comments on commit 2af71ca

Please sign in to comment.