Skip to content

Commit

Permalink
dashboard: optimize RateTracker
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan committed Jun 9, 2023
1 parent e5bf5a4 commit c0f5389
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions dashboard/assets/scripts/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -960,8 +960,12 @@ class RateTracker {
const duration = now - this.timeLast;
this._reset();
this._addReading(duration, value);
const valueSum = this._values.reduce((a, b) => a + b, 0);
const durationSum = this._durations.reduce((a, b) => a + b, 0);
let valueSum = 0;
let durationSum = 0;
for (let i = 0; i < this._keepReadings; i++) {
valueSum += this._values[i];
durationSum += this._durations[i];
}
return valueSum / durationSum;
}
}
Expand Down

0 comments on commit c0f5389

Please sign in to comment.