port endomondo data provider from my private package

This commit is contained in:
Dima Gerasimov 2020-09-12 11:06:27 +01:00 committed by karlicoss
parent 28fcc1d9b6
commit baac593aef
2 changed files with 71 additions and 1 deletions

70
my/endomondo.py Normal file
View file

@ -0,0 +1,70 @@
'''
Endomondo exercise data
'''
from dataclasses import dataclass
from pathlib import Path
from typing import Sequence, Iterable
from .core.common import Paths, get_files
from .core.error import Res
from my.config import endomondo as user_config
@dataclass
class endomondo(user_config):
'''
Uses [[https://github.com/karlicoss/endoexport][endoexport]] outputs
'''
# paths[s]/glob to the exported JSON data
export_path: Paths
def inputs() -> Sequence[Path]:
return get_files(endomondo.export_path)
# todo add a doctor check for pip endoexport module
import endoexport.dal
from endoexport.dal import Point, Workout
# todo cachew?
def workouts() -> Iterable[Res[Workout]]:
dal = endoexport.dal.DAL(inputs())
yield from dal.workouts()
def dataframe(defensive=True):
def it():
for w in workouts():
if isinstance(w, Exception):
yield {'error': str(w)}
else:
try:
d = {
'id' : w.id ,
'start_time' : w.start_time ,
'duration' : w.duration ,
'sport' : w.sport ,
'heart_rate_avg': w.heart_rate_avg,
'speed_avg' : w.speed_avg ,
'kcal' : w.kcal ,
}
except Exception as e:
# TODO use the trace? otherwise str() might be too short..
# r.g. for KeyError it only shows the missing key
# todo check for 'defensive'
d = {'error': f'{e} {w}'}
yield d
import pandas as pd # type: ignore
return pd.DataFrame(it())
def stats():
from .core import stat
return stat(workouts)
# TODO make sure it's possible to 'advise' functions and override stuff

View file

@ -11,7 +11,7 @@ from pathlib import Path
# TODO pytz for timezone???
from .common import get_files, LazyLogger
from .core.common import get_files, LazyLogger
from my.config import foursquare as config