Skip to content

Commit

Permalink
fix progress
Browse files Browse the repository at this point in the history
  • Loading branch information
twd2 committed Mar 12, 2017
1 parent 96afe7e commit 51532fc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 6 additions & 3 deletions jd4/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from jd4.langs import langs
from jd4.log import logger
from jd4.sandbox import create_sandbox
from jd4.status import STATUS_COMPILE_ERROR, STATUS_SYSTEM_ERROR
from jd4.status import STATUS_COMPILE_ERROR, STATUS_SYSTEM_ERROR, STATUS_JUDGING, STATUS_COMPILING

RETRY_DELAY_SEC = 30

Expand Down Expand Up @@ -84,13 +84,15 @@ async def pretest(self):

async def build(self):
lang = self.request.pop('lang')
self.next(status=STATUS_COMPILING, progress=0)
build_fn = langs.get(lang)
if not build_fn:
raise SystemError('Unsupported language: {}'.format(lang))
package, message = await build_fn(sandbox, self.request.pop('code').encode())
if not package:
logger.info('Compile error: %s', message)
raise CompileError(message)
self.next(status=STATUS_JUDGING, progress=0)
return package

async def judge(self, cases_file, package):
Expand All @@ -101,12 +103,13 @@ async def judge(self, cases_file, package):
total_memory_usage_bytes = 0
for index, case in enumerate(cases):
status, score, time_usage_ns, memory_usage_bytes, stderr = await case.judge(sandbox, package)
self.next(case={'status': status,
self.next(status=STATUS_JUDGING,
case={'status': status,
'score': score,
'time_ms': time_usage_ns // 1000000,
'memory_kb': memory_usage_bytes // 1024,
'judge_text': stderr.decode(encoding='utf-8', errors='replace')},
progress=(index + 1) / len(cases))
progress=(index + 1) / len(cases) * 100)
logger.debug('Case %d: %d, %g, %g, %g, %s',
index, status, score, time_usage_ns / 1000000, memory_usage_bytes / 1024, stderr)
total_status = max(total_status, status)
Expand Down
2 changes: 2 additions & 0 deletions jd4/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
STATUS_RUNTIME_ERROR = 6
STATUS_COMPILE_ERROR = 7
STATUS_SYSTEM_ERROR = 8
STATUS_JUDGING = 20
STATUS_COMPILING = 21

0 comments on commit 51532fc

Please sign in to comment.