diff --git a/judge/dispatcher.py b/judge/dispatcher.py index c4480956c..75e63e4cb 100644 --- a/judge/dispatcher.py +++ b/judge/dispatcher.py @@ -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, 若全部错误则取第一个错误测试点状态,否则为部分正确 diff --git a/problem/migrations/0013_auto_20181227_0719.py b/problem/migrations/0013_auto_20181227_0719.py new file mode 100644 index 000000000..9be46b53d --- /dev/null +++ b/problem/migrations/0013_auto_20181227_0719.py @@ -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), + ] diff --git a/problem/models.py b/problem/models.py index 29e317bd3..61e525c99 100644 --- a/problem/models.py +++ b/problem/models.py @@ -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) diff --git a/problem/serializers.py b/problem/serializers.py index dbea96b7d..7e05f6fad 100644 --- a/problem/serializers.py +++ b/problem/serializers.py @@ -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) diff --git a/problem/views/admin.py b/problem/views/admin.py index a357cea5c..afa348f82 100644 --- a/problem/views/admin.py +++ b/problem/views/admin.py @@ -49,6 +49,7 @@ 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: @@ -56,6 +57,7 @@ def process_zip(self, uploaded_zip_file, spj, dir=""): 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": {}} @@ -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], diff --git a/submission/models.py b/submission/models.py index 261052e9d..d79f451ab 100644 --- a/submission/models.py +++ b/submission/models.py @@ -18,6 +18,7 @@ class JudgeStatus: PENDING = 6 JUDGING = 7 PARTIALLY_ACCEPTED = 8 + PRESNTATION_ERROR = 9 class Submission(models.Model):