diff --git a/my/endomondo.py b/my/endomondo.py new file mode 100644 index 0000000..53ffcdb --- /dev/null +++ b/my/endomondo.py @@ -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 diff --git a/my/foursquare.py b/my/foursquare.py index a722b3a..a2f9878 100755 --- a/my/foursquare.py +++ b/my/foursquare.py @@ -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