my.body.sleep: integrate with optional temperature data
This commit is contained in:
parent
725597de97
commit
ed47e98d5c
2 changed files with 18 additions and 1 deletions
|
@ -36,6 +36,7 @@ class Measurement(NamedTuple):
|
|||
# NOTE: the timezone should be set with respect to the export date!!!
|
||||
import pytz # type: ignore
|
||||
tz = pytz.timezone('Europe/London')
|
||||
# TODO when I change tz, check the diff
|
||||
|
||||
|
||||
@mcachew(cache_path=cache_dir() / 'bluemaestro.cache')
|
||||
|
|
|
@ -7,10 +7,26 @@ class Combine:
|
|||
self.modules = modules
|
||||
|
||||
@cdf
|
||||
def dataframe(self) -> DataFrameT:
|
||||
def dataframe(self, with_temperature: bool=True) -> DataFrameT:
|
||||
import pandas as pd # type: ignore
|
||||
# todo include 'source'?
|
||||
df = pd.concat([m.dataframe() for m in self.modules])
|
||||
|
||||
if with_temperature:
|
||||
from ... import bluemaestro as BM
|
||||
bdf = BM.dataframe()
|
||||
temp = bdf['temp']
|
||||
|
||||
def calc_avg_temperature(row):
|
||||
start = row['sleep_start']
|
||||
end = row['sleep_end']
|
||||
if pd.isna(start) or pd.isna(end):
|
||||
return None
|
||||
|
||||
# on no temp data, returns nan, ok
|
||||
return temp[start: end].mean()
|
||||
|
||||
df['avg_temp'] = df.apply(calc_avg_temperature, axis=1)
|
||||
return df
|
||||
|
||||
def stats(self) -> Stats:
|
||||
|
|
Loading…
Add table
Reference in a new issue