Skip to content

Commit

Permalink
Additional validations on Strava activity creation
Browse files Browse the repository at this point in the history
[backend] added additional validations to ensure int values are used instead of float on Strava activity creation
  • Loading branch information
joaovitoriasilva committed Nov 7, 2024
1 parent 298c80f commit 26338d6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion backend/app/activities/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion backend/app/gpx/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
18 changes: 10 additions & 8 deletions backend/app/strava/activity_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,27 +243,29 @@ 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,
total_timer_time=total_timer_time,
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,
Expand Down

0 comments on commit 26338d6

Please sign in to comment.