Skip to content

Commit

Permalink
Fix: Use hourly data for chart
Browse files Browse the repository at this point in the history
Fix: Do not aggregate too few datapoints
  • Loading branch information
chakflying committed Dec 22, 2023
1 parent 6a59e9d commit 3b4cdf2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions server/socket-handlers/chart-socket-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ module.exports.chartSocketHandler = (socket) => {

if (period <= 24) {
data = uptimeCalculator.getDataArray(period * 60, "minute");
} else if (period <= 720) {
data = uptimeCalculator.getDataArray(period, "hour");
} else {
data = uptimeCalculator.getDataArray(period / 24, "day");
}
Expand Down
11 changes: 9 additions & 2 deletions src/components/PingChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -224,17 +224,18 @@ export default {
continue;
}
if (datapoint.up > 0) {
if (datapoint.up > 0 && this.chartRawData.length > aggregatePoints * 2) {
// Aggregate Up data using a sliding window
aggregateBuffer.push(datapoint);
if (aggregateBuffer.length === aggregatePoints) {
const average = this.getAverage(aggregateBuffer);
this.pushDatapoint(average, avgPingData, minPingData, maxPingData, downData, colorData);
// Remove the first half of the buffer
aggregateBuffer = aggregateBuffer.slice(Math.floor(aggregatePoints / 2));
}
} else {
// datapoint is fully down, no need to aggregate
// datapoint is fully down or too few datapoints, no need to aggregate
// Clear the aggregate buffer
if (aggregateBuffer.length > 0) {
const average = this.getAverage(aggregateBuffer);
Expand All @@ -245,6 +246,12 @@ export default {
this.pushDatapoint(datapoint, avgPingData, minPingData, maxPingData, downData, colorData);
}
}
// Clear the aggregate buffer if there are still datapoints
if (aggregateBuffer.length > 0) {
const average = this.getAverage(aggregateBuffer);
this.pushDatapoint(average, avgPingData, minPingData, maxPingData, downData, colorData);
aggregateBuffer = [];
}
}
return {
Expand Down

0 comments on commit 3b4cdf2

Please sign in to comment.