Created
November 9, 2018 12:55
-
-
Save aldipower/13a563a2aa163eaffcb5f254be3a4349 to your computer and use it in GitHub Desktop.
Prints a cadence table for pace-'body height'-relations to gain optimal hip extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/node | |
const bodyHeightCmArg = process.argv[2]; | |
const paceArg = process.argv[3]; | |
function printUsage() { | |
console.log(`Cadence calculator - Print cadence for specific paces and body height to gain optimal hip extension | |
Usage: | |
./cadence.js bodyHeightInCm [paceMinKm] | |
Example: | |
./cadence.js 177 | |
./cadence.js 177 4:00`); | |
process.exit(); | |
} | |
function calcCadence(speedKmh, bodyHeightCm) { | |
return Math.ceil(160 + (speedKmh - 6) * 2.5 - (bodyHeightCm - 170) / 2); | |
} | |
function speedToPace(speedKmh) { | |
const pace = 60 / speedKmh; | |
const minuten = Math.floor(pace); | |
const sekunden = Math.floor((pace - minuten) * 60).toString(); | |
return `${minuten.toString().padStart(2, '0')}:${sekunden.padStart(2, '0')}`; | |
} | |
function paceToSpeed(paceString) { | |
const [minutes, seconds] = paceString.split(':'); | |
if (minutes == null || seconds == null) { | |
throw new Error(`Incorrect pace argument: ${paceString}`); | |
} | |
return 60 / (parseInt(minutes, 10) + parseInt(seconds, 10) / 60); | |
} | |
if (bodyHeightCmArg == null) { | |
printUsage(); | |
} | |
if (paceArg != null) { | |
try { | |
paceToSpeed(paceArg); | |
} catch (error) { | |
console.log(error); | |
printUsage(); | |
} | |
} | |
const bodyHeight = parseInt(bodyHeightCmArg, 10); | |
console.log(`Pace Cadence Body height: ${bodyHeight}cm`); | |
if (paceArg != null) { | |
console.log(`${speedToPace(paceToSpeed(paceArg))} ${calcCadence(paceToSpeed(paceArg), bodyHeight)}`); | |
} else { | |
for (let speed = 7; speed <= 23; speed += 0.4) { | |
console.log(`${speedToPace(speed)} ${calcCadence(speed, bodyHeight)}`); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment