Maximizing Sleep With Plotly and Sleep Cycle

by make_it_or_leave_it in Circuits > Tools

4268 Views, 20 Favorites, 0 Comments

Maximizing Sleep With Plotly and Sleep Cycle

535407972f7cc62b0800003b.jpg
Screen Shot 2014-04-20 at 12.08.45 PM.png

As a competitive swimmer and high school student, every minute of sleep is valuable to me. Being diligent about studying, eating and sleeping are the keys to my success in both the school and the pool. If you do not share this lifestyle but still want to understand your sleep patterns and discover how to maximize your sleep potential, you might find this valuable. With a collaboration of two essentials, Plotly and Sleep Cycle, you will be well on your way to better sleep. The Sleep Cycle mobile application utilizes a smartphone's accelerometer to track each night of sleep. I've logged just under two hundred nights thus far. The app traces your patterns of sleep, but unfortunately, the data gathered by the application is not displayed in an easy, understandable way. That is where Plotly comes in!

Gathering Data

5353fbc226ece23b5c00000d.jpg
5353fcd9182470c612000001.jpg
5353fc64d535cfd8a000003a.jpg

This step is quite straight forward, download the Sleep Cycle app, place it on your bed, while plugged into a charger, and sleep the night away. You'll need a minimum of seven nights in order to get a sleep quality percentage.

Export the Data

5353f4ecc6ba5d3c9c00002b.jpg
IMG_0876.JPG

Once you have a decent amount of nights, and you're ready to display them in Plotly, you'll need to export the data form Sleep Cycle. Thankfully, Sleep Cycle makes this incredibly easy. Go to settings>advanced>export database and send the file to a desirable target that can be opened on a PC or Mac. (The file will save as a .csv)

Adding the Data to Plotly

Screen Shot 2014-04-20 at 11.50.55 AM.png
Screen Shot 2014-04-20 at 11.51.34 AM.png
Screen Shot 2014-04-20 at 11.52.03 AM.png
Screen Shot 2014-04-20 at 11.52.19 AM.png
Screen Shot 2014-04-20 at 11.52.38 AM.png

The first thing you'll want to do is obtain a Plotly account. Once done, create a new project, and import the csv file. Once the file is selected, the data will automatically input. If you would rather experiment with my data rather than log nights, it is provided!

Downloads

Display the Data (the Fun Part)

Screen Shot 2014-04-20 at 11.58.08 AM.png
Screen Shot 2014-04-20 at 11.58.38 AM.png
Screen Shot 2014-04-20 at 12.08.11 PM.png
Screen Shot 2014-04-20 at 12.08.22 PM.png
Screen Shot 2014-04-20 at 12.08.34 PM.png
Screen Shot 2014-04-20 at 12.10.31 PM.png

For this next step, it is up to you what data you would like to see. For me, I chose to display sleep quality percentage each night. For that, I selected the date to be X and the quality to be Y. Once you've selected the desired date, click line plot. (You can do a line plot or a scatterplot, I chose a scatterplot) At first glance, you should see some sort of relationship, but for a more detailed version and r-value, click Fit Trace, add a linear fit, and run it.

Have fun playing around with Plotly! Customize the look to meet your needs, display the data you want to see, and be on your way to maximizing your sleep.