deepankardatta / AppleHealthAnalysis

A R package to analyse exported Apple Health XML data
GNU General Public License v3.0
25 stars 4 forks source link

Package Features #2

Open benjaminwnelson opened 6 years ago

benjaminwnelson commented 6 years ago

Thank you for making such a fantastic package for accessing Apple Healthkit data. I was wondering if there is a way to access the following additional variables?

Also, is there a way to provide summery variables for each day, such as total steps, as well as interday data in 10 minute bins, such as steps every 10 minutes?

Thanks!

deepankardatta commented 6 years ago

Hi there

Thanks for your interest. The package is still in a very early stage, and I haven't had much time to work on it. It's really meant to be an easy way to extract the data, and for the user to make the most of the data as needed.


I can't see "Active Minutes" and "Idle Hours" on my Apple Health data. It might be that I've not asked to measure it on my phone, or it is a composite measure.

Could you try the following and see what happens:

library(AppleHealthAnalysis)
health_data <- ah_import_xml("export.xml")
summary(health_data$type)

or levels(health_data$type)

The last command gives you a list of all the metrics that your phone / apple watch measures. Do you see "Active Minutes" and "Idle Hours" there?


To your second question you can extract the data as above, and then select what variable you want, e.g.: heart_rate_data <- ah_data_select( health_data , "HeartRate" )

I haven't gone out of my way to test this thoroughly, but you will probably need the dplyr, tidyr, purrr, shiny and ggplot2 libraries. Maybe lubridate

I've cribbed some of the code from the in-development shiny dashboard (again not fully developed yet) to filter the data:

health_data %>%
          filter( type == input$health_variable ) %>%
          filter( date >= input$dates_to_explore[1] & date <= input$dates_to_explore[2]

You need to specify the health data type, and dates you want.

I've then cribbed some in-development code from a heatmap function (from data already filtered to be heart rate data):

test <- heart_rate_data %>%
  group_by(  date , hour )  %>%
  summarise( heart_rate = mean(value) , n = n() )

This should filter the data enough for you to boxplot them. You just need to filter it to the specifications that you want.


I hope this helps!

With Thanks

deepankardatta commented 6 years ago

So I think what you actually want for "Active Minutes" is to select the data for "AppleExerciseTime", e.g.

library(AppleHealthAnalysis)
health_data <- ah_import_xml("export.xml")
active_minutes <- ah_data_select( health_data , "AppleExerciseTime" )

Apple Health keeps exercise and stand time in a format that for "AppleExerciseTime" and "AppleStandHour" if the data point exists it counts as a positive exercise or stand effort in that time period, and if it doesn't exist then it didn't happen.

My data doesn't have idle hours when i filter it in excel. Does yours? I suspect you need to define what you exactly mean by "idle", e.g. not standing / not active minutes , and do some maths to get that time.