From dd76d01e3d948bf5cac468c30291c5c7b3ed21aa Mon Sep 17 00:00:00 2001 From: Peter Stockings Date: Sat, 11 Mar 2023 21:51:33 +1100 Subject: [PATCH] Using rpm->speed/power functions display distance, calories, speed and power (Not yet sending to backend,, need to confirm this is working first) --- templates/new_workout.html | 600 +++++++++++++++++++++---------------- 1 file changed, 341 insertions(+), 259 deletions(-) diff --git a/templates/new_workout.html b/templates/new_workout.html index b96e993..40fda74 100644 --- a/templates/new_workout.html +++ b/templates/new_workout.html @@ -5,304 +5,386 @@ Exercise Bike Display + - - -
-
-
-
-

RPM

-

0

-
-
-

Duration

-

00:00

-
-
-
- -
-
+ - - - + + + // Calculate the time difference between the start and end dates in milliseconds + const timeDiffMs = endDate.getTime() - startDate.getTime(); + + // Calculate the distance traveled based on speed and time difference + const distance = speedPerMs * timeDiffMs; + + return distance; + } + + function calculateCalories(startDate, endDate, power) { + // Calculate the time difference between the start and end dates in seconds + const timeDiffSec = (endDate.getTime() - startDate.getTime()) / 1000; + + // Calculate the energy(joules) expended based on power and time difference + const energy = powerPerSec * timeDiffSec; + + //Convert joules to calories + return energy * 0.238902957619; + } + +