effkay / convert_apple_health_export

Extract blood pressure data from Apple Health export XML and convert to a CSV
MIT License
0 stars 1 forks source link

Request to add heart rate. #1

Open MtnBiker opened 3 years ago

MtnBiker commented 3 years ago

Edit: Not as simple as stated. HR is not exactly at same time. But maybe I can still sort it out. Edit 2: My data has too many differences, so will work on another version. Withings records heart rate two different ways. One as shown below and HKQuantityTypeIdentifierHeartRate. And the time stamp is exactly the same; occurs some seconds later.

This works great. Withings BPM Connect also records heart rate with the same time stamp. I may be able to figure it out but realized you've assumed only time, systolic and diastolic. Simple hacking appears easy except for the def call(diastolic_records, systolic_records, hr_records) method.

XPATH_HEARTRATE= "//Record[contains(@type,'HKQuantityTypeIdentifierRestingHeartRate')]"

If I figure it out I'll let you know. Your Ruby skills are way beyond mine. I want to include something like this in a Rails app to better view the data.

Thank you for putting this together. I was able to hack it even though I don't understand all of what you've done.

effkay commented 3 years ago

Hi @MtnBiker

Thanks for the feedback. Reopening this issue because I plan to add the heart rate as you suggested.

MtnBiker commented 3 years ago

Great. I would also suggest you put systolic firsts since that's standard.

I've got my version working. But because the time stamp for hr is later, I used a crude hack to pick it up. Crude because time becomes a string and it's hard to do math on a string. Which just gave me an idea. Does Ruby have .to_t? Of course not, but parsing the string and doing the math is straightforward.

effkay commented 3 years ago

You can parse a String and make it a Date object with DateTime.parse

effkay commented 3 years ago

Feel free to create a separate issue for the Suggested change in order;)

MtnBiker commented 3 years ago

I'm working on how to use the script in my Rails app. But I need to understand a couple of concepts better. If/when I succeed, I'll get back.