API - fix new sports addition

- add data migration and fix data init for new instances
- update and fix tests
This commit is contained in:
Sam
2021-09-01 14:05:45 +02:00
parent 69467d8a6b
commit 1881165b57
7 changed files with 197 additions and 53 deletions

View File

@ -77,12 +77,14 @@ def get_workouts(
workouts_list_by_sport[sport_id][
'total_duration'
] += convert_timedelta_to_integer(workout.moving)
workouts_list_by_sport[sport_id]['total_ascent'] += float(
workout.ascent
)
workouts_list_by_sport[sport_id]['total_descent'] += float(
workout.descent
)
if workout.ascent:
workouts_list_by_sport[sport_id]['total_ascent'] += float(
workout.ascent
)
if workout.descent:
workouts_list_by_sport[sport_id]['total_descent'] += float(
workout.descent
)
# filter_type == 'by_time'
else:
@ -133,11 +135,11 @@ def get_workouts(
if workout.ascent:
workouts_list_by_time[time_period][sport_id][
'total_ascent'
] += float(workout.ascent / 1000)
] += float(workout.ascent)
if workout.descent:
workouts_list_by_time[time_period][sport_id][
'total_descent'
] += float(workout.descent / 1000)
] += float(workout.descent)
return {
'status': 'success',
'data': {
@ -188,6 +190,8 @@ def get_workouts_by_time(
"2017": {
"3": {
"nb_workouts": 2,
"total_ascent": 203.0,
"total_ascent": 156.0,
"total_distance": 15.282,
"total_duration": 12341
}
@ -195,11 +199,15 @@ def get_workouts_by_time(
"2019": {
"1": {
"nb_workouts": 3,
"total_ascent": 150.0,
"total_ascent": 178.0,
"total_distance": 47,
"total_duration": 9960
},
"2": {
"nb_workouts": 1,
"total_ascent": 46.0,
"total_ascent": 78.0,
"total_distance": 5.613,
"total_duration": 1267
}
@ -285,16 +293,22 @@ def get_workouts_by_sport(
"statistics": {
"1": {
"nb_workouts": 3,
"total_ascent": 150.0,
"total_ascent": 178.0,
"total_distance": 47,
"total_duration": 9960
},
"2": {
"nb_workouts": 1,
"total_ascent": 46.0,
"total_ascent": 78.0,
"total_distance": 5.613,
"total_duration": 1267
},
"3": {
"nb_workouts": 2,
"total_ascent": 203.0,
"total_ascent": 156.0,
"total_distance": 15.282,
"total_duration": 12341
}