From 79bcdd162652ea5bc1c019bc0073f2d1254fd92a Mon Sep 17 00:00:00 2001 From: Jason Meno Date: Fri, 24 Jan 2020 18:55:23 -0500 Subject: [PATCH] Added metadata support for all records --- apple_health_xml_convert.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/apple_health_xml_convert.py b/apple_health_xml_convert.py index 5242ca7..acd9706 100644 --- a/apple_health_xml_convert.py +++ b/apple_health_xml_convert.py @@ -48,7 +48,13 @@ def convert_xml(): attribute_list = [] for child in etree.getroot(): - attribute_list.append(child.attrib) + child_attrib = child.attrib + for metadata_entry in list(child): + metadata_values = list(metadata_entry.attrib.values()) + metadata_dict = {metadata_values[0] : metadata_values[1]} + child_attrib.update(metadata_dict) + + attribute_list.append(child_attrib) health_df = pd.DataFrame(attribute_list) @@ -69,6 +75,16 @@ def convert_xml(): 'endDate', 'creationDate'] + # Add loop specific column ordering if metadata entries exist + if 'com.loopkit.InsulinKit.MetadataKeyProgrammedTempBasalRate' in original_cols: + shifted_cols.append('com.loopkit.InsulinKit.MetadataKeyProgrammedTempBasalRate') + + if 'com.loopkit.InsulinKit.MetadataKeyScheduledBasalRate' in original_cols: + shifted_cols.append('com.loopkit.InsulinKit.MetadataKeyScheduledBasalRate') + + if 'com.loudnate.CarbKit.HKMetadataKey.AbsorptionTimeMinutes' in original_cols: + shifted_cols.append('com.loudnate.CarbKit.HKMetadataKey.AbsorptionTimeMinutes') + remaining_cols = list(set(original_cols) - set(shifted_cols)) reordered_cols = shifted_cols + remaining_cols health_df = health_df.reindex(labels=reordered_cols, axis='columns')