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

No more VO2_max in steps_activities table since 2024-05-23 #236

Open
lpierron opened this issue Jul 1, 2024 · 2 comments
Open

No more VO2_max in steps_activities table since 2024-05-23 #236

lpierron opened this issue Jul 1, 2024 · 2 comments

Comments

@lpierron
Copy link

lpierron commented Jul 1, 2024

No more VO2_max in steps_activities table since 2024-05-23

Open garmin_activities database with sqlite3.

Log example:

sqlite> select strftime("%Y-%m-%d", start_time) AS day, sport, VO2_Max  from steps_activities JOIN activities ON activities.activity_id = steps_activities.activity_id where start_time > '2024-05-01' ORDER BY start_time DESC;
2024-06-26|running|
2024-06-25|running|
2024-06-22|walking|
2024-06-22|walking|
2024-06-21|running|
2024-06-19|running|
2024-06-17|running|
2024-06-14|running|
2024-06-12|running|
2024-06-11|running|
2024-06-09|walking|
2024-06-09|walking|
2024-06-07|running|
2024-06-05|running|
2024-06-03|running|
2024-05-29|running|
2024-05-28|running|
2024-05-27|running|
2024-05-25|walking|
2024-05-24|running|
2024-05-24|walking|
2024-05-24|running|
2024-05-23|running|
2024-05-22|running|38.0
2024-05-17|running|38.0
2024-05-16|running|38.0
2024-05-14|running|38.0
2024-05-13|running|38.0
2024-05-13|running|
2024-05-06|running|38.0
2024-05-03|running|38.0
2024-05-02|running|38.0
2024-05-01|walking|

You can see that all running and walking activities since 2024-05-23 have no VO2_Max data.

@lpierron
Copy link
Author

lpierron commented Aug 1, 2024

To help, I wrote a little program to get the VO2Max on my Garmin Connect account with garth:
vo2max.py.zip

Partial result of running VO2max.py:

-------------------- api.get_max_metrics('2024-07-31') --------------------
[
    {
        "userId": 50448457,
        "generic": {
            "calendarDate": "2024-07-31",
            "vo2MaxPreciseValue": 38.0,
            "vo2MaxValue": 38.0,
            "fitnessAge": 52,
            "fitnessAgeDescription": null,
            "maxMetCategory": 0
        },
        "cycling": null,
        "heatAltitudeAcclimation": null
    }
]
---------------------------------------------------------------------------
-------------------- api.get_max_metrics('2024-08-01') --------------------
[]

@lpierron
Copy link
Author

lpierron commented Sep 6, 2024

I found the problem and solution.

Since May 2024, Garmin JSON activity files do not export some fields with a null value like avgVerticalOscillation.

So in this program, the variable avg_vertical_oscillation is set to None and an exception occurs at line #119:

def _process_steps_activity(self, activity_id, activity_summary):
root_logger.debug("process_steps_activity for %s", activity_id)
avg_vertical_oscillation = self._get_field_obj(activity_summary, 'avgVerticalOscillation', fitfile.Distance.from_meters)
avg_step_length = self._get_field_obj(activity_summary, 'avgStrideLength', fitfile.Distance.from_meters)
run = {
'activity_id' : activity_id,
'steps' : self._get_field(activity_summary, 'steps', float),
'avg_steps_per_min' : self._get_field(activity_summary, 'averageRunningCadenceInStepsPerMinute', float),
'max_steps_per_min' : self._get_field(activity_summary, 'maxRunningCadenceInStepsPerMinute', float),
'avg_step_length' : avg_step_length.meters_or_feet(self.measurement_system),
'avg_gct_balance' : self._get_field(activity_summary, 'avgGroundContactBalance', float),
'avg_vertical_oscillation' : avg_vertical_oscillation.meters_or_feet(self.measurement_system),
'avg_ground_contact_time' : fitfile.conversions.ms_to_dt_time(self._get_field(activity_summary, 'avgGroundContactTime', float)),
'vo2_max' : self._get_field(activity_summary, 'vO2MaxValue', float),
}
StepsActivities.s_insert_or_update(self.garmin_act_db_session, run, ignore_none=True)

So I suggest to modify _get_field_obj in idbutils/json_file_processor.py:
https://github.com/tcgoetz/utilities/blob/5ce3f712f34818cddf5327cd827a480989ff6940/idbutils/json_file_processor.py#L79-L84

and replacing by:

    def _get_field_obj(self, json, fieldname, format_func):
        try:
            data = json[fieldname]
            return format_func(data)
        except KeyError as e:
            self.logger.debug("JSON %s not found in %r, setting to `0`: %s", fieldname, json, e)
        return format_func(0)

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

No branches or pull requests

1 participant