support testcase score

This commit is contained in:
virusdefender 2019-03-21 07:57:21 +08:00
parent 76c5aa4438
commit 11364fa90b
3 changed files with 19 additions and 12 deletions

View File

@ -111,11 +111,13 @@ class JudgeDispatcher(DispatcherBase):
score = 0 score = 0
try: try:
for i in range(len(resp_data)): 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"] resp_data[i]["score"] = self.problem.test_case_score[i]["score"]
score += resp_data[i]["score"]
else: else:
resp_data[i]["score"] = 0 resp_data[i]["score"] = 0
score += resp_data[i]["score"]
except IndexError: except IndexError:
logger.error(f"Index Error raised when summing up the score in problem {self.problem.id}") logger.error(f"Index Error raised when summing up the score in problem {self.problem.id}")
self.submission.statistic_info["score"] = 0 self.submission.statistic_info["score"] = 0
@ -149,7 +151,8 @@ class JudgeDispatcher(DispatcherBase):
"spj_config": spj_config.get("config"), "spj_config": spj_config.get("config"),
"spj_compile_config": spj_config.get("compile"), "spj_compile_config": spj_config.get("compile"),
"spj_src": self.problem.spj_code, "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: with ChooseJudgeServer() as server:

View File

@ -47,8 +47,8 @@ _c_lang_spj_compile = {
_c_lang_spj_config = { _c_lang_spj_config = {
"exe_name": "spj-{spj_version}", "exe_name": "spj-{spj_version}",
"command": "{exe_path} {in_file_path} {user_out_file_path}", "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" "seccomp_rule": "c_cpp_file_io"
} }
_cpp_lang_config = { _cpp_lang_config = {
@ -95,8 +95,8 @@ _cpp_lang_spj_compile = {
_cpp_lang_spj_config = { _cpp_lang_spj_config = {
"exe_name": "spj-{spj_version}", "exe_name": "spj-{spj_version}",
"command": "{exe_path} {in_file_path} {user_out_file_path}", "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" "seccomp_rule": "c_cpp_file_io"
} }
_java_lang_config = { _java_lang_config = {

View File

@ -38,7 +38,8 @@ class TestCaseZipProcessor(object):
except zipfile.BadZipFile: except zipfile.BadZipFile:
raise APIError("Bad zip file") raise APIError("Bad zip file")
name_list = zip_file.namelist() 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: if not test_case_list:
raise APIError("Empty file") raise APIError("Empty file")
@ -61,7 +62,7 @@ class TestCaseZipProcessor(object):
info = [] info = []
if spj: if test_case_spj:
for index, item in enumerate(test_case_list): for index, item in enumerate(test_case_list):
data = {"input_name": item, "input_size": size_cache[item]} data = {"input_name": item, "input_size": size_cache[item]}
info.append(data) info.append(data)
@ -89,6 +90,9 @@ class TestCaseZipProcessor(object):
def filter_name_list(self, name_list, spj, dir=""): def filter_name_list(self, name_list, spj, dir=""):
ret = [] ret = []
prefix = 1 prefix = 1
# 在 spj 情况下,可以不传 out 文件,但是一旦传了,也是可以接受的,就按照非 spj 去过滤一遍
if f"{dir}1.out" in name_list:
spj = False
if spj: if spj:
while True: while True:
in_name = f"{prefix}.in" in_name = f"{prefix}.in"
@ -97,7 +101,7 @@ class TestCaseZipProcessor(object):
prefix += 1 prefix += 1
continue continue
else: else:
return sorted(ret, key=natural_sort_key) return spj, sorted(ret, key=natural_sort_key)
else: else:
while True: while True:
in_name = f"{prefix}.in" in_name = f"{prefix}.in"
@ -108,7 +112,7 @@ class TestCaseZipProcessor(object):
prefix += 1 prefix += 1
continue continue
else: else:
return sorted(ret, key=natural_sort_key) return spj, sorted(ret, key=natural_sort_key)
class TestCaseAPI(CSRFExemptAPIView, TestCaseZipProcessor): 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) test_case_dir = os.path.join(settings.TEST_CASE_DIR, problem.test_case_id)
if not os.path.isdir(test_case_dir): if not os.path.isdir(test_case_dir):
return self.error("Test case does not exists") 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") name_list.append("info")
file_name = os.path.join(test_case_dir, problem.test_case_id + ".zip") file_name = os.path.join(test_case_dir, problem.test_case_id + ".zip")
with zipfile.ZipFile(file_name, "w") as file: with zipfile.ZipFile(file_name, "w") as file: