Skip to content

Commit

Permalink
#318: modify the units
Browse files Browse the repository at this point in the history
  • Loading branch information
kmyk committed Feb 19, 2019
1 parent eb3652f commit 6e2233f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
26 changes: 13 additions & 13 deletions onlinejudge/service/atcoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def __init__(self, contest_id: str, problem_id: str):
self._task_id = None # type: Optional[int]
self._task_name = None # type: Optional[str]
self._time_limit_msec = None # type: Optional[int]
self._memory_limit_mb = None # type: Optional[int]
self._memory_limit_byte = None # type: Optional[int]
self._alphabet = None # type: Optional[str]

@classmethod
Expand All @@ -245,7 +245,7 @@ def _from_table_row(cls, tr: bs4.Tag) -> 'AtCoderProblem':
self._alphabet = tds[0].text
self._task_name = tds[1].text
self._time_limit_msec = int(float(utils.remove_suffix(tds[2].text, ' sec')) * 1000)
self._memory_limit_mb = int(utils.remove_suffix(tds[3].text, ' MB'))
self._memory_limit_byte = int(utils.remove_suffix(tds[3].text, ' MB')) * 1000 * 1000
assert tds[4].text.strip() in ('', 'Submit')
return self

Expand Down Expand Up @@ -455,7 +455,7 @@ def _load_details(self, session: Optional[requests.Session] = None) -> int:

get_task_name = utils.getter_with_load_details('_task_name') # type: Callable[..., str]
get_time_limit_msec = utils.getter_with_load_details('_time_limit_msec') # type: Callable[..., int]
get_memory_limit_mb = utils.getter_with_load_details('_memory_limit_mb') # type: Callable[..., int]
get_memory_limit_byte = utils.getter_with_load_details('_memory_limit_byte') # type: Callable[..., int]
get_alphabet = utils.getter_with_load_details('_alphabet') # type: Callable[..., str]


Expand All @@ -471,8 +471,8 @@ def __init__(self, contest_id: str, submission_id: int, problem_id: Optional[str
self._score = None # type: Optional[int]
self._code_size = None # type: Optional[int]
self._status = None # type: Optional[str]
self._exec_time_ms = None # type: Optional[int]
self._memory_kb = None # type: Optional[int]
self._exec_time_msec = None # type: Optional[int]
self._memory_byte = None # type: Optional[int]
self._compile_error = None # type: Optional[str]
self._test_cases = None # type: Optional[List[AtCoderSubmissionTestCaseResult]]

Expand Down Expand Up @@ -562,8 +562,8 @@ def _load_details(self, session: Optional[requests.Session] = None) -> None:
self._score = int(data['Score'])
self._code_size = int(utils.remove_suffix(data['Code Size'], ' Byte'))
self._status = data['Status']
self._exec_time_ms = int(utils.remove_suffix(data['Exec Time'], ' ms'))
self._memory_kb = int(utils.remove_suffix(data['Memory'], ' KB'))
self._exec_time_msec = int(utils.remove_suffix(data['Exec Time'], ' ms'))
self._memory_byte = int(utils.remove_suffix(data['Memory'], ' KB')) * 1000

# Compile Error
compile_error = soup.find('h4', text='Compile Error')
Expand Down Expand Up @@ -591,26 +591,26 @@ def get_problem(self, session: Optional[requests.Session] = None) -> AtCoderProb
get_score = utils.getter_with_load_details('_score') # type: Callable[..., int]
get_code_size = utils.getter_with_load_details('_code_size') # type: Callable[..., int]
get_status = utils.getter_with_load_details('_status') # type: Callable[..., str]
get_exec_time_ms = utils.getter_with_load_details('_exec_time_ms') # type: Callable[..., int]
get_memory_kb = utils.getter_with_load_details('_memory_kb') # type: Callable[..., int]
get_exec_time_msec = utils.getter_with_load_details('_exec_time_msec') # type: Callable[..., int]
get_memory_byte = utils.getter_with_load_details('_memory_byte') # type: Callable[..., int]
get_test_cases = utils.getter_with_load_details('_test_cases') # type: Callable[..., List[AtCoderSubmissionTestCaseResult]]


class AtCoderSubmissionTestCaseResult(object):
def __init__(self, case_name: str, status: str, exec_time_ms: int, memory_kb: int):
def __init__(self, case_name: str, status: str, exec_time_msec: int, memory_kb: int):
self.case_name = case_name
self.status = status
self.exec_time_ms = exec_time_ms
self.exec_time_msec = exec_time_msec
self.memory_kb = memory_kb

@classmethod
def _from_table_row(cls, tr: bs4.Tag) -> 'AtCoderSubmissionTestCaseResult':
tds = tr.find_all('td')
case_name = tds[0].text
status = tds[1].text
exec_time_ms = int(utils.remove_suffix(tds[2].text, ' ms'))
exec_time_msec = int(utils.remove_suffix(tds[2].text, ' ms'))
memory_kb = int(utils.remove_suffix(tds[3].text, ' KB'))
return AtCoderSubmissionTestCaseResult(case_name, status, exec_time_ms, memory_kb)
return AtCoderSubmissionTestCaseResult(case_name, status, exec_time_msec, memory_kb)


onlinejudge.dispatch.services += [AtCoderService]
Expand Down
6 changes: 3 additions & 3 deletions tests/service_atcoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_list_problems(self):
self.assertEqual(problems[0].get_alphabet(), 'A')
self.assertEqual(problems[0].get_task_name(), 'Two Abbreviations')
self.assertEqual(problems[0].get_time_limit_msec(), 2000)
self.assertEqual(problems[0].get_memory_limit_mb(), 1024)
self.assertEqual(problems[0].get_memory_limit_byte(), 1024 * 1000 * 1000)
self.assertEqual(problems[5].get_alphabet(), 'F')
self.assertEqual(problems[5].problem_id, 'agc028_f')
self.assertEqual(problems[6].get_alphabet(), 'F2')
Expand Down Expand Up @@ -73,8 +73,8 @@ def test_submission_info(self):
self.assertEqual(submission.get_language_name(), 'C++14 (GCC 5.4.1)')
self.assertEqual(submission.get_score(), 800)
self.assertEqual(submission.get_code_size(), 1457)
self.assertEqual(submission.get_exec_time_ms(), 85)
self.assertEqual(submission.get_memory_kb(), 3328)
self.assertEqual(submission.get_exec_time_msec(), 85)
self.assertEqual(submission.get_memory_byte(), 3328 * 1000)

def test_get_source_code(self):
submission = AtCoderSubmission.from_url('https://atcoder.jp/contests/abc100/submissions/3082514')
Expand Down

0 comments on commit 6e2233f

Please sign in to comment.