From 11364fa90ba82301808e53efb2ece8421d3b7f92 Mon Sep 17 00:00:00 2001 From: virusdefender Date: Thu, 21 Mar 2019 07:57:21 +0800 Subject: [PATCH] support testcase score --- judge/dispatcher.py | 9 ++++++--- judge/languages.py | 8 ++++---- problem/views/admin.py | 14 +++++++++----- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/judge/dispatcher.py b/judge/dispatcher.py index bd099ac2..74418a96 100644 --- a/judge/dispatcher.py +++ b/judge/dispatcher.py @@ -111,11 +111,13 @@ class JudgeDispatcher(DispatcherBase): score = 0 try: for i in range(len(resp_data)): - if resp_data[i]["result"] == JudgeStatus.ACCEPTED: + if self.problem.spj: + resp_data[i]["score"] = resp_data[i]["score"] + elif not self.problem.spj and resp_data[i]["result"] == JudgeStatus.ACCEPTED: resp_data[i]["score"] = self.problem.test_case_score[i]["score"] - score += resp_data[i]["score"] else: resp_data[i]["score"] = 0 + score += resp_data[i]["score"] except IndexError: logger.error(f"Index Error raised when summing up the score in problem {self.problem.id}") self.submission.statistic_info["score"] = 0 @@ -149,7 +151,8 @@ class JudgeDispatcher(DispatcherBase): "spj_config": spj_config.get("config"), "spj_compile_config": spj_config.get("compile"), "spj_src": self.problem.spj_code, - "io_mode": self.problem.io_mode + "io_mode": self.problem.io_mode, + "test_case_score": self.problem.test_case_score } with ChooseJudgeServer() as server: diff --git a/judge/languages.py b/judge/languages.py index 0bf0038d..3d29b50d 100644 --- a/judge/languages.py +++ b/judge/languages.py @@ -47,8 +47,8 @@ _c_lang_spj_compile = { _c_lang_spj_config = { "exe_name": "spj-{spj_version}", - "command": "{exe_path} {in_file_path} {user_out_file_path}", - "seccomp_rule": "c_cpp" + "command": "{exe_path} {in_file_path} {user_out_file_path} {out_file_path} {score} {custom_score_file_path} {extra_file_path}", + "seccomp_rule": "c_cpp_file_io" } _cpp_lang_config = { @@ -95,8 +95,8 @@ _cpp_lang_spj_compile = { _cpp_lang_spj_config = { "exe_name": "spj-{spj_version}", - "command": "{exe_path} {in_file_path} {user_out_file_path}", - "seccomp_rule": "c_cpp" + "command": "{exe_path} {in_file_path} {user_out_file_path} {out_file_path} {score} {custom_score_file_path} {extra_file_path}", + "seccomp_rule": "c_cpp_file_io" } _java_lang_config = { diff --git a/problem/views/admin.py b/problem/views/admin.py index 280e4fa1..b0109bfe 100644 --- a/problem/views/admin.py +++ b/problem/views/admin.py @@ -38,7 +38,8 @@ class TestCaseZipProcessor(object): except zipfile.BadZipFile: raise APIError("Bad zip file") name_list = zip_file.namelist() - test_case_list = self.filter_name_list(name_list, spj=spj, dir=dir) + # # 在 spj 情况下,可以不传 out 文件,但是一旦传了,也是可以接受的,就按照非 spj 去过滤一遍,test_case_spj 代表这种情况 + test_case_spj, test_case_list = self.filter_name_list(name_list, spj=spj, dir=dir) if not test_case_list: raise APIError("Empty file") @@ -61,7 +62,7 @@ class TestCaseZipProcessor(object): info = [] - if spj: + if test_case_spj: for index, item in enumerate(test_case_list): data = {"input_name": item, "input_size": size_cache[item]} info.append(data) @@ -89,6 +90,9 @@ class TestCaseZipProcessor(object): def filter_name_list(self, name_list, spj, dir=""): ret = [] prefix = 1 + # 在 spj 情况下,可以不传 out 文件,但是一旦传了,也是可以接受的,就按照非 spj 去过滤一遍 + if f"{dir}1.out" in name_list: + spj = False if spj: while True: in_name = f"{prefix}.in" @@ -97,7 +101,7 @@ class TestCaseZipProcessor(object): prefix += 1 continue else: - return sorted(ret, key=natural_sort_key) + return spj, sorted(ret, key=natural_sort_key) else: while True: in_name = f"{prefix}.in" @@ -108,7 +112,7 @@ class TestCaseZipProcessor(object): prefix += 1 continue else: - return sorted(ret, key=natural_sort_key) + return spj, sorted(ret, key=natural_sort_key) class TestCaseAPI(CSRFExemptAPIView, TestCaseZipProcessor): @@ -131,7 +135,7 @@ class TestCaseAPI(CSRFExemptAPIView, TestCaseZipProcessor): test_case_dir = os.path.join(settings.TEST_CASE_DIR, problem.test_case_id) if not os.path.isdir(test_case_dir): return self.error("Test case does not exists") - name_list = self.filter_name_list(os.listdir(test_case_dir), problem.spj) + _, name_list = self.filter_name_list(os.listdir(test_case_dir), problem.spj) name_list.append("info") file_name = os.path.join(test_case_dir, problem.test_case_id + ".zip") with zipfile.ZipFile(file_name, "w") as file: