From 3d28c3ca6e0115070d0a33d7bfd1e9f40363faf0 Mon Sep 17 00:00:00 2001 From: Dima Gerasimov Date: Thu, 11 Apr 2019 11:35:07 +0100 Subject: [PATCH] some wip --- TODO.org | 10 +++------- analyse.py | 23 ++++++++++++----------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/TODO.org b/TODO.org index 62f6537..ccea496 100644 --- a/TODO.org +++ b/TODO.org @@ -1,6 +1,5 @@ https://github.com/crowoy/Health-Analysis https://github.com/joytafty-work/SleepModel -https://github.com/carleshf/jawboneup2tex https://github.com/search?l=Jupyter+Notebook&q=s_awakenings&type=Code&utf8=%E2%9C%93 https://github.com/oshev/colifer/blob/592cc6b4d1ac9005c52fccdfb4e207513812baaa/colifer.py https://github.com/oshev/colifer/blob/592cc6b4d1ac9005c52fccdfb4e207513812baaa/reportextenders/jawbone/jawbone_sleep.py @@ -9,10 +8,7 @@ https://github.com/GlenCrawford/ruby_jawbone * https://nyquist212.wordpress.com/2015/06/22/visualizing-jawbone-up-data-with-d3-js/ -* jawbone sleeps meta: -** time_created: apparently starto of sleep (leftmost point of plot) -** time_updated: rightmost point of plot -** details -> asleep_time, awake_time +* TODO ok, so shoud really do a week of consistent bedtime/waking up to make some final decision on jawbone? - -* TODO align multiple on the same plot/picture to see patterns +* TODO figure out timezones +* TODO post on reddit? release and ask people to run against their data? diff --git a/analyse.py b/analyse.py index 8300a6b..6be3997 100755 --- a/analyse.py +++ b/analyse.py @@ -70,6 +70,8 @@ def load_sleeps() -> List[SleepEntry]: return [SleepEntry(js) for js in sleeps] import numpy as np # type: ignore import matplotlib.pyplot as plt # type: ignore +from matplotlib.figure import Figure # type: ignore +from matplotlib.axes import Axes # type: ignore # pip install imageio from imageio import imread # type: ignore from scipy.misc import imresize # type: ignore @@ -85,8 +87,6 @@ def hhmm(time: datetime): # return fromstart / tick import matplotlib.dates as mdates # type: ignore -from matplotlib.figure import Figure # type: ignore -from matplotlib.axes import Axes # type: ignore from matplotlib.ticker import MultipleLocator, FixedLocator # type: ignore def plot_one(sleep: SleepEntry, fig: Figure, axes: Axes, xlims=None, showtext=True): @@ -166,11 +166,7 @@ import melatonin dt = melatonin.get_data() # dt = {k: v for k, v in dt.items() if v is not None} -sleeps = [sleeps_by_date[d] for d in dt if d in sleeps_by_date] -sleeps_count = len(sleeps) - - -fig: Figure = plt.figure(figsize=(15, sleeps_count * 1)) +sleeps = list(sleeps_by_date.values()) # [sleeps_by_date[d] for d in dt if d in sleeps_by_date] def predicate(sleep: SleepEntry): """ @@ -182,15 +178,20 @@ def predicate(sleep: SleepEntry): return True return False -# sleeps = lfilter(predicate, sleeps) +sleeps = lfilter(predicate, sleeps) +sleeps_count = len(sleeps) +print(sleeps_count) + + +fig: Figure = plt.figure(figsize=(15, sleeps_count * 1)) axarr = fig.subplots(nrows=len(sleeps)) for i, (sleep, axes) in enumerate(zip(sleeps, axarr)): plot_one(sleep, fig, axes, showtext=True) - used = dt[sleep.date_] + used = dt.get(sleep.date_, None) sused: str color: str - used = True if used is None else False # TODO? + # used = True if used is None else False # TODO? if used is True: sused = "YES" color = 'green' @@ -199,7 +200,7 @@ for i, (sleep, axes) in enumerate(zip(sleeps, axarr)): color = 'red' else: sused = "??" - color = 'blue' + color = 'white' axes.text(axes.get_xlim()[0], 20, sused) axes.patch.set_alpha(0.5) axes.set_facecolor(color)