handle more fixmes, add make_dict
This commit is contained in:
parent
3365f979ed
commit
c3812fc2e7
7 changed files with 24 additions and 11 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -208,3 +208,5 @@ pip-selfcheck.json
|
||||||
|
|
||||||
# End of https://www.gitignore.io/api/python,emacs
|
# End of https://www.gitignore.io/api/python,emacs
|
||||||
with_my
|
with_my
|
||||||
|
|
||||||
|
cov
|
||||||
|
|
|
@ -66,7 +66,7 @@ def iter_data() -> Iterator[Res[Competition]]:
|
||||||
cont = res['content'].zoom()
|
cont = res['content'].zoom()
|
||||||
ignore(cont, 'handle', 'handleLower', 'userId', 'createdAt', 'updatedAt', 'createdBy', 'updatedBy')
|
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()
|
ds = cont['DATA_SCIENCE'].zoom()
|
||||||
|
|
||||||
mar, srm = zoom(ds, 'MARATHON_MATCH', 'SRM')
|
mar, srm = zoom(ds, 'MARATHON_MATCH', 'SRM')
|
||||||
|
|
17
my/common.py
17
my/common.py
|
@ -1,7 +1,7 @@
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import functools
|
import functools
|
||||||
import types
|
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
|
# some helper functions
|
||||||
PathIsh = Union[Path, str]
|
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
|
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')
|
Cl = TypeVar('Cl')
|
||||||
R = TypeVar('R')
|
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),)
|
axes.text(xlims[1] - timedelta(hours=1.5), 20, str(sleep),)
|
||||||
# plt.text(sleep.asleep(), 0, hhmm(sleep.asleep()))
|
# 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]:
|
def sleeps_by_date() -> Dict[date, SleepEntry]:
|
||||||
logger = get_logger()
|
logger = get_logger()
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import NamedTuple, List
|
from typing import NamedTuple, List
|
||||||
|
|
||||||
|
# TODO FIXME
|
||||||
from kython.ktakeout import TakeoutHTMLParser
|
from kython.ktakeout import TakeoutHTMLParser
|
||||||
|
|
||||||
from ..kython.kompress import kopen
|
from ..kython.kompress import kopen
|
||||||
|
|
|
@ -7,7 +7,7 @@ from pathlib import Path
|
||||||
from typing import List, Sequence, Mapping, Iterator
|
from typing import List, Sequence, Mapping, Iterator
|
||||||
|
|
||||||
from .kython.kompress import CPath
|
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
|
from mycfg import paths
|
||||||
import mycfg.repos.rexport.dal as rexport
|
import mycfg.repos.rexport.dal as rexport
|
||||||
|
@ -110,8 +110,6 @@ def _get_state(bfile: Path) -> Dict[Sid, SaveWithDt]:
|
||||||
bdt = _get_bdate(bfile)
|
bdt = _get_bdate(bfile)
|
||||||
|
|
||||||
saves = [SaveWithDt(save, bdt) for save in rexport.DAL([bfile]).saved()]
|
saves = [SaveWithDt(save, bdt) for save in rexport.DAL([bfile]).saved()]
|
||||||
# TODO FIXME remove kython?
|
|
||||||
from kython import make_dict
|
|
||||||
return make_dict(
|
return make_dict(
|
||||||
sorted(saves, key=lambda p: p.save.created),
|
sorted(saves, key=lambda p: p.save.created),
|
||||||
key=lambda s: s.save.sid,
|
key=lambda s: s.save.sid,
|
||||||
|
@ -195,7 +193,6 @@ def test_get_all_saves():
|
||||||
# TODO not sure if this is necesasry anymore?
|
# TODO not sure if this is necesasry anymore?
|
||||||
saves = list(saved())
|
saves = list(saved())
|
||||||
# just check that they are unique..
|
# just check that they are unique..
|
||||||
from kython import make_dict
|
|
||||||
make_dict(saves, key=lambda s: s.sid)
|
make_dict(saves, key=lambda s: s.sid)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ from pathlib import Path
|
||||||
from typing import Dict, List, Optional, Iterator
|
from typing import Dict, List, Optional, Iterator
|
||||||
from datetime import datetime
|
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 .kython.kompress import open as kopen
|
||||||
|
|
||||||
from mycfg import rtm as config
|
from mycfg import rtm as config
|
||||||
|
@ -90,9 +90,7 @@ class DAL:
|
||||||
|
|
||||||
def get_todos_by_uid(self) -> Dict[str, MyTodo]:
|
def get_todos_by_uid(self) -> Dict[str, MyTodo]:
|
||||||
todos = self.all_todos()
|
todos = self.all_todos()
|
||||||
# TODO use make_dict?
|
return make_dict(todos, key=lambda t: t.uid)
|
||||||
res = {todo.uid: todo for todo in todos}
|
|
||||||
return res
|
|
||||||
|
|
||||||
def get_todos_by_title(self) -> Dict[str, List[MyTodo]]:
|
def get_todos_by_title(self) -> Dict[str, List[MyTodo]]:
|
||||||
todos = self.all_todos()
|
todos = self.all_todos()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue