Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some workout columns should be float, not text #12

Open
simonw opened this issue Oct 23, 2020 · 4 comments
Open

Some workout columns should be float, not text #12

simonw opened this issue Oct 23, 2020 · 4 comments
Labels
enhancement New feature or request

Comments

@simonw
Copy link
Collaborator

simonw commented Oct 23, 2020

Columns duration, totalDistance and totalEnergyBurned should be converted to float.

def workout_to_db(workout, db, zipfile=None):
record = dict(workout.attrib)
# add metadata entry items as extra keys
for el in workout.findall("MetadataEntry"):
record["metadata_" + el.attrib["key"]] = el.attrib["value"]
# Dump any WorkoutEvent in a nested list for the moment
record["workout_events"] = [el.attrib for el in workout.findall("WorkoutEvent")]
pk = db["workouts"].insert(record, alter=True, hash_id="id").last_pk

@simonw simonw added the enhancement New feature or request label Oct 23, 2020
@Mjboothaus
Copy link

Hi Simon -- just experimenting with your excellent software!

Up to this point in time I have been using the (paid) HealthFit App to export my workouts from my Apple Watch, one walk at the time into either .GPX or .FIT format and then using another library to suck it into Python and eventually here to my "Emmaus Walking" app:

https://share.streamlit.io/mjboothaus/emmaus_walking/emmaus_walking/app.py

I just used healthkit-to-sqlite to convert my export.zip file and it all "just worked".

I did notice the issue with various numeric fields being stored in the SQLite db as TEXT for now and just thought I'd flag it - but you're already self-reported this issue.

Keep up the great work!

I was curious if you have any thoughts about periodically exporting "export.zip" and how to just update the SQLite file instead of re-creating it each time. Hopefully Apple will give some thought to managing this data in a more sensible fashion as it grows over time. Ideally one could pull it from iCloud (where it is allegedly being backed up).

@Mjboothaus
Copy link

P.s. wondering if you have explored using the spatialite functionality with the location data in workouts?

@simonw
Copy link
Collaborator Author

simonw commented Jul 13, 2021

Unfortunately I don't think updating the database is practical, because the export doesn't include unique identifiers which can be used to update existing records and create new ones. Recreating from scratch works around that limitation.

I've not explored workouts with SpatiaLite but that's a really good idea.

@Mjboothaus
Copy link

In terms of unique identifiers - could you use values stored in HKMetadataKeySyncIdentifier?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants