display single sleep on plot

This commit is contained in:
Dima Gerasimov 2017-11-13 23:22:31 +00:00
parent 1486266bb3
commit 25414b4284

View file

@ -1,7 +1,7 @@
#!/usr/bin/env python3.6
from kython import *
from backup_config import SLEEPS_FILE
from backup_config import SLEEPS_FILE, GRAPHS_DIR
from datetime import datetime
from datetime import date
@ -33,6 +33,9 @@ class SleepEntry:
def completed(self) -> datetime:
return datetime.fromtimestamp(self.js['time_completed'])
def graph(self) -> str:
return os.path.join(GRAPHS_DIR, self.xid() + ".png")
def __str__(self) -> str:
return f"{self.date_()} {self.title()}"
@ -45,4 +48,33 @@ def load_sleeps() -> List[SleepEntry]:
return [SleepEntry(js) for js in sleeps]
sleeps = load_sleeps()
pprint(sleeps[:2])
# TODO use map?
sleep = sleeps[0]
# pprint(sleeps[:2])
span = sleep.completed() - sleep.created()
print(f"span: {span}")
import numpy as np # type: ignore
import matplotlib.pyplot as plt # type: ignore
# pip install imageio
from imageio import imread # type: ignore
img = imread(sleep.graph())
# all of them are 300x300 images apparently
(a, b, _) = img.shape
# print(img.shape)
# print(img.size)
print(a)
print(b)
np.random.seed(0)
x = np.random.uniform(0.0, a, 100)
y = np.random.uniform(0.0, b, 100)
plt.scatter(x,y,zorder=1)
plt.imshow(img,zorder=0)
plt.title(str(sleep))
plt.text(0, 0, str(sleep.created().time()))
plt.text(300, 0, str(sleep.completed().time()))
plt.show()