From 8fa5d685cf7fc1fdef9883f0df956f01095b042f Mon Sep 17 00:00:00 2001 From: Fmstrat Date: Tue, 22 Mar 2022 13:29:53 -0400 Subject: [PATCH] Added total elevation to dashboard --- fittrackee/users/models.py | 3 ++- .../Dashboard/UserStatsCards/index.vue | 24 ++++++++++++++----- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/fittrackee/users/models.py b/fittrackee/users/models.py index 5e4176e3..23af9798 100644 --- a/fittrackee/users/models.py +++ b/fittrackee/users/models.py @@ -120,7 +120,7 @@ class User(BaseModel): ) total = ( db.session.query( - func.sum(Workout.distance), func.sum(Workout.duration) + func.sum(Workout.distance), func.sum(Workout.duration), func.sum(Workout.ascent) ) .filter(Workout.user_id == self.id) .first() @@ -147,6 +147,7 @@ class User(BaseModel): ], 'total_distance': float(total[0]), 'total_duration': str(total[1]), + 'total_ascent': str(total[2]), 'imperial_units': self.imperial_units, } diff --git a/fittrackee_client/src/components/Dashboard/UserStatsCards/index.vue b/fittrackee_client/src/components/Dashboard/UserStatsCards/index.vue index ed14e004..144687c1 100644 --- a/fittrackee_client/src/components/Dashboard/UserStatsCards/index.vue +++ b/fittrackee_client/src/components/Dashboard/UserStatsCards/index.vue @@ -8,7 +8,12 @@ + props.user.total_duration ) const totalDuration = computed(() => get_duration(userTotalDuration)) - const defaultUnitFrom: TUnit = 'km' - const unitTo: TUnit = user.value.imperial_units - ? units[defaultUnitFrom].defaultTarget - : defaultUnitFrom + const distanceUnitFrom: TUnit = 'km' + const distanceUnitTo: TUnit = user.value.imperial_units + ? units[distanceUnitFrom].defaultTarget + : distanceUnitFrom const totalDistance = user.value.imperial_units - ? convertDistance(user.value.total_distance, defaultUnitFrom, unitTo, 2) + ? convertDistance(user.value.total_distance, distanceUnitFrom, distanceUnitTo, 2) : parseFloat(user.value.total_distance.toFixed(2)) + const ascentUnitFrom: TUnit = 'm' + const ascentUnitTo: TUnit = user.value.imperial_units + ? units[ascentUnitFrom].defaultTarget + : ascentUnitFrom + const totalAscent = user.value.imperial_units + ? convertDistance(user.value.total_ascent, ascentUnitFrom, ascentUnitTo, 2) + : parseFloat(user.value.total_ascent.toFixed(2)) function get_duration(total_duration: ComputedRef) { const duration = total_duration.value.match(/day/g)