dogsheep / healthkit-to-sqlite

Convert an Apple Healthkit export zip to a SQLite database
https://datasette.io/tools/healthkit-to-sqlite
Apache License 2.0
191 stars 9 forks source link

Use XML Analyser to figure out the structure of the export XML #1

Closed simonw closed 4 years ago

simonw commented 4 years ago

https://github.com/simonw/xml_analyser

simonw commented 4 years ago

I ran xml_analyser against the XML HealthKit export.xml file and got the following results:

{
  'ActivitySummary': {'attr_counts': {'activeEnergyBurned': 980,
                                     'activeEnergyBurnedGoal': 980,
                                     'activeEnergyBurnedUnit': 980,
                                     'appleExerciseTime': 980,
                                     'appleExerciseTimeGoal': 980,
                                     'appleStandHours': 980,
                                     'appleStandHoursGoal': 980,
                                     'dateComponents': 980},
                     'child_counts': {},
                     'count': 980,
                     'parent_counts': {'HealthData': 980}},
 'Correlation': {'attr_counts': {'creationDate': 1,
                                 'endDate': 1,
                                 'sourceName': 1,
                                 'sourceVersion': 1,
                                 'startDate': 1,
                                 'type': 1},
                 'child_counts': {'MetadataEntry': 1, 'Record': 2},
                 'count': 1,
                 'parent_counts': {'HealthData': 1}},
 'ExportDate': {'attr_counts': {'value': 1},
                'child_counts': {},
                'count': 1,
                'parent_counts': {'HealthData': 1}},
 'HealthData': {'attr_counts': {'locale': 1},
                'child_counts': {'ActivitySummary': 980,
                                 'Correlation': 1,
                                 'ExportDate': 1,
                                 'Me': 1,
                                 'Record': 2672231,
                                 'Workout': 663},
                'count': 1,
                'parent_counts': {}},
 'HeartRateVariabilityMetadataList': {'attr_counts': {},
                                      'child_counts': {'InstantaneousBeatsPerMinute': 93653},
                                      'count': 2318,
                                      'parent_counts': {'Record': 2318}},
 'InstantaneousBeatsPerMinute': {'attr_counts': {'bpm': 93653, 'time': 93653},
                                 'child_counts': {},
                                 'count': 93653,
                                 'parent_counts': {'HeartRateVariabilityMetadataList': 93653}},
 'Location': {'attr_counts': {'altitude': 398683,
                              'course': 398683,
                              'date': 398683,
                              'horizontalAccuracy': 398683,
                              'latitude': 398683,
                              'longitude': 398683,
                              'speed': 398683,
                              'verticalAccuracy': 398683},
              'child_counts': {},
              'count': 398683,
              'parent_counts': {'WorkoutRoute': 398683}},
 'Me': {'attr_counts': {'HKCharacteristicTypeIdentifierBiologicalSex': 1,
                        'HKCharacteristicTypeIdentifierBloodType': 1,
                        'HKCharacteristicTypeIdentifierDateOfBirth': 1,
                        'HKCharacteristicTypeIdentifierFitzpatrickSkinType': 1},
        'child_counts': {},
        'count': 1,
        'parent_counts': {'HealthData': 1}},
 'MetadataEntry': {'attr_counts': {'key': 290449, 'value': 290449},
                   'child_counts': {},
                   'count': 290449,
                   'parent_counts': {'Correlation': 1,
                                     'Record': 287974,
                                     'Workout': 1928,
                                     'WorkoutRoute': 546}},
 'Record': {'attr_counts': {'creationDate': 2672233,
                            'device': 2665111,
                            'endDate': 2672233,
                            'sourceName': 2672233,
                            'sourceVersion': 2671779,
                            'startDate': 2672233,
                            'type': 2672233,
                            'unit': 2650012,
                            'value': 2672232},
            'child_counts': {'HeartRateVariabilityMetadataList': 2318,
                             'MetadataEntry': 287974},
            'count': 2672233,
            'parent_counts': {'Correlation': 2, 'HealthData': 2672231}},
 'Workout': {'attr_counts': {'creationDate': 663,
                             'device': 230,
                             'duration': 663,
                             'durationUnit': 663,
                             'endDate': 663,
                             'sourceName': 663,
                             'sourceVersion': 663,
                             'startDate': 663,
                             'totalDistance': 663,
                             'totalDistanceUnit': 663,
                             'totalEnergyBurned': 663,
                             'totalEnergyBurnedUnit': 663,
                             'workoutActivityType': 663},
             'child_counts': {'MetadataEntry': 1928,
                              'WorkoutEvent': 2094,
                              'WorkoutRoute': 340},
             'count': 663,
             'parent_counts': {'HealthData': 663}},
 'WorkoutEvent': {'attr_counts': {'date': 2094,
                                  'duration': 837,
                                  'durationUnit': 837,
                                  'type': 2094},
                  'child_counts': {},
                  'count': 2094,
                  'parent_counts': {'Workout': 2094}},
 'WorkoutRoute': {'attr_counts': {'creationDate': 340,
                                  'endDate': 340,
                                  'sourceName': 340,
                                  'sourceVersion': 340,
                                  'startDate': 340},
                  'child_counts': {'Location': 398683, 'MetadataEntry': 546},
                  'count': 340,
                  'parent_counts': {'Workout': 340}}}

The most interesting bit is this:

 'HealthData': {'attr_counts': {'locale': 1},
                'child_counts': {'ActivitySummary': 980,
                                 'Correlation': 1,
                                 'ExportDate': 1,
                                 'Me': 1,
                                 'Record': 2672231,
                                 'Workout': 663},