I have a value given in metres per second (mps) retrieved from the Strava API and I want to convert this minutes per kilometre (pace). On the surface this seems simple, off the top of my head I came up with the following:
const metresPerSecond = 3.358;
var metresPerMinute = metresPerSecond*60;
var minutesPerKm = 1000/metresPerMinute;
console.log(minutesPerKm); // 4.96
I've also tried doing it by using the time & distance values like so:
const timeInSeconds = 1203;
const distanceInMetres = 4040;
var pace = (timeInSeconds/distanceInMetres)/60*1000;
console.log(pace); // 4.96
Initially I assumed this was correct but on looking at the pace value in Strava for this activity the value is 4.58
. I thought this could be because they are doing something clever with their data such as removing stationary sections etc, but I input the time/distance values into this site here and it gave me the same 4.58
value so there is clearly another way of doing this that I'm not understanding.
Anybody any idea what I'm doing wrong?
You're doing it entirely correct. The only thing you're missing is that you should convert the 'leftover' minutes from decimal minutes to seconds.
const timeInSeconds = 1203;
const distanceInMetres = 4040;
var pace = (timeInSeconds/distanceInMetres)/60*1000;
var leftover = pace % 1;
var minutes = pace - leftover;
var seconds = Math.round(leftover * 60);
console.log(minutes+":"+seconds)
Results in 4:58