Add a javascript version of the prediction example.
This commit is contained in:
parent
a5c94a9230
commit
61a93c6345
|
|
@ -1,6 +1,9 @@
|
|||
# Wattage predictions
|
||||
|
||||
See [concept2_predictions.py](concept2_predictions.py)
|
||||
See:
|
||||
|
||||
* [concept2_predictions.py](concept2_predictions.py)
|
||||
* [concept2_predictions.js](concept2_predictions.js)
|
||||
|
||||
## Zones
|
||||
|
||||
|
|
@ -49,4 +52,3 @@ UT2 power range is 15% (60% minus 45%)
|
|||
so 132 bmp should be 4 fifths into that 15% = 12%
|
||||
|
||||
so expected power is 110W/(45%+12%) = 193W
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,63 @@
|
|||
function calculateWattage(restingHeartRate, maximumHeartRate, heartRate, basePowerOutput) {
|
||||
function getZonePercentile(heartRate, restingHeartRate, maximumHeartRate) {
|
||||
const HRR = maximumHeartRate - restingHeartRate;
|
||||
const zonePercentage = ((heartRate - restingHeartRate) / HRR) * 100;
|
||||
return Math.round(zonePercentage * 100) / 100;
|
||||
}
|
||||
|
||||
function getHrrRange(zone) {
|
||||
if (zone <= 65) return [0, 65];
|
||||
else if (zone <= 70) return [65, 70];
|
||||
else if (zone <= 80) return [70, 80];
|
||||
else if (zone <= 85) return [80, 85];
|
||||
else if (zone <= 95) return [85, 95];
|
||||
else return [95, 100];
|
||||
}
|
||||
|
||||
function getPowerRange(zone) {
|
||||
if (zone <= 65) return [0, 45];
|
||||
else if (zone <= 70) return [45, 60];
|
||||
else if (zone <= 80) return [60, 70];
|
||||
else if (zone <= 85) return [70, 80];
|
||||
else if (zone <= 95) return [80, 105];
|
||||
else return [105, 115];
|
||||
}
|
||||
|
||||
const zonePercentage = getZonePercentile(heartRate, restingHeartRate, maximumHeartRate);
|
||||
console.log("Zone:", zonePercentage);
|
||||
|
||||
const minPower = getPowerRange(zonePercentage)[0];
|
||||
const maxPower = getPowerRange(zonePercentage)[1];
|
||||
|
||||
const [minHrr, maxHrr] = getHrrRange(zonePercentage);
|
||||
console.log("Min HRR:", minHrr);
|
||||
console.log("Max HRR:", maxHrr);
|
||||
|
||||
const powerRange = maxPower - minPower;
|
||||
console.log("Power range:", powerRange);
|
||||
|
||||
const hrrRange = maxHrr - minHrr;
|
||||
console.log("HRR range:", hrrRange);
|
||||
console.log("Zone minus min HRR:", zonePercentage - minHrr);
|
||||
|
||||
const hrrPercentage = (zonePercentage - minHrr) / hrrRange;
|
||||
console.log("HRR percentage:", hrrPercentage);
|
||||
|
||||
const powerPercentage = (minPower + hrrPercentage * powerRange) / 100;
|
||||
console.log("Power percentage:", powerPercentage);
|
||||
|
||||
// Calculate predicted power
|
||||
const predictedPower = basePowerOutput / powerPercentage;
|
||||
|
||||
return Math.round(predictedPower);
|
||||
}
|
||||
|
||||
// Example usage
|
||||
const restingHeartRate = 58;
|
||||
const maximumHeartRate = 165;
|
||||
const heartRate = 132;
|
||||
const basePowerOutput = 110;
|
||||
|
||||
const watts = calculateWattage(restingHeartRate, maximumHeartRate, heartRate, basePowerOutput);
|
||||
console.log(`Predicted power: ${watts} watts`);
|
||||
|
||||
Loading…
Reference in New Issue