my.body.exercise: add more annotations & ci check
This commit is contained in:
parent
06ee72bc30
commit
e63c159b80
4 changed files with 31 additions and 25 deletions
|
@ -2,7 +2,7 @@
|
||||||
Feel free to remove this if you don't need it/add your own custom settings and use them
|
Feel free to remove this if you don't need it/add your own custom settings and use them
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from my.core import Paths
|
from my.core import Paths, PathIsh
|
||||||
|
|
||||||
class hypothesis:
|
class hypothesis:
|
||||||
# expects outputs from https://github.com/karlicoss/hypexport
|
# expects outputs from https://github.com/karlicoss/hypexport
|
||||||
|
@ -23,3 +23,6 @@ class reddit:
|
||||||
|
|
||||||
class endomondo:
|
class endomondo:
|
||||||
export_path: Paths = ''
|
export_path: Paths = ''
|
||||||
|
|
||||||
|
class exercise:
|
||||||
|
workout_log: PathIsh = '/some/path.org'
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
'''
|
'''
|
||||||
Cardio data, filtered from Endomondo and inferred from other data sources
|
Cardio data, filtered from Endomondo and inferred from other data sources
|
||||||
'''
|
'''
|
||||||
from ...core.pandas import check_dataframe as cdf
|
from ...core.pandas import DataFrameT, check_dataframe as cdf
|
||||||
|
|
||||||
import pandas as pd # type: ignore
|
|
||||||
|
|
||||||
|
|
||||||
CARDIO = {
|
CARDIO = {
|
||||||
|
@ -24,10 +22,10 @@ NOT_CARDIO = {
|
||||||
|
|
||||||
|
|
||||||
@cdf
|
@cdf
|
||||||
def endomondo_cardio() -> pd.DataFrame:
|
def endomondo_cardio() -> DataFrameT:
|
||||||
assert len(CARDIO.intersection(NOT_CARDIO)) == 0, (CARDIO, NOT_CARDIO)
|
assert len(CARDIO.intersection(NOT_CARDIO)) == 0, (CARDIO, NOT_CARDIO)
|
||||||
|
|
||||||
from ..endomondo import dataframe as EDF
|
from ...endomondo import dataframe as EDF
|
||||||
df = EDF()
|
df = EDF()
|
||||||
|
|
||||||
# not sure...
|
# not sure...
|
||||||
|
@ -46,5 +44,5 @@ def endomondo_cardio() -> pd.DataFrame:
|
||||||
return df
|
return df
|
||||||
|
|
||||||
|
|
||||||
def dataframe():
|
def dataframe() -> DataFrameT:
|
||||||
return endomondo_cardio()
|
return endomondo_cardio()
|
||||||
|
|
|
@ -8,7 +8,7 @@ For now it's worth keeping it here as an example and perhaps utility functions m
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from ...core.pandas import check_dataframe as cdf
|
from ...core.pandas import DataFrameT, check_dataframe as cdf
|
||||||
|
|
||||||
from my.config import exercise as config
|
from my.config import exercise as config
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ def cross_trainer_data():
|
||||||
for k, v in row.items():
|
for k, v in row.items():
|
||||||
# todo have something smarter... e.g. allow pandas to infer the type??
|
# todo have something smarter... e.g. allow pandas to infer the type??
|
||||||
mapper = mappers.get(k, maybe(float))
|
mapper = mappers.get(k, maybe(float))
|
||||||
d[k] = mapper(v)
|
d[k] = mapper(v) # type: ignore[operator]
|
||||||
yield d
|
yield d
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# todo add parsing context
|
# todo add parsing context
|
||||||
|
@ -70,11 +70,11 @@ def cross_trainer_data():
|
||||||
|
|
||||||
|
|
||||||
@cdf
|
@cdf
|
||||||
def cross_trainer_manual_dataframe():
|
def cross_trainer_manual_dataframe() -> DataFrameT:
|
||||||
'''
|
'''
|
||||||
Only manual org-mode entries
|
Only manual org-mode entries
|
||||||
'''
|
'''
|
||||||
import pandas as pd
|
import pandas as pd # type: ignore[import]
|
||||||
df = pd.DataFrame(cross_trainer_data())
|
df = pd.DataFrame(cross_trainer_data())
|
||||||
return df
|
return df
|
||||||
|
|
||||||
|
@ -83,11 +83,11 @@ _DELTA = timedelta(hours=10)
|
||||||
|
|
||||||
# todo check error handling by introducing typos (e.g. especially dates) in org-mode
|
# todo check error handling by introducing typos (e.g. especially dates) in org-mode
|
||||||
@cdf
|
@cdf
|
||||||
def dataframe():
|
def dataframe() -> DataFrameT:
|
||||||
'''
|
'''
|
||||||
Attaches manually logged data (which Endomondo can't capture) and attaches it to Endomondo
|
Attaches manually logged data (which Endomondo can't capture) and attaches it to Endomondo
|
||||||
'''
|
'''
|
||||||
import pandas as pd
|
import pandas as pd # type: ignore[import]
|
||||||
|
|
||||||
from ...endomondo import dataframe as EDF
|
from ...endomondo import dataframe as EDF
|
||||||
edf = EDF()
|
edf = EDF()
|
||||||
|
@ -99,7 +99,7 @@ def dataframe():
|
||||||
# now for each manual entry, find a 'close enough' endomondo entry
|
# now for each manual entry, find a 'close enough' endomondo entry
|
||||||
# ideally it's a 1-1 (or 0-1) relationship, but there might be errors
|
# ideally it's a 1-1 (or 0-1) relationship, but there might be errors
|
||||||
rows = []
|
rows = []
|
||||||
idxs = []
|
idxs = [] # type: ignore[var-annotated]
|
||||||
NO_ENDOMONDO = 'no endomondo matches'
|
NO_ENDOMONDO = 'no endomondo matches'
|
||||||
for i, row in mdf.iterrows():
|
for i, row in mdf.iterrows():
|
||||||
rd = row.to_dict()
|
rd = row.to_dict()
|
||||||
|
@ -159,12 +159,12 @@ def dataframe():
|
||||||
# TODO wtf?? where is speed coming from??
|
# TODO wtf?? where is speed coming from??
|
||||||
|
|
||||||
|
|
||||||
def stats():
|
from ...core import stat, Stats
|
||||||
from ...core import stat
|
def stats() -> Stats:
|
||||||
return stat(cross_trainer_data)
|
return stat(cross_trainer_data)
|
||||||
|
|
||||||
|
|
||||||
def compare_manual():
|
def compare_manual() -> None:
|
||||||
df = dataframe()
|
df = dataframe()
|
||||||
df = df.set_index('start_time')
|
df = df.set_index('start_time')
|
||||||
|
|
||||||
|
|
21
tox.ini
21
tox.ini
|
@ -37,15 +37,20 @@ commands =
|
||||||
pip install git+https://github.com/karlicoss/pockexport
|
pip install git+https://github.com/karlicoss/pockexport
|
||||||
pip install git+https://github.com/karlicoss/rexport
|
pip install git+https://github.com/karlicoss/rexport
|
||||||
pip install git+https://github.com/karlicoss/endoexport
|
pip install git+https://github.com/karlicoss/endoexport
|
||||||
|
|
||||||
|
pip install git+https://github.com/karlicoss/porg
|
||||||
|
|
||||||
# todo I guess use a script...
|
# todo I guess use a script...
|
||||||
python3 -m mypy -p my.github.ghexport \
|
python3 -m mypy -p my.github.ghexport \
|
||||||
-p my.hypothesis \
|
-p my.hypothesis \
|
||||||
-p my.instapaper \
|
-p my.instapaper \
|
||||||
-p my.pocket \
|
-p my.pocket \
|
||||||
-p my.reddit \
|
-p my.reddit \
|
||||||
-p my.endomondo \
|
-p my.endomondo \
|
||||||
--txt-report .mypy-coverage \
|
-p my.body.exercise.cardio \
|
||||||
--html-report .mypy-coverage \
|
-p my.body.exercise.cross_trainer \
|
||||||
|
--txt-report .mypy-coverage \
|
||||||
|
--html-report .mypy-coverage \
|
||||||
{posargs}
|
{posargs}
|
||||||
# txt report is a bit more convenient to view on CI
|
# txt report is a bit more convenient to view on CI
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue