Skip to content

Commit

Permalink
fix fps parser
Browse files Browse the repository at this point in the history
  • Loading branch information
virusdefender committed Apr 5, 2019
1 parent eab8002 commit 61b07df
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
8 changes: 8 additions & 0 deletions docs/data.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
{
"update": [
{
"version": "2019-04-05",
"level": "Recommend",
"title": "2019-04-05",
"details": [
"Fix bugs in Free Problem Set parser"
]
},
{
"version": "2019-04-03",
"level": "Important",
Expand Down
9 changes: 5 additions & 4 deletions fps/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import string
import hashlib
import json
import os
import xml.etree.ElementTree as ET


Expand Down Expand Up @@ -145,14 +146,14 @@ def save_test_case(self, problem, base_dir):
if spj:
one_info = {
"input_size": len(input_content),
"input_name": f"{index}.in"
"input_name": f"{index + 1}.in"
}
else:
one_info = {
"input_size": len(input_content),
"input_name": f"{index}.in",
"input_name": f"{index + 1}.in",
"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()
}
test_cases[index] = one_info
Expand All @@ -162,11 +163,11 @@ def save_test_case(self, problem, base_dir):
}
with open(os.path.join(base_dir, "info"), "w", encoding="utf-8") as f:
f.write(json.dumps(info, indent=4))
return info


if __name__ == "__main__":
import pprint
import os

parser = FPSParser("fps.xml")
helper = FPSHelper()
Expand Down
8 changes: 6 additions & 2 deletions problem/views/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ def _create_problem(self, problem_data, creator):
input_description=problem_data["input"],
output_description=problem_data["output"],
hint=problem_data["hint"],
test_case_score=[],
test_case_score=problem_data["test_case_score"],
time_limit=time_limit,
memory_limit=problem_data["memory_limit"]["value"],
samples=problem_data["samples"],
Expand Down Expand Up @@ -686,12 +686,16 @@ def post(self, request):
test_case_id = rand_str()
test_case_dir = os.path.join(settings.TEST_CASE_DIR, test_case_id)
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)
s = FPSProblemSerializer(data=problem_data)
if not s.is_valid():
return self.error(f"Parse FPS file error: {s.errors}")
problem_data = s.data
problem_data["test_case_id"] = test_case_id
problem_data["test_case_score"] = score
self._create_problem(problem_data, request.user)
return self.success({"import_count": len(problems)})

0 comments on commit 61b07df

Please sign in to comment.