4 releases
0.0.4 | Dec 31, 2022 |
---|---|
0.0.3 | Dec 31, 2022 |
0.0.2 | Dec 31, 2022 |
0.0.1 | Dec 31, 2022 |
#510 in Visualization
340KB
756 lines
healthkit-to-sqlite
Command-line tool to convert Apple HealthKit data to a SQLite database.
Getting Started
- Open the Health app on your iOS device.
- Click your profile icon in the top-right corner.
- Click the "Export All Health Data" button.
- Share the resulting ZIP archive to your computer.
- Run the healthkit-to-sqlite tool on the exported ZIP archive.
cargo install healthkit-to-sqlite-cli
healthkit-to-sqlite export.zip sqlite://healthkit.db
Datasette
You can use https://datasette.io/ to view and explore the resulting SQLite database file. Install the https://datasette.io/plugins/datasette-geojson-map plugin to visualize the workout routes data on a map.
datasette install datasette-geojson-map
datasette healthkit.db
Decisions
- Only the
Record
,Workout
, andActivitySummary
elements are currently exported. Record
elements are inserted to a table with a name matching the value of the element'stype
attribute.Workout
elements are inserted to a table named "Workout".- The descendent
workoutEvent
andworkoutStatistics
elements are represented as JSON columns. - The descendent
workoutRoute
element is converted to a GeoJSON LineString and stored in a JSON column named "geometry" for easy integration with https://datasette.io/plugins/datasette-geojson-map. - The JSON columns can be verbose and result in large HTML table cell sizes, making it difficult to browse the results. In this case, it may be useful to specify the truncate_cells_html setting
datasette healthkit.db --setting truncate_cells_html 40
. Note that this setting does not appear to be compatible with the datasette-pretty-json plugin.
- The descendent
ActivitySummary
elements are inserted as rows to a table named "ActivitySummary".- In an attempt to future proof against Apple adding, removing, or changing element attributes, the code only assumes the existence of a limited number of attributes:
Record
elements must have atype
attribute.Workout
elements must have aworkoutActivity
attribute.MetadataEntry
elements must havekey
andvalue
attributes.FileReference
elements must have apath
attribute.
Dependencies
~58MB
~1M SLoC