Created
October 1, 2012 06:37
-
-
Save andrewjbennett/3809859 to your computer and use it in GitHub Desktop.
zeo - draw graph of sleep/wake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
import time | |
from matplotlib.pyplot import * | |
times0 = [] | |
times1 = [] | |
times2 = [] | |
with open('zeodata.csv', 'rb') as csvfile: | |
zreader = csv.reader(csvfile, delimiter=',') | |
for row in zreader: | |
if row[0] == "Sleep Date": | |
continue | |
if row[9] == '' or row[11] == '': | |
continue | |
date = row[0] | |
dtime = time.strptime(date, "%m/%d/%Y") | |
start = row[9] | |
startTime = time.strptime(start, "%m/%d/%Y %H:%M") | |
end = row[11] | |
endTime = time.strptime(end, "%m/%d/%Y %H:%M") | |
# draw a line from start to end | |
epochStartTime = time.mktime(startTime) | |
epochEndTime = time.mktime(endTime) | |
dayNumber = time.strftime("%j",startTime) | |
epochDay = time.mktime(time.strptime(time.strftime("%j %Y",startTime),"%j %Y")) | |
epochEndDay = time.mktime(time.strptime(time.strftime("%j %Y",endTime),"%j %Y")) | |
if (time.strftime("%Y", startTime) == "2012"): | |
dayNumber = int(dayNumber) + 366 | |
if time.strftime("%j", startTime) == time.strftime("%j", endTime): | |
minsSinceStartTime = (epochStartTime - epochDay) / 60 | |
minsSinceEndTime = (epochEndTime - epochDay) / 60 | |
times0.append(int(dayNumber)) | |
times1.append(abs(1440-int(minsSinceStartTime))) | |
times2.append(abs(1440-int(minsSinceEndTime))) | |
else: | |
# draw a line from start to midnight | |
minsSinceStartTime = (epochStartTime - epochDay) / 60 | |
midnightStart = 60 * 24 | |
times0.append(int(dayNumber)) | |
times1.append(abs(1440-int(minsSinceStartTime))) | |
times2.append(abs(1440-int(midnightStart))) | |
# draw a line from the next day to end | |
minsSinceEndTime = (epochEndTime - epochEndDay) / 60 | |
midnightEnd = 0 | |
times0.append(int(dayNumber)+1) | |
times1.append(abs(1440-int(midnightEnd))) | |
times2.append(abs(1440-int(minsSinceEndTime))) | |
vlines(times0,times1,times2) | |
show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment