diff --git a/backend/app/activities/activity_streams/crud.py b/backend/app/activities/activity_streams/crud.py index fb468bc5c..20597eda3 100644 --- a/backend/app/activities/activity_streams/crud.py +++ b/backend/app/activities/activity_streams/crud.py @@ -369,7 +369,7 @@ def transform_activity_streams_hr(activity_stream, activity, db): activity: The activity object associated with the stream, used to retrieve the user ID. db: The database session or connection used to fetch user details. Returns: - The activity stream object with an added 'hr_zone_percentages' attribute, which contains the percentage of time spent in each heart rate zone and their respective HR boundaries. If waypoints or user details are missing, returns the original activity stream unchanged. + The activity stream object with an added 'hr_zone_percentages' attribute, which contains the percentage of time spent in each heart rate zone and their respective HR boundaries. If waypoi[...] Notes: - Heart rate zones are calculated using the formula: max_heart_rate = 220 - age. - The function expects waypoints to be a list of dicts with an "hr" key. @@ -429,7 +429,11 @@ def transform_activity_streams_hr(activity_stream, activity, db): # Calculate time in seconds for each zone using the percentage # of total_timer_time - if hasattr(activity, "total_timer_time") and activity.total_timer_time: + has_timer_time = ( + hasattr(activity, "total_timer_time") + and activity.total_timer_time + ) + if has_timer_time: total_time_seconds = activity.total_timer_time zone_time_seconds = [ int((percent / 100) * total_time_seconds)