some attempts ti analyse data

This commit is contained in:
Dima Gerasimov 2018-10-16 23:19:09 +01:00
parent d531cba77a
commit 3484a5a39b
5 changed files with 63 additions and 4 deletions

View file

@ -43,7 +43,7 @@ class Emfit:
def epochs(self):
return self.jj['sleep_epoch_datapoints']
@property
@property # type: ignore
@lru_cache()
def sleep_start(self) -> datetime:
for [ts, e] in self.epochs:
@ -52,7 +52,7 @@ class Emfit:
return fromts(ts)
raise RuntimeError
@property
@property # type: ignore
@lru_cache()
def sleep_end(self) -> datetime:
for [ts, e] in reversed(self.epochs):
@ -79,9 +79,17 @@ class Emfit:
@property
def summary(self):
return f"for {hhmm(self.sleep_minutes)} hrv: [{self.hrv_morning:.0f} {self.hrv_evening:.0f} {self.hrv_morning - self.hrv_evening:3.0f} {self.hrv_lf}/{self.hrv_hf}]"
return f"""
slept for {hhmm(self.sleep_minutes)}
hrv morning: {self.hrv_morning:.0f}
hrv evening: {self.hrv_evening:.0f}
recovery: {self.hrv_morning - self.hrv_evening:3.0f}
{self.hrv_lf}/{self.hrv_hf}""".replace('\n', ' ')
def __str__(self) -> str:
return f"from {self.sleep_start} to {self.sleep_end}"
# measured_datapoints
# [[timestamp, pulse, breath?, ??? hrv?]] # every 4 seconds?
@property
@ -117,6 +125,10 @@ class Emfit:
res.append(rmssd)
return tss, res
@property
def measured_hr_avg(self):
return self.jj["measured_hr_avg"]
@property
def sleep_hr_coverage(self):
tss, hrs = self.sleep_hr

23
emfit/__main__.py Normal file
View file

@ -0,0 +1,23 @@
from emfit import get_datas
for e in get_datas():
# print("-------")
print(f"{e.end} {e.measured_hr_avg} {e.summary}")
# TODO get average HR
# TODO get 'quality', that is amount of time it actually had signal
from kython.plotting import plot_timestamped
everything = get_datas()
tss = [e.end for e in everything]
hrs = [e.measured_hr_avg for e in everything]
plot_timestamped(
tss,
hrs,
ratio=(15, 3),
mavgs=[(5, 'blue'), (10, 'green')],
marker='.',
ylimits=[40, 70],
).savefig('hrs.png')

19
plot.py Normal file → Executable file
View file

@ -1,8 +1,11 @@
#!/usr/bin/env python3
import matplotlib.dates as md # type: ignore
import numpy as np # type: ignore
import seaborn as sns # type: ignore
import matplotlib.pyplot as plt
from emfit import get_datas
def plot_file(jj: str):
pts = jj['sleep_epoch_datapoints']
@ -87,6 +90,7 @@ def plot_recovery_vs_hr_percentage():
plt.show()
# TODO ah. it's only last segment?
def plot_hr():
jj = get_datas()[-1]
tss, uu = jj.sleep_hr
@ -94,7 +98,19 @@ def plot_hr():
uu = uu[::10]
plt.figure(figsize=(15,4))
ax = sns.pointplot(tss, uu, markers=" ")
ax.set(ylim=(None, 1000))
# TODO wtf is that/??
ax.set(ylim=(None, 200))
plt.show()
def plot_hr_trend():
everything = get_datas()
tss = [e.end for e in everything]
hrs = [e.measured_hr_avg for e in everything]
plt.figure(figsize=(15,4))
ax = sns.pointplot(tss, hrs) # , markers=" ")
# TODO wtf is that/??
ax.set(ylim=(None, 70))
plt.show()
@ -111,6 +127,7 @@ def plot_hr():
# stats()
# plot_recovery_vs_hr_percentage()
# stats()
plot_hr_trend()
# import matplotlib
# matplotlib.use('Agg')

2
run Executable file
View file

@ -0,0 +1,2 @@
#!/bin/bash
python3 -m emfit

5
test.py Executable file
View file

@ -0,0 +1,5 @@
#!/usr/bin/env python3
from emfit import get_datas
for d in get_datas():
print(d)