Created
May 11, 2015 01:17
-
-
Save cobolfoo/6868b0558f7f9c6be831 to your computer and use it in GitHub Desktop.
Converting XML data about health rate from Apple Watch to CSV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$xml = xml_parser_create(); | |
xml_parse_into_struct($xml, file_get_contents("export.xml"),$values,$indexes); | |
print '"Date/Time","Average","Minimum","Maximum"'."\r\n"; | |
foreach($values as $val) { | |
if (isset($val["attributes"]) == false) { | |
continue; | |
} | |
if ($val["attributes"]["TYPE"] != "HKQuantityTypeIdentifierHeartRate") continue; | |
$date = $val["attributes"]["STARTDATE"]; | |
sscanf($date, "%04s%02s%02s%02s%02s%02s-0400", $year, $month, $day, $hour, $minute, $second ); | |
$readable_date = $year."-".$month."-".$day." ".$hour.":".$minute.":".$second; | |
$min = round($val["attributes"]["MIN"] * 60); | |
$max = round($val["attributes"]["MAX"] * 60); | |
$avg = round($val["attributes"]["AVERAGE"] * 60); | |
print '"'.$readable_date.'","'.$min.'","'.$avg.'","'.$max.'"'."\r\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment