body.exercise: add cardio summary, move cross trainer to a separate file

This commit is contained in:
Dima Gerasimov 2020-09-17 21:35:18 +01:00 committed by karlicoss
parent eb14d5988d
commit f02c572cc0
2 changed files with 58 additions and 8 deletions

View file

@ -0,0 +1,50 @@
'''
Cardio data, filtered from Endomondo and inferred from other data sources
'''
from ...core.pandas import check_dataframe as cdf
import pandas as pd # type: ignore
CARDIO = {
'Running',
'Running, treadmill',
'Cross training',
'Walking',
'Skating',
'Spinning',
'Skiing',
'Table tennis',
'Rope jumping',
}
# todo if it has HR data, take it into the account??
NOT_CARDIO = {
'Other',
}
@cdf
def endomondo_cardio() -> pd.DataFrame:
assert len(CARDIO.intersection(NOT_CARDIO)) == 0, (CARDIO, NOT_CARDIO)
from ..endomondo import dataframe as EDF
df = EDF()
# not sure...
# df = df[df['heart_rate_avg'].notna()]
is_cardio = df['sport'].isin(CARDIO)
not_cardio = df['sport'].isin(NOT_CARDIO)
neither = ~is_cardio & ~not_cardio
# if neither -- count, but warn? or show error?
# todo error about the rest??
# todo append errors?
df.loc[neither, 'error'] = 'Unexpected exercise type, please mark as cardio or non-cardio'
df = df[is_cardio | neither]
return df
def dataframe():
return endomondo_cardio()