diff --git a/backend/app/activities/utils.py b/backend/app/activities/utils.py index 099264ee..75a10d42 100644 --- a/backend/app/activities/utils.py +++ b/backend/app/activities/utils.py @@ -562,7 +562,7 @@ def define_activity_type(activity_type): # "Yoga" # Get the activity type from the mapping - auxType = type_mapping.get(str(activity_type), 10) + auxType = type_mapping.get(activity_type, 10) # Return the activity type return auxType diff --git a/backend/app/gpx/utils.py b/backend/app/gpx/utils.py index 9629100a..6ae44cde 100644 --- a/backend/app/gpx/utils.py +++ b/backend/app/gpx/utils.py @@ -242,7 +242,7 @@ def parse_gpx_file(file: str, user_id: int) -> dict: activity = activities_schema.Activity( user_id=user_id, name=activity_name, - distance=round(distance) if distance else None, + distance=round(distance) if distance else 0, activity_type=activity_type, start_time=first_waypoint_time.strftime("%Y-%m-%dT%H:%M:%S"), end_time=last_waypoint_time.strftime("%Y-%m-%dT%H:%M:%S"), diff --git a/backend/app/strava/activity_utils.py b/backend/app/strava/activity_utils.py index 36459519..9314aabd 100644 --- a/backend/app/strava/activity_utils.py +++ b/backend/app/strava/activity_utils.py @@ -243,9 +243,11 @@ def parse_activity( activity_to_store = activities_schema.Activity( user_id=user_id, name=detailedActivity.name, - distance=round(detailedActivity.distance), + distance=round(detailedActivity.distance) if avg_hr else 0, description=detailedActivity.description, - activity_type=activities_utils.define_activity_type(detailedActivity.sport_type), + activity_type=activities_utils.define_activity_type( + str(detailedActivity.sport_type) + ), start_time=start_date_parsed.strftime("%Y-%m-%dT%H:%M:%S"), end_time=end_date_parsed.strftime("%Y-%m-%dT%H:%M:%S"), total_elapsed_time=total_elapsed_time, @@ -253,17 +255,17 @@ def parse_activity( city=city, town=town, country=country, - elevation_gain=ele_gain, - elevation_loss=ele_loss, + elevation_gain=round(ele_gain) if ele_gain else None, + elevation_loss=round(ele_loss) if ele_loss else None, pace=average_pace, average_speed=avg_speed, max_speed=max_speed, - average_power=avg_power, + average_power=round(avg_power) if avg_power else None, max_power=max_power, - normalized_power=np, - average_hr=avg_hr, + normalized_power=round(np) if np else None, + average_hr=round(avg_hr) if avg_hr else None, max_hr=max_hr, - average_cad=avg_cadence, + average_cad=round(avg_cadence) if avg_cadence else None, max_cad=max_cadence, calories=round(detailedActivity.calories), gear_id=gear_id,