confinement-measures-oura.ipynb
How do the lockdowns/confinements related to COVID-19 influence our activity and sleep? This notebook looks into it!
Please log in to comment.Would people be interested in similar plots for other data sources (e.g. fitbit?)
The Oura Ring gives you daily scores for activity
, readiness
and sleep
. Let's see how those values change over time, comparing before and during the confinement. You can easily run this notebook on your data. You just need to connect your Oura ring to Open Humans!
Below's the boring processing code.
We're loading R for the visualization and aggregate the data points to get weekly averages, to smoothen out some of the day to day noise:
Now we can make our plots. Right now it grabs data going back to 2019-11-01
and uses 2020-03-15
as the confinemenet data. You can change those values below to make it work for your own situation.
The Oura Ring gives you daily scores for activity
, readiness
and sleep
. Let's see how those values change over time, comparing before and during the confinement. You can easily run this notebook on your data. You just need to connect your Oura ring to Open Humans!
Below's the boring processing code.
from ohapi import api
import os
import requests
import tempfile
user_details = api.exchange_oauth2_member(os.environ.get('OH_ACCESS_TOKEN'))
for i in user_details['data']:
if i['source'] == 'direct-sharing-184' and i['basename'] == 'oura-data.json':
break
import json
oura = json.loads(requests.get(i['download_url']).content)
dates = []
values = []
value_type = []
for sdate in oura['sleep']:
dates.append(sdate['summary_date'])
values.append(sdate['score'])
value_type.append('sleep')
for sdate in oura['activity']:
dates.append(sdate['summary_date'])
values.append(sdate['score'])
value_type.append('activity')
for sdate in oura['readiness']:
dates.append(sdate['summary_date'])
values.append(sdate['score'])
value_type.append('readiness')
import pandas as pd
dataframe = pd.DataFrame(
data = {
'date': dates,
'value': values,
'type': value_type
}
)
We're loading R for the visualization and aggregate the data points to get weekly averages, to smoothen out some of the day to day noise:
%load_ext rpy2.ipython
%%R -i dataframe
library(lubridate)
dataframe$date <- as.Date(dataframe$date)
dataframe$week <- floor_date(dataframe$date,unit='week')
df_agg <- aggregate(value~week+type,data=dataframe,FUN=mean)
head(df_agg)
Now we can make our plots. Right now it grabs data going back to 2019-11-01
and uses 2020-03-15
as the confinemenet data. You can change those values below to make it work for your own situation.
%%R -w 6 -h 6 --units in -r 200
library(ggplot2)
ggplot(subset(df_agg, df_agg$week > as.Date('2019-11-01')), aes(x=week,y=value)) +
geom_vline(xintercept=as.Date('2020-03-15'), color='red') +
geom_line() + theme_minimal() +
geom_smooth(se = FALSE,color='grey') +
scale_y_continuous('score') +
facet_grid(type ~ .) + labs(
title = "Personal effects of the confinement",
subtitle = "Red bar denotes start of confinement",
caption = 'Scores for "activity", "readiness" and "sleep" as given by the Oura ring.\n Black lines are weekly averages. Grey lines are loess fit.'
) + theme(text = element_text(size=12)) +
theme(plot.caption= element_text(size=9))