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 c0f5389 commit 40bd8f5
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions dashboard/assets/scripts/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -940,11 +940,7 @@ class RateTracker {
this._durations = new Array(keepReadings).fill(0);
this._values = new Array(keepReadings).fill(0);
this._keepReadings = keepReadings;
this._reset();
}

_reset() {
this.timeLast = Date.now() / 1000;
this._timeLast = Date.now() / 1000;
}

_addReading(duration, value) {
Expand All @@ -957,8 +953,8 @@ class RateTracker {

getRate(value) {
const now = Date.now() / 1000;
const duration = now - this.timeLast;
this._reset();
const duration = now - this._timeLast;
this._timeLast = Date.now() / 1000;
this._addReading(duration, value);
let valueSum = 0;
let durationSum = 0;
Expand Down

0 comments on commit 40bd8f5

Please sign in to comment.