some attempts ti analyse data
This commit is contained in:
parent
d531cba77a
commit
3484a5a39b
5 changed files with 63 additions and 4 deletions
|
@ -43,7 +43,7 @@ class Emfit:
|
||||||
def epochs(self):
|
def epochs(self):
|
||||||
return self.jj['sleep_epoch_datapoints']
|
return self.jj['sleep_epoch_datapoints']
|
||||||
|
|
||||||
@property
|
@property # type: ignore
|
||||||
@lru_cache()
|
@lru_cache()
|
||||||
def sleep_start(self) -> datetime:
|
def sleep_start(self) -> datetime:
|
||||||
for [ts, e] in self.epochs:
|
for [ts, e] in self.epochs:
|
||||||
|
@ -52,7 +52,7 @@ class Emfit:
|
||||||
return fromts(ts)
|
return fromts(ts)
|
||||||
raise RuntimeError
|
raise RuntimeError
|
||||||
|
|
||||||
@property
|
@property # type: ignore
|
||||||
@lru_cache()
|
@lru_cache()
|
||||||
def sleep_end(self) -> datetime:
|
def sleep_end(self) -> datetime:
|
||||||
for [ts, e] in reversed(self.epochs):
|
for [ts, e] in reversed(self.epochs):
|
||||||
|
@ -79,9 +79,17 @@ class Emfit:
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def summary(self):
|
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
|
# measured_datapoints
|
||||||
# [[timestamp, pulse, breath?, ??? hrv?]] # every 4 seconds?
|
# [[timestamp, pulse, breath?, ??? hrv?]] # every 4 seconds?
|
||||||
@property
|
@property
|
||||||
|
@ -117,6 +125,10 @@ class Emfit:
|
||||||
res.append(rmssd)
|
res.append(rmssd)
|
||||||
return tss, res
|
return tss, res
|
||||||
|
|
||||||
|
@property
|
||||||
|
def measured_hr_avg(self):
|
||||||
|
return self.jj["measured_hr_avg"]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def sleep_hr_coverage(self):
|
def sleep_hr_coverage(self):
|
||||||
tss, hrs = self.sleep_hr
|
tss, hrs = self.sleep_hr
|
||||||
|
|
23
emfit/__main__.py
Normal file
23
emfit/__main__.py
Normal 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
19
plot.py
Normal file → Executable file
|
@ -1,8 +1,11 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
import matplotlib.dates as md # type: ignore
|
import matplotlib.dates as md # type: ignore
|
||||||
import numpy as np # type: ignore
|
import numpy as np # type: ignore
|
||||||
import seaborn as sns # type: ignore
|
import seaborn as sns # type: ignore
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
|
from emfit import get_datas
|
||||||
|
|
||||||
|
|
||||||
def plot_file(jj: str):
|
def plot_file(jj: str):
|
||||||
pts = jj['sleep_epoch_datapoints']
|
pts = jj['sleep_epoch_datapoints']
|
||||||
|
@ -87,6 +90,7 @@ def plot_recovery_vs_hr_percentage():
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
|
# TODO ah. it's only last segment?
|
||||||
def plot_hr():
|
def plot_hr():
|
||||||
jj = get_datas()[-1]
|
jj = get_datas()[-1]
|
||||||
tss, uu = jj.sleep_hr
|
tss, uu = jj.sleep_hr
|
||||||
|
@ -94,7 +98,19 @@ def plot_hr():
|
||||||
uu = uu[::10]
|
uu = uu[::10]
|
||||||
plt.figure(figsize=(15,4))
|
plt.figure(figsize=(15,4))
|
||||||
ax = sns.pointplot(tss, uu, markers=" ")
|
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()
|
plt.show()
|
||||||
|
|
||||||
|
@ -111,6 +127,7 @@ def plot_hr():
|
||||||
# stats()
|
# stats()
|
||||||
# plot_recovery_vs_hr_percentage()
|
# plot_recovery_vs_hr_percentage()
|
||||||
# stats()
|
# stats()
|
||||||
|
plot_hr_trend()
|
||||||
# import matplotlib
|
# import matplotlib
|
||||||
# matplotlib.use('Agg')
|
# matplotlib.use('Agg')
|
||||||
|
|
||||||
|
|
2
run
Executable file
2
run
Executable file
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/bash
|
||||||
|
python3 -m emfit
|
5
test.py
Executable file
5
test.py
Executable file
|
@ -0,0 +1,5 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
from emfit import get_datas
|
||||||
|
|
||||||
|
for d in get_datas():
|
||||||
|
print(d)
|
Loading…
Add table
Reference in a new issue