adapt codeforces/topcoder data from private package
This commit is contained in:
parent
2fff128939
commit
cf087ae316
3 changed files with 29 additions and 26 deletions
|
@ -5,15 +5,15 @@ from pathlib import Path
|
|||
import json
|
||||
from typing import Dict, Iterator, Any
|
||||
|
||||
from kython import cproperty, fget
|
||||
from kython.konsume import zoom, ignore
|
||||
from kython.kerror import Res, ytry, unwrap
|
||||
from ..common import cproperty, get_files
|
||||
from ..error import Res, unwrap
|
||||
|
||||
from kython import fget
|
||||
from kython.konsume import zoom, ignore, wrap
|
||||
# TODO remove
|
||||
from kython.kdatetime import as_utc
|
||||
|
||||
|
||||
_BDIR = Path('/L/zzz_syncthing/data/codeforces')
|
||||
|
||||
|
||||
Cid = int
|
||||
|
||||
class Contest(NamedTuple):
|
||||
|
@ -29,8 +29,10 @@ class Contest(NamedTuple):
|
|||
|
||||
Cmap = Dict[Cid, Contest]
|
||||
|
||||
|
||||
def get_contests() -> Cmap:
|
||||
last = max(_BDIR.glob('allcontests*.json'))
|
||||
from mycfg import paths
|
||||
last = max(get_files(paths.codeforces.export_path, 'allcontests*.json'))
|
||||
j = json.loads(last.read_text())
|
||||
d = {}
|
||||
for c in j['result']:
|
||||
|
@ -39,18 +41,13 @@ def get_contests() -> Cmap:
|
|||
return d
|
||||
|
||||
|
||||
def get_latest():
|
||||
last = max(_BDIR.glob('codeforces*.json'))
|
||||
return json.loads(last.read_text())
|
||||
|
||||
|
||||
class Competition(NamedTuple):
|
||||
contest_id: str
|
||||
contest_id: Cid
|
||||
contest: str
|
||||
cmap: Cmap
|
||||
|
||||
@cproperty
|
||||
def uid(self) -> str:
|
||||
def uid(self) -> Cid:
|
||||
return self.contest_id
|
||||
|
||||
def __hash__(self):
|
||||
|
@ -77,11 +74,13 @@ class Competition(NamedTuple):
|
|||
# TODO ytry???
|
||||
ignore(json, 'rank', 'oldRating', 'newRating')
|
||||
|
||||
from kython.konsume import wrap
|
||||
|
||||
def iter_data() -> Iterator[Res[Competition]]:
|
||||
cmap = get_contests()
|
||||
from mycfg import paths
|
||||
last = max(get_files(paths.codeforces.export_path, 'codeforces*.json'))
|
||||
|
||||
with wrap(get_latest()) as j:
|
||||
with wrap(json.loads(last.read_text())) as j:
|
||||
j['status'].ignore()
|
||||
res = j['result'].zoom()
|
||||
|
|
@ -5,14 +5,19 @@ from pathlib import Path
|
|||
import json
|
||||
from typing import Dict, Iterator, Any
|
||||
|
||||
from kython import cproperty, fget
|
||||
from ..common import cproperty, get_files
|
||||
from ..error import Res, unwrap
|
||||
|
||||
# TODO get rid of fget?
|
||||
from kython import fget
|
||||
from kython.konsume import zoom, wrap, ignore
|
||||
from kython.kerror import Res, ytry, unwrap
|
||||
|
||||
|
||||
def get_latest():
|
||||
last = max(Path('/L/zzz_syncthing/data/topcoder').glob('*.json'))
|
||||
return json.loads(last.read_text())
|
||||
# TODO json type??
|
||||
def _get_latest() -> Dict:
|
||||
from mycfg import paths
|
||||
pp = max(get_files(paths.topcoder.export_path, glob='*.json'))
|
||||
return json.loads(pp.read_text())
|
||||
|
||||
|
||||
class Competition(NamedTuple):
|
||||
|
@ -52,7 +57,7 @@ class Competition(NamedTuple):
|
|||
|
||||
|
||||
def iter_data() -> Iterator[Res[Competition]]:
|
||||
with wrap(get_latest()) as j:
|
||||
with wrap(_get_latest()) as j:
|
||||
ignore(j, 'id', 'version')
|
||||
|
||||
res = j['result'].zoom()
|
|
@ -95,8 +95,7 @@ def setup_logger(logger, level=None, format=None, datefmt=None):
|
|||
PathIsh = Union[Path, str]
|
||||
|
||||
|
||||
# TODO use glob or something? see in promnesia
|
||||
def get_files(pp: PathIsh, glob: str) -> List[Path]:
|
||||
def get_files(pp: PathIsh, glob: str) -> List[Path]:
|
||||
"""
|
||||
Helper function to avoid boilerplate.
|
||||
"""
|
||||
|
@ -104,6 +103,6 @@ def get_files(pp: PathIsh, glob: str) -> List[Path]:
|
|||
if path.is_dir():
|
||||
return list(sorted(path.glob(glob)))
|
||||
else:
|
||||
assert path.is_file(), path
|
||||
# TODO FIXME assert matches glob??
|
||||
raise RuntimeError()
|
||||
return path
|
||||
return [path]
|
||||
|
|
Loading…
Add table
Reference in a new issue