Skip to content

Commit

Permalink
fix: drop out-of-bound coords in reducer
Browse files Browse the repository at this point in the history
The fix from #251 introduced a logic that
1. allocated all "too-old" coords to the first group coords[0]
2. deleted all but one entries from that first group.

This caused aggregators to stop calculating proper results for that first group.

The proposed new logic drops out-of-bounds entries already in the reducer.
This allows the first group to have multiple entries.
Aggregate functions should now work again.
  • Loading branch information
akloeckner committed Dec 3, 2022
1 parent c50ac9d commit 88f16dc
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ export default class Graph {

const histGroups = this._history.reduce((res, item) => this._reducer(res, item), []);

// drop potential out of bound entry's except one
if (histGroups[0] && histGroups[0].length) {
histGroups[0] = [histGroups[0][histGroups[0].length - 1]];
}

// extend length to fill missing history
const requiredNumOfPoints = Math.ceil(this.hours * this.points);
histGroups.length = requiredNumOfPoints;
Expand All @@ -71,9 +66,11 @@ export default class Graph {
_reducer(res, item) {
const age = this._endTime - new Date(item.last_changed).getTime();
const interval = (age / ONE_HOUR * this.points) - this.hours * this.points;
const key = interval < 0 ? Math.floor(Math.abs(interval)) : 0;
if (!res[key]) res[key] = [];
res[key].push(item);
if (interval < 0) {
const key = Math.floor(Math.abs(interval));
if (!res[key]) res[key] = [];
res[key].push(item);
}
return res;
}

Expand Down

0 comments on commit 88f16dc

Please sign in to comment.