Round all numbers in stats using roundDigits

This commit is contained in:
Matt McWilliams 2024-10-20 08:53:25 -04:00
parent cc2b41527a
commit e094372308
4 changed files with 45 additions and 43 deletions

View File

@ -272,29 +272,29 @@ class Client {
private setStatistics (stats : SequenceStatistics) { private setStatistics (stats : SequenceStatistics) {
if (stats !== null) { if (stats !== null) {
this.set('statsFrameTotalAvg', this.roundDigits(stats.totalFrameAvg, 2).toString()); this.set('statsFrameTotalLast', this.roundDigits(stats.totalFrameLast, 0));
this.set('statsFrameTotalLast', Math.round(stats.totalFrameLast).toString()); this.set('statsFrameTotalAvg', this.roundDigits(stats.totalFrameAvg, 2));
this.set('statsFrameTotalMargin', Math.round(stats.totalFrameMargin).toString()); this.set('statsFrameTotalMargin', this.roundDigits(stats.totalFrameMargin, 1));
this.set('statsFPS', this.roundDigits(stats.fps, 2).toString()); this.set('statsFPS', this.roundDigits(stats.fps, 2));
this.set('statsFrameLoadAvg', this.roundDigits(stats.loadAvg, 2).toString()); this.set('statsFrameLoadAvg', this.roundDigits(stats.loadAvg, 2));
this.set('statsFrameLoadMargin', Math.round(stats.loadMargin).toString()); this.set('statsFrameLoadMargin', this.roundDigits(stats.loadMargin, 1));
this.set('statsFrameOpenLast', Math.round(stats.openLast).toString()); this.set('statsFrameOpenLast', this.roundDigits(stats.openLast, 0));
this.set('statsFrameOpenAvg', this.roundDigits(stats.openAvg, 2).toString()); this.set('statsFrameOpenAvg', this.roundDigits(stats.openAvg, 2));
this.set('statsFrameOpenMargin', Math.round(stats.openMargin).toString()); this.set('statsFrameOpenMargin', this.roundDigits(stats.openMargin, 1));
this.set('statsFrameCloseLast', Math.round(stats.closeLast).toString()); this.set('statsFrameCloseLast', this.roundDigits(stats.closeLast, 0));
this.set('statsFrameCloseAvg', this.roundDigits(stats.closeAvg, 2).toString()); this.set('statsFrameCloseAvg', this.roundDigits(stats.closeAvg, 2));
this.set('statsFrameCloseMargin', Math.round(stats.closeMargin).toString()); this.set('statsFrameCloseMargin', this.roundDigits(stats.closeMargin, 1));
this.set('statsExposureLast', Math.round(stats.exposureLast).toString()); this.set('statsExposureLast', this.roundDigits(stats.exposureLast, 0));
this.set('statsExposureAvg', this.roundDigits(stats.exposureAvg, 2).toString()); this.set('statsExposureAvg', this.roundDigits(stats.exposureAvg, 2));
this.set('statsExposureMargin', Math.round(stats.exposureMargin).toString()); this.set('statsExposureMargin', this.roundDigits(stats.exposureMargin, 1));
this.set('statsElapsed', Math.round(stats.elapsed).toString()); this.set('statsElapsed', this.roundDigits(stats.elapsed, 0));
this.set('statsEstimate', Math.round(stats.estimate).toString()); this.set('statsEstimate', this.roundDigits(stats.estimate, 0));
this.set('statsElapsedHuman', this.shortenHumanize(Math.round(stats.elapsed))); this.set('statsElapsedHuman', this.shortenHumanize(Math.round(stats.elapsed)));
this.set('statsEstimateHuman', this.shortenHumanize(Math.round(stats.estimate))); this.set('statsEstimateHuman', this.shortenHumanize(Math.round(stats.estimate)));
@ -492,9 +492,10 @@ class Client {
.replace('seconds', 's').replace('second', 's'); .replace('seconds', 's').replace('second', 's');
} }
private roundDigits (val : number, digits : number) { private roundDigits (val : number, digits : number) : string {
const mult : number = Math.pow(10.0, digits); const mult : number = Math.pow(10.0, digits);
return Math.round(val * mult) / mult; const rounded : number = Math.round(val * mult) / mult;
return rounded.toString();
} }
} }

View File

@ -225,23 +225,23 @@ class Client {
} }
setStatistics(stats) { setStatistics(stats) {
if (stats !== null) { if (stats !== null) {
this.set('statsFrameTotalAvg', this.roundDigits(stats.totalFrameAvg, 2).toString()); this.set('statsFrameTotalLast', this.roundDigits(stats.totalFrameLast, 0));
this.set('statsFrameTotalLast', Math.round(stats.totalFrameLast).toString()); this.set('statsFrameTotalAvg', this.roundDigits(stats.totalFrameAvg, 2));
this.set('statsFrameTotalMargin', Math.round(stats.totalFrameMargin).toString()); this.set('statsFrameTotalMargin', this.roundDigits(stats.totalFrameMargin, 1));
this.set('statsFPS', this.roundDigits(stats.fps, 2).toString()); this.set('statsFPS', this.roundDigits(stats.fps, 2));
this.set('statsFrameLoadAvg', this.roundDigits(stats.loadAvg, 2).toString()); this.set('statsFrameLoadAvg', this.roundDigits(stats.loadAvg, 2));
this.set('statsFrameLoadMargin', Math.round(stats.loadMargin).toString()); this.set('statsFrameLoadMargin', this.roundDigits(stats.loadMargin, 1));
this.set('statsFrameOpenLast', Math.round(stats.openLast).toString()); this.set('statsFrameOpenLast', this.roundDigits(stats.openLast, 0));
this.set('statsFrameOpenAvg', this.roundDigits(stats.openAvg, 2).toString()); this.set('statsFrameOpenAvg', this.roundDigits(stats.openAvg, 2));
this.set('statsFrameOpenMargin', Math.round(stats.openMargin).toString()); this.set('statsFrameOpenMargin', this.roundDigits(stats.openMargin, 1));
this.set('statsFrameCloseLast', Math.round(stats.closeLast).toString()); this.set('statsFrameCloseLast', this.roundDigits(stats.closeLast, 0));
this.set('statsFrameCloseAvg', this.roundDigits(stats.closeAvg, 2).toString()); this.set('statsFrameCloseAvg', this.roundDigits(stats.closeAvg, 2));
this.set('statsFrameCloseMargin', Math.round(stats.closeMargin).toString()); this.set('statsFrameCloseMargin', this.roundDigits(stats.closeMargin, 1));
this.set('statsExposureLast', Math.round(stats.exposureLast).toString()); this.set('statsExposureLast', this.roundDigits(stats.exposureLast, 0));
this.set('statsExposureAvg', this.roundDigits(stats.exposureAvg, 2).toString()); this.set('statsExposureAvg', this.roundDigits(stats.exposureAvg, 2));
this.set('statsExposureMargin', Math.round(stats.exposureMargin).toString()); this.set('statsExposureMargin', this.roundDigits(stats.exposureMargin, 1));
this.set('statsElapsed', Math.round(stats.elapsed).toString()); this.set('statsElapsed', this.roundDigits(stats.elapsed, 0));
this.set('statsEstimate', Math.round(stats.estimate).toString()); this.set('statsEstimate', this.roundDigits(stats.estimate, 0));
this.set('statsElapsedHuman', this.shortenHumanize(Math.round(stats.elapsed))); this.set('statsElapsedHuman', this.shortenHumanize(Math.round(stats.elapsed)));
this.set('statsEstimateHuman', this.shortenHumanize(Math.round(stats.estimate))); this.set('statsEstimateHuman', this.shortenHumanize(Math.round(stats.estimate)));
} }
@ -414,7 +414,8 @@ class Client {
} }
roundDigits(val, digits) { roundDigits(val, digits) {
const mult = Math.pow(10.0, digits); const mult = Math.pow(10.0, digits);
return Math.round(val * mult) / mult; const rounded = Math.round(val * mult) / mult;
return rounded.toString();
} }
} }
client = new Client(); client = new Client();

File diff suppressed because one or more lines are too long

View File

@ -136,7 +136,7 @@
<form id="statisticsForm" onsubmit="return false;" class="flex"> <form id="statisticsForm" onsubmit="return false;" class="flex">
<div id="statisticsFrame" class="quarter"> <div id="statisticsFrame" class="quarter">
<div> <div>
<label for="statsFrameTotalAvg">Frame Total Avg</label><input id="statsFrameTotalAvg" class="large" type="text" readonly value="0" /><span> ms +/-</span> <label for="statsFrameTotalAvg">Frame Total Avg</label><input id="statsFrameTotalAvg" class="large" type="text" readonly value="0" /><span> ms ±</span>
<input id="statsFrameTotalMargin" class="small" type="text" readonly value="0"/><span>%</span> <input id="statsFrameTotalMargin" class="small" type="text" readonly value="0"/><span>%</span>
</div> </div>
<div> <div>
@ -146,20 +146,20 @@
<label for="statsFPS">FPS</label><input id="statsFPS" class="large" type="text" readonly value="0" /> <label for="statsFPS">FPS</label><input id="statsFPS" class="large" type="text" readonly value="0" />
</div> </div>
<div> <div>
<label for="statsFrameLoadAvg">Frame Load Avg</label><input id="statsFrameLoadAvg" class="large" type="text" readonly value="0" /><span> ms +/-</span> <label for="statsFrameLoadAvg">Frame Load Avg</label><input id="statsFrameLoadAvg" class="large" type="text" readonly value="0" /><span> ms ±</span>
<input id="statsFrameLoadMargin" class="small" type="text" readonly value="0"/><span>%</span> <input id="statsFrameLoadMargin" class="small" type="text" readonly value="0"/><span>%</span>
</div> </div>
</div> </div>
<div id="statisticsOpenClose" class="quarter"> <div id="statisticsOpenClose" class="quarter">
<div> <div>
<label for="statsFrameOpenAvg">Cam Open Avg</label><input id="statsFrameOpenAvg" class="large" type="text" readonly value="0" /><span> ms +/-</span> <label for="statsFrameOpenAvg">Cam Open Avg</label><input id="statsFrameOpenAvg" class="large" type="text" readonly value="0" /><span> ms ±</span>
<input id="statsFrameOpenMargin" class="small" type="text" readonly value="0"/><span>%</span> <input id="statsFrameOpenMargin" class="small" type="text" readonly value="0"/><span>%</span>
</div> </div>
<div> <div>
<label for="statsFrameOpenLast">Frame Open Last</label><input id="statsFrameOpenLast" class="large" type="text" readonly value="0" /><span> ms</span> <label for="statsFrameOpenLast">Frame Open Last</label><input id="statsFrameOpenLast" class="large" type="text" readonly value="0" /><span> ms</span>
</div> </div>
<div> <div>
<label for="statsFrameCloseAvg">Cam Close Avg</label><input id="statsFrameCloseAvg" class="large" type="text" readonly value="0" /><span> ms +/-</span> <label for="statsFrameCloseAvg">Cam Close Avg</label><input id="statsFrameCloseAvg" class="large" type="text" readonly value="0" /><span> ms ±</span>
<input id="statsFrameCloseMargin" class="small" type="text" readonly value="0"/><span>%</span> <input id="statsFrameCloseMargin" class="small" type="text" readonly value="0"/><span>%</span>
</div> </div>
<div> <div>
@ -168,7 +168,7 @@
</div> </div>
<div id="statisticsExposure" class="quarter"> <div id="statisticsExposure" class="quarter">
<div> <div>
<label for="statsExposureAvg">Exposure Avg</label><input id="statsExposureAvg" class="large" type="text" readonly value="0" /><span> ms +/-</span> <label for="statsExposureAvg">Exposure Avg</label><input id="statsExposureAvg" class="large" type="text" readonly value="0" /><span> ms ±</span>
<input id="statsExposureMargin" class="small" type="text" readonly value="0"/><span>%</span> <input id="statsExposureMargin" class="small" type="text" readonly value="0"/><span>%</span>
</div> </div>
<div> <div>