Skip to content

Commit

Permalink
Added metadata support for all records
Browse files Browse the repository at this point in the history
  • Loading branch information
jameno authored Jan 24, 2020
1 parent 5c26ad9 commit 79bcdd1
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion apple_health_xml_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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')
Expand Down

0 comments on commit 79bcdd1

Please sign in to comment.