mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2024-12-27 23:51:47 +00:00
fix fps parser
This commit is contained in:
parent
eab80024a8
commit
61b07dfc4c
@ -1,5 +1,13 @@
|
|||||||
{
|
{
|
||||||
"update": [
|
"update": [
|
||||||
|
{
|
||||||
|
"version": "2019-04-05",
|
||||||
|
"level": "Recommend",
|
||||||
|
"title": "2019-04-05",
|
||||||
|
"details": [
|
||||||
|
"Fix bugs in Free Problem Set parser"
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"version": "2019-04-03",
|
"version": "2019-04-03",
|
||||||
"level": "Important",
|
"level": "Important",
|
||||||
|
@ -5,6 +5,7 @@ import random
|
|||||||
import string
|
import string
|
||||||
import hashlib
|
import hashlib
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
|
|
||||||
|
|
||||||
@ -145,14 +146,14 @@ class FPSHelper(object):
|
|||||||
if spj:
|
if spj:
|
||||||
one_info = {
|
one_info = {
|
||||||
"input_size": len(input_content),
|
"input_size": len(input_content),
|
||||||
"input_name": f"{index}.in"
|
"input_name": f"{index + 1}.in"
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
one_info = {
|
one_info = {
|
||||||
"input_size": len(input_content),
|
"input_size": len(input_content),
|
||||||
"input_name": f"{index}.in",
|
"input_name": f"{index + 1}.in",
|
||||||
"output_size": len(output_content),
|
"output_size": len(output_content),
|
||||||
"output_name": f"{index}.out",
|
"output_name": f"{index + 1}.out",
|
||||||
"stripped_output_md5": hashlib.md5(output_content.rstrip().encode("utf-8")).hexdigest()
|
"stripped_output_md5": hashlib.md5(output_content.rstrip().encode("utf-8")).hexdigest()
|
||||||
}
|
}
|
||||||
test_cases[index] = one_info
|
test_cases[index] = one_info
|
||||||
@ -162,11 +163,11 @@ class FPSHelper(object):
|
|||||||
}
|
}
|
||||||
with open(os.path.join(base_dir, "info"), "w", encoding="utf-8") as f:
|
with open(os.path.join(base_dir, "info"), "w", encoding="utf-8") as f:
|
||||||
f.write(json.dumps(info, indent=4))
|
f.write(json.dumps(info, indent=4))
|
||||||
|
return info
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import pprint
|
import pprint
|
||||||
import os
|
|
||||||
|
|
||||||
parser = FPSParser("fps.xml")
|
parser = FPSParser("fps.xml")
|
||||||
helper = FPSHelper()
|
helper = FPSHelper()
|
||||||
|
@ -652,7 +652,7 @@ class FPSProblemImport(CSRFExemptAPIView):
|
|||||||
input_description=problem_data["input"],
|
input_description=problem_data["input"],
|
||||||
output_description=problem_data["output"],
|
output_description=problem_data["output"],
|
||||||
hint=problem_data["hint"],
|
hint=problem_data["hint"],
|
||||||
test_case_score=[],
|
test_case_score=problem_data["test_case_score"],
|
||||||
time_limit=time_limit,
|
time_limit=time_limit,
|
||||||
memory_limit=problem_data["memory_limit"]["value"],
|
memory_limit=problem_data["memory_limit"]["value"],
|
||||||
samples=problem_data["samples"],
|
samples=problem_data["samples"],
|
||||||
@ -686,12 +686,16 @@ class FPSProblemImport(CSRFExemptAPIView):
|
|||||||
test_case_id = rand_str()
|
test_case_id = rand_str()
|
||||||
test_case_dir = os.path.join(settings.TEST_CASE_DIR, test_case_id)
|
test_case_dir = os.path.join(settings.TEST_CASE_DIR, test_case_id)
|
||||||
os.mkdir(test_case_dir)
|
os.mkdir(test_case_dir)
|
||||||
helper.save_test_case(_problem, test_case_dir)
|
score = []
|
||||||
|
for item in helper.save_test_case(_problem, test_case_dir)["test_cases"].values():
|
||||||
|
score.append({"score": 0, "input_name": item["input_name"],
|
||||||
|
"output_name": item.get("output_name")})
|
||||||
problem_data = helper.save_image(_problem, settings.UPLOAD_DIR, settings.UPLOAD_PREFIX)
|
problem_data = helper.save_image(_problem, settings.UPLOAD_DIR, settings.UPLOAD_PREFIX)
|
||||||
s = FPSProblemSerializer(data=problem_data)
|
s = FPSProblemSerializer(data=problem_data)
|
||||||
if not s.is_valid():
|
if not s.is_valid():
|
||||||
return self.error(f"Parse FPS file error: {s.errors}")
|
return self.error(f"Parse FPS file error: {s.errors}")
|
||||||
problem_data = s.data
|
problem_data = s.data
|
||||||
problem_data["test_case_id"] = test_case_id
|
problem_data["test_case_id"] = test_case_id
|
||||||
|
problem_data["test_case_score"] = score
|
||||||
self._create_problem(problem_data, request.user)
|
self._create_problem(problem_data, request.user)
|
||||||
return self.success({"import_count": len(problems)})
|
return self.success({"import_count": len(problems)})
|
||||||
|
Loading…
Reference in New Issue
Block a user