Skip to content

Commit e42dd71

Browse files
committed
fix submission subsitude codes
1 parent 83189c9 commit e42dd71

File tree

4 files changed

+25
-12
lines changed

4 files changed

+25
-12
lines changed

judge/testing.py

+19-8
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,18 @@ def __init__(self, submission: Submission):
147147
self.sub_dirpath = PathManager.submission_dir(str(submission.user_id), submission.id)
148148
if not exists(self.sub_dirpath):
149149
os.makedirs(self.sub_dirpath, exist_ok=True)
150-
prob_dir = PathManager.problem_dir(submission.problem._id) # use display id
151-
print('problem id:', submission.problem._id)
152-
print('problem dir:', prob_dir)
150+
problem: Problem = submission.problem
151+
prob_dir = PathManager.problem_dir(problem._id) # use display id
153152
if not exists(prob_dir):
154153
raise Exception("problem dir {} not exists".format(prob_dir))
155154
for filename in os.listdir(prob_dir):
156-
print(f'copy {join(prob_dir, filename)} to {self.sub_dirpath}')
157155
shutil.copy2(join(prob_dir, filename), self.sub_dirpath)
156+
for index, codename in enumerate(problem.code_names):
157+
filecontent = submission.code_list[index]
158+
codepath = join(self.sub_dirpath, codename)
159+
with open(codepath, "w") as wfp:
160+
print(f"substitude {codepath} with user implemented")
161+
wfp.write(filecontent)
158162

159163
def judge(self):
160164
tester_path = join(self.sub_dirpath, TESTER_NAME)
@@ -174,25 +178,27 @@ def judge(self):
174178
failed_info = []
175179
with open(join(log_path, "results.json")) as fp:
176180
res = json.load(fp)
181+
grade = res['grade']
177182
self.sub.grade = res['grade']
178183
for idx in res['failed']:
179184
log_fp = open(join(log_path, f"testcase{idx}.log"), "r")
180185
testcase_fp = open(join(self.sub_dirpath, TESTCASE_NAME), "r")
181186
testcase_json_data = json.load(testcase_fp)
187+
# notice the index here, logical index starts from 1
182188
if "config" in testcase_json_data:
183189
# global config
184190
config = testcase_json_data["config"]
185191
else:
186-
cur_data = testcase_json_data["testcases"][idx]
192+
cur_data = testcase_json_data["testcases"][idx-1]
187193
if "config" in cur_data:
188194
# specific config for testcase
189195
config = ["config"]
190196
else:
191197
# no config
192198
config = None
193199
displayed_test = {
194-
"input": testcase_json_data["testcases"][idx]["input"],
195-
"expected_output":testcase_json_data["testcases"][idx]["output"],
200+
"input": testcase_json_data["testcases"][idx-1]["input"],
201+
"expected_output":testcase_json_data["testcases"][idx-1]["output"],
196202
}
197203
# config, "testcase"
198204
failed_info.append({
@@ -204,5 +210,10 @@ def judge(self):
204210
log_fp.close()
205211
testcase_fp.close()
206212
self.sub.failed_info = failed_info
207-
self.sub.result = JudgeStatus.FINISHED
213+
if grade == 0:
214+
self.sub.result = JudgeStatus.ALL_FAILED
215+
elif grade == 100:
216+
self.sub.result = JudgeStatus.ALL_PASSED
217+
else:
218+
self.sub.result = JudgeStatus.SOME_PASSED
208219
self.sub.save()

submission/models.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
class JudgeStatus:
1212
PENDING = 0
1313
JUDGING = 1
14-
FINISHED = 2
15-
SYSTEM_ERROR = 3
14+
SYSTEM_ERROR = 2
15+
ALL_PASSED = 3
16+
SOME_PASSED = 4
17+
ALL_FAILED = 5
1618

1719

1820
class Submission(models.Model):

submission/serializers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class SubmissionSafeModelSerializer(serializers.ModelSerializer):
2828

2929
class Meta:
3030
model = Submission
31-
exclude = ("info", "contest", "ip")
31+
exclude = ("contest", "ip")
3232

3333

3434
class SubmissionListSerializer(serializers.ModelSerializer):

submission/views/user.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def check_contest_permission(self, request):
7070
@validate_serializer(CreateSubmissionSerializer)
7171
@login_required
7272
def post(self, request):
73-
print(request.data)
73+
# print(request.data)
7474
data = request.data
7575
hide_id = False
7676

0 commit comments

Comments
 (0)