patrickloeber / patricks-workouts

Displays my Apple Health data in a Steamlit App.
https://patloeber.com/workouts
11 stars 1 forks source link

Pre-processing error #1

Open rokesby opened 3 months ago

rokesby commented 3 months ago

(patricks_venv) ➜ patricks-workouts git:(main) ✗ python workout_preprocessor.py Do workout preprocessing...

Traceback (most recent call last): File "/Users/reza/Code/patricks-workouts/patricks_venv/lib/python3.12/site-packages/pandas/core/indexes/base.py", line 3805, in get_loc return self._engine.get_loc(casted_key) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "index.pyx", line 167, in pandas._libs.index.IndexEngine.get_loc File "index.pyx", line 196, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/hashtable_class_helper.pxi", line 7081, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas/_libs/hashtable_class_helper.pxi", line 7089, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'totalEnergyBurned'

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/Users/reza/Code/patricks-workouts/workout_preprocessor.py", line 87, in create_and_save_optimized_file("./workouts.pickle", "./temp/apple_health_export/Export.xml") File "/Users/reza/Code/patricks-workouts/workout_preprocessor.py", line 62, in create_and_save_optimized_file workout_data['totalEnergyBurned'] = pd.to_numeric(workout_data['totalEnergyBurned'])


  File "/Users/reza/Code/patricks-workouts/patricks_venv/lib/python3.12/site-packages/pandas/core/frame.py", line 4102, in __getitem__
    indexer = self.columns.get_loc(key)
              ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/reza/Code/patricks-workouts/patricks_venv/lib/python3.12/site-packages/pandas/core/indexes/base.py", line 3812, in get_loc
    raise KeyError(key) from err
KeyError: 'totalEnergyBurned'
rokesby commented 3 months ago

If you comment out, the pre-processor does run but the Stream visualisation fails as it is expecting these values.

   workout_data['duration'] = pd.to_numeric(workout_data['duration'])
    # workout_data['totalEnergyBurned'] = pd.to_numeric(workout_data['totalEnergyBurned'])
    # workout_data['totalDistance'] = pd.to_numeric(workout_data['totalDistance'])

These attributes might not be present in the latest export.xml files due to deprecation:

  1. https://developer.apple.com/documentation/healthkit/hkworkout/1615491-totalenergyburned
  2. https://developer.apple.com/documentation/healthkit/hkworkout/1615756-totaldistance

We may need to get these attributes using a more up to date method.