handle more fixmes, add make_dict
This commit is contained in:
parent
3b03591dda
commit
09a0c8eb28
7 changed files with 24 additions and 11 deletions
|
@ -66,7 +66,7 @@ def iter_data() -> Iterator[Res[Competition]]:
|
|||
cont = res['content'].zoom()
|
||||
ignore(cont, 'handle', 'handleLower', 'userId', 'createdAt', 'updatedAt', 'createdBy', 'updatedBy')
|
||||
|
||||
cont['DEVELOP'].ignore() # TODO FIXME handle it??
|
||||
cont['DEVELOP'].ignore() # TODO handle it??
|
||||
ds = cont['DATA_SCIENCE'].zoom()
|
||||
|
||||
mar, srm = zoom(ds, 'MARATHON_MATCH', 'SRM')
|
||||
|
|
17
my/common.py
17
my/common.py
|
@ -1,7 +1,7 @@
|
|||
from pathlib import Path
|
||||
import functools
|
||||
import types
|
||||
from typing import Union, Callable, Dict, Iterable, TypeVar, Sequence, List, Optional, TYPE_CHECKING, Any
|
||||
from typing import Union, Callable, Dict, Iterable, TypeVar, Sequence, List, Optional, Any, cast
|
||||
|
||||
# some helper functions
|
||||
PathIsh = Union[Path, str]
|
||||
|
@ -54,6 +54,21 @@ def group_by_key(l: Iterable[T], key: Callable[[T], K]) -> Dict[K, List[T]]:
|
|||
return res
|
||||
|
||||
|
||||
def _identity(v: T) -> V:
|
||||
return cast(V, v)
|
||||
|
||||
def make_dict(l: Iterable[T], key: Callable[[T], K], value: Callable[[T], V]=_identity) -> Dict[K, V]:
|
||||
res: Dict[K, V] = {}
|
||||
for i in l:
|
||||
k = key(i)
|
||||
v = value(i)
|
||||
pv = res.get(k, None) # type: ignore
|
||||
if pv is not None:
|
||||
raise RuntimeError(f"Duplicate key: {k}. Previous value: {pv}, new value: {v}")
|
||||
res[k] = v
|
||||
return res
|
||||
|
||||
|
||||
Cl = TypeVar('Cl')
|
||||
R = TypeVar('R')
|
||||
|
||||
|
|
|
@ -187,7 +187,7 @@ def plot_one(sleep: SleepEntry, fig: Figure, axes: Axes, xlims=None, showtext=Tr
|
|||
axes.text(xlims[1] - timedelta(hours=1.5), 20, str(sleep),)
|
||||
# plt.text(sleep.asleep(), 0, hhmm(sleep.asleep()))
|
||||
|
||||
from kython import make_dict, group_by_key
|
||||
from ..common import group_by_key
|
||||
|
||||
def sleeps_by_date() -> Dict[date, SleepEntry]:
|
||||
logger = get_logger()
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
from datetime import datetime
|
||||
from typing import NamedTuple, List
|
||||
|
||||
# TODO FIXME
|
||||
from kython.ktakeout import TakeoutHTMLParser
|
||||
|
||||
from ..kython.kompress import kopen
|
||||
|
|
|
@ -7,7 +7,7 @@ from pathlib import Path
|
|||
from typing import List, Sequence, Mapping, Iterator
|
||||
|
||||
from .kython.kompress import CPath
|
||||
from .common import mcachew, get_files, LazyLogger
|
||||
from .common import mcachew, get_files, LazyLogger, make_dict
|
||||
|
||||
from mycfg import paths
|
||||
import mycfg.repos.rexport.dal as rexport
|
||||
|
@ -110,8 +110,6 @@ def _get_state(bfile: Path) -> Dict[Sid, SaveWithDt]:
|
|||
bdt = _get_bdate(bfile)
|
||||
|
||||
saves = [SaveWithDt(save, bdt) for save in rexport.DAL([bfile]).saved()]
|
||||
# TODO FIXME remove kython?
|
||||
from kython import make_dict
|
||||
return make_dict(
|
||||
sorted(saves, key=lambda p: p.save.created),
|
||||
key=lambda s: s.save.sid,
|
||||
|
@ -195,7 +193,6 @@ def test_get_all_saves():
|
|||
# TODO not sure if this is necesasry anymore?
|
||||
saves = list(saved())
|
||||
# just check that they are unique..
|
||||
from kython import make_dict
|
||||
make_dict(saves, key=lambda s: s.sid)
|
||||
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ from pathlib import Path
|
|||
from typing import Dict, List, Optional, Iterator
|
||||
from datetime import datetime
|
||||
|
||||
from .common import LazyLogger, get_files, group_by_key, cproperty
|
||||
from .common import LazyLogger, get_files, group_by_key, cproperty, make_dict
|
||||
from .kython.kompress import open as kopen
|
||||
|
||||
from mycfg import rtm as config
|
||||
|
@ -90,9 +90,7 @@ class DAL:
|
|||
|
||||
def get_todos_by_uid(self) -> Dict[str, MyTodo]:
|
||||
todos = self.all_todos()
|
||||
# TODO use make_dict?
|
||||
res = {todo.uid: todo for todo in todos}
|
||||
return res
|
||||
return make_dict(todos, key=lambda t: t.uid)
|
||||
|
||||
def get_todos_by_title(self) -> Dict[str, List[MyTodo]]:
|
||||
todos = self.all_todos()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue