add my.body.sleep, combine together emfit/jawbone

This commit is contained in:
Dima Gerasimov 2020-10-09 22:34:38 +01:00 committed by karlicoss
parent e8e4994c02
commit 725597de97
5 changed files with 29 additions and 2 deletions

View file

17
my/body/sleep/common.py Normal file
View file

@ -0,0 +1,17 @@
from ...core import stat, Stats
from ...core.pandas import DataFrameT, check_dataframe as cdf
class Combine:
def __init__(self, modules) -> None:
self.modules = modules
@cdf
def dataframe(self) -> DataFrameT:
import pandas as pd # type: ignore
# todo include 'source'?
df = pd.concat([m.dataframe() for m in self.modules])
return df
def stats(self) -> Stats:
return stat(self.dataframe)

11
my/body/sleep/main.py Normal file
View file

@ -0,0 +1,11 @@
from ... import jawbone
from ... import emfit
from .common import Combine
_combined = Combine([
jawbone,
emfit,
])
dataframe = _combined.dataframe
stats = _combined.stats

View file

@ -133,7 +133,7 @@ def dataframe() -> DataFrameT:
import pandas # type: ignore
return pandas.DataFrame(dicts)
# TODO add dataframe support to stat()
from ..core import stat, Stats
def stats() -> Stats:
return stat(pre_dataframe)

View file

@ -147,7 +147,6 @@ def dataframe():
# TODO tz is in sleeps json
# TODO add dataframe support to stat()
def stats():
from ..core import stat
return stat(pre_dataframe)