Sleep data graphs

I’ve been using the Sleep as Android app to track my sleep for a little while now.  The application allows exporting to CSV files. I thought, “GREAT! I can bash in some, well, BASH and put this in Graphite“. You know to look at it in relation to other things I’m tracking and wastes of time like that.

I cracked open the CSV and immediately noticed it was REALLY whacky. Okay, well, not whacky, just not what I expected. I was expecting a row of data descriptions with a day’s values per row. This was going to take more work than I anticipated.

I took a spin around the Googles to see if I could borrow someone else’s work. I found this gentleman had done the parsing of the CSV file already. Unfortunately for me, it was in Ruby, which I don’t know. (LIES!)

I hacked together some Python and, after some playing around with the data (and reading the above website), I found it was was three rows per day. The first row has some static data and variables which are the descriptions for the next two rows of data. The variables in the first row are the times it captures data points at. The second row had the data I wanted which was a value low (deep sleep) to high (light sleep).

A little more Python hackery and I produced Graphite friendly output.  The python script is available over here.

I was thinking of adding in the ability to put this directly into Graphite, but my mind was starting to wander at this point. Perhaps another day.