Skip to content

Commit

Permalink
Fix a couple of code style issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Xyene committed Mar 7, 2020
1 parent 0d45364 commit 729e3d5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
27 changes: 8 additions & 19 deletions dmoj/judge.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from http.server import HTTPServer
from itertools import chain

from dmoj import graders, packet
from dmoj import packet
from dmoj.control import JudgeControlRequestHandler
from dmoj.error import CompileError
from dmoj.judgeenv import clear_problem_dirs_cache, env, get_supported_problems, startup_warnings
Expand Down Expand Up @@ -82,17 +82,8 @@ def update_problems(self):
self.updater_signal.set()

def _block_and_grade(self, problem, language, source, short_circuit, report=print):
if 'signature_grader' in problem.config:
grader_class = graders.SignatureGrader
elif 'interactive' in problem.config:
grader_class = graders.BridgedInteractiveGrader
elif 'custom_judge' in problem.config:
grader_class = graders.CustomGrader
else:
grader_class = graders.StandardGrader

try:
self.current_grader = grader_class(self, problem, language, utf8bytes(source))
self.current_grader = problem.grader_class(self, problem, language, utf8bytes(source))
except CompileError as compilation_error:
error = compilation_error.args[0] or b'compiler exited abnormally'

Expand Down Expand Up @@ -187,25 +178,23 @@ def grade_cases(self, grader, cases, short_circuit=False, is_short_circuiting=Fa
if isinstance(case, BatchedTestCase):
yield BatchBegin()

for batched_case in self.grade_cases(grader, case.batched_cases,
short_circuit=case.config['short_circuit'],
is_short_circuiting=is_short_circuiting):
for batched_result in self.grade_cases(grader, case.batched_cases,
short_circuit=case.config['short_circuit'],
is_short_circuiting=is_short_circuiting):
# A batched case just failed.
# There are two cases where this means that we should completely short-circuit:
# 1. If the batch was worth 0 points, to emulate the property of 0-point cases.
# 2. If the short_circuit flag is true, see <https://github.com/DMOJ/judge/issues/341>.
if (batched_case.result_flag & Result.WA) and \
if (batched_result.result_flag & Result.WA) and \
(short_circuit or case.kind in (TestCase.KIND_SAMPLE, TestCase.KIND_PRETEST)):
is_short_circuiting = True
yield batched_case
yield batched_result
yield BatchEnd()
continue

# Stop grading if we're short circuiting
if is_short_circuiting:
result = Result(case)
result.result_flag = Result.SC
yield result
yield Result(case, Result.SC)
continue

result = grader.grade(case)
Expand Down
13 changes: 13 additions & 0 deletions dmoj/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,19 @@ def _resolve_archive_files(self):
return archive
return None

@property
def grader_class(self):
from dmoj import graders

if 'signature_grader' in self.config:
return graders.SignatureGrader
elif 'interactive' in self.config:
return graders.BridgedInteractiveGrader
elif 'custom_judge' in self.config:
return graders.CustomGrader
else:
return graders.StandardGrader


class ProblemDataManager(dict):
def __init__(self, problem_id, **kwargs):
Expand Down
4 changes: 2 additions & 2 deletions dmoj/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class Result:
'IE': 'red',
}

def __init__(self, case):
self.result_flag = 0
def __init__(self, case, result_flag=0):
self.result_flag = result_flag
self.execution_time = 0
self.wall_clock_time = 0
self.max_memory = 0
Expand Down

0 comments on commit 729e3d5

Please sign in to comment.