Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Presentation Error support #209

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions judge/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ def judge(self):
resp["data"].sort(key=lambda x: int(x["test_case"]))
self.submission.info = resp
self._compute_statistic_info(resp["data"])
if self.problem.pe_ignored:
for case in resp["data"]:
if case["result"] is JudgeStatus.PRESNTATION_ERROR:
case["result"] = 0
error_test_case = list(filter(lambda case: case["result"] != 0, resp["data"]))
# ACM模式下,多个测试点全部正确则AC,否则取第一个错误的测试点的状态
# OI模式下, 若多个测试点全部正确则AC, 若全部错误则取第一个错误测试点状态,否则为部分正确
Expand Down
45 changes: 45 additions & 0 deletions problem/migrations/0013_auto_20181227_0719.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.4 on 2018-12-27 07:19
from __future__ import unicode_literals

from django.db import migrations, models
from django.conf import settings
import os
import json
import hashlib


def update_all_stripped_md5(apps, schema_editor):
Problem = apps.get_model("problem", "Problem")
problems = Problem.objects.all()
for problem in problems:
test_case_dir = os.path.join(settings.TEST_CASE_DIR, problem.test_case_id)
try:
with open(os.path.join(test_case_dir, "info")) as f:
info = json.load(f)
if not info["spj"]:
for id in info["test_cases"]:
with open(os.path.join(test_case_dir,f"{id}.out"),"rb") as f:
content = f.read()
stripped_md5 = hashlib.md5(b"\n".join([x.rstrip() for x in content.split(b"\n") if len(x) > 0])).hexdigest()
info["test_cases"][id]["all_stripped_output_md5"] = stripped_md5
with open(os.path.join(test_case_dir, "info"), "w", encoding="utf-8") as f:
f.write(json.dumps(info, indent=4))
except Exception as err:
print(f"{test_case_dir} info not found")


class Migration(migrations.Migration):

dependencies = [
('problem', '0012_auto_20180501_0436'),
]

operations = [
migrations.AddField(
model_name='problem',
name='pe_ignored',
field=models.BooleanField(default=False),
),
migrations.RunPython(update_all_stripped_md5, reverse_code=migrations.RunPython.noop),
]
1 change: 1 addition & 0 deletions problem/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class Problem(models.Model):
languages = JSONField()
template = JSONField()
create_time = models.DateTimeField(auto_now_add=True)
pe_ignored = models.BooleanField(default=False)
# we can not use auto_now here
last_update_time = models.DateTimeField(null=True)
created_by = models.ForeignKey(User)
Expand Down
1 change: 1 addition & 0 deletions problem/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class CreateOrEditProblemSerializer(serializers.Serializer):
spj_code = serializers.CharField(allow_blank=True, allow_null=True)
spj_compile_ok = serializers.BooleanField(default=False)
visible = serializers.BooleanField()
pe_ignored = serializers.BooleanField()
difficulty = serializers.ChoiceField(choices=Difficulty.choices())
tags = serializers.ListField(child=serializers.CharField(max_length=32), allow_empty=False)
hint = serializers.CharField(allow_blank=True, allow_null=True)
Expand Down
3 changes: 3 additions & 0 deletions problem/views/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@ def process_zip(self, uploaded_zip_file, spj, dir=""):

size_cache = {}
md5_cache = {}
stripped_md5_cache = {}

for item in test_case_list:
with open(os.path.join(test_case_dir, item), "wb") as f:
content = zip_file.read(f"{dir}{item}").replace(b"\r\n", b"\n")
size_cache[item] = len(content)
if item.endswith(".out"):
md5_cache[item] = hashlib.md5(content.rstrip()).hexdigest()
stripped_md5_cache[item] = hashlib.md5(b"\n".join([x.rstrip() for x in content.split(b"\n") if len(x) > 0])).hexdigest()
f.write(content)
test_case_info = {"spj": spj, "test_cases": {}}

Expand All @@ -71,6 +73,7 @@ def process_zip(self, uploaded_zip_file, spj, dir=""):
test_case_list = zip(*[test_case_list[i::2] for i in range(2)])
for index, item in enumerate(test_case_list):
data = {"stripped_output_md5": md5_cache[item[1]],
"all_stripped_output_md5": stripped_md5_cache[item[1]],
"input_size": size_cache[item[0]],
"output_size": size_cache[item[1]],
"input_name": item[0],
Expand Down
1 change: 1 addition & 0 deletions submission/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class JudgeStatus:
PENDING = 6
JUDGING = 7
PARTIALLY_ACCEPTED = 8
PRESNTATION_ERROR = 9


class Submission(models.Model):
Expand Down