Open morteako opened 1 month ago
When inputing watts in the editor, the resulting watts in the workout can differ by 1, because of flooring/rounding issues. This is fixed by rounding the wattFromFtpPct-calculation instead of flooring
Example FTP: 280, input 279 ftpPct = Math.floor(1000 * (279 / 280)) / 10; ftPct = 99.6
result in editor: 279, 99.6%
when we then calculate in the workout: Math.floor((ftpPct * ftp) / 100) = Math.floor((27888 / 100) = 278;
Based on my tests, changing the floor in the wattFromFtpPct to round, should fix this. Since
wattFromFtpPct
let failures = []; for (let ftp = 1; ftp <= 500; ftp += 1) { for (let watt = 0; watt <= 1000; watt += 1) { const ftpPct = Math.floor(1000 * (watt / ftp)) / 10; const wattFromFtpPct = Math.floor((ftpPct * ftp) / 100); if (wattFromFtpPct !== watt) { failures.push({ watt, exactWattFromFtpPct: (ftpPct * ftp) / 100, ftpPct, ftp, }); } } } console.log(failures);
=> Lots of issues
let failures = []; for (let ftp = 1; ftp <= 500; ftp += 1) { for (let watt = 0; watt <= 1000; watt += 1) { const ftpPct = Math.floor(1000 * (watt / ftp)) / 10; const wattFromFtpPct = Math.round((ftpPct * ftp) / 100); if (wattFromFtpPct !== watt) { failures.push({ watt, exactWattFromFtpPct: (ftpPct * ftp) / 100, ftpPct, ftp, }); } } } console.log(failures);
=> All watts are correct
When inputing watts in the editor, the resulting watts in the workout can differ by 1, because of flooring/rounding issues. This is fixed by rounding the wattFromFtpPct-calculation instead of flooring
Example FTP: 280, input 279 ftpPct = Math.floor(1000 * (279 / 280)) / 10; ftPct = 99.6
result in editor: 279, 99.6%
when we then calculate in the workout: Math.floor((ftpPct * ftp) / 100) = Math.floor((27888 / 100) = 278;
Based on my tests, changing the floor in the
wattFromFtpPct
to round, should fix this. SinceGif of error in action : 279 => 278
Testing
Testing code old version
=> Lots of issues
Testing code for new version
=> All watts are correct