mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-06-19 18:56:48 +02:00
fix distribute daily data across bucket ranges
This commit is contained in:
parent
b6227e7605
commit
3a5bedda88
1 changed files with 28 additions and 13 deletions
|
@ -866,10 +866,11 @@ class UptimeCalculator {
|
||||||
const exactMinutes = Math.ceil(days * 24 * 60);
|
const exactMinutes = Math.ceil(days * 24 * 60);
|
||||||
rawDataPoints = this.getDataArray(exactMinutes, "minute");
|
rawDataPoints = this.getDataArray(exactMinutes, "minute");
|
||||||
} else if (days <= 30) {
|
} else if (days <= 30) {
|
||||||
const exactHours = Math.ceil(days * 24);
|
// For 1-30 days, use hourly data (up to 720 hours)
|
||||||
|
const exactHours = Math.min(Math.ceil(days * 24), 720);
|
||||||
rawDataPoints = this.getDataArray(exactHours, "hour");
|
rawDataPoints = this.getDataArray(exactHours, "hour");
|
||||||
} else {
|
} else {
|
||||||
// For > 30 days, use daily data to avoid hitting the 720-hour limit
|
// For > 30 days, use daily data
|
||||||
const requestDays = Math.min(days, 365);
|
const requestDays = Math.min(days, 365);
|
||||||
rawDataPoints = this.getDataArray(requestDays, "day");
|
rawDataPoints = this.getDataArray(requestDays, "day");
|
||||||
}
|
}
|
||||||
|
@ -898,21 +899,35 @@ class UptimeCalculator {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Aggregate available data into buckets
|
// Aggregate available data into buckets
|
||||||
let bucketIndex = 0;
|
|
||||||
for (const [ timestamp, dataPoint ] of Object.entries(availableData)) {
|
for (const [ timestamp, dataPoint ] of Object.entries(availableData)) {
|
||||||
const timestampNum = parseInt(timestamp);
|
const timestampNum = parseInt(timestamp);
|
||||||
|
|
||||||
// Find the appropriate bucket for this data point (more efficient)
|
// Find the appropriate bucket for this data point
|
||||||
while (bucketIndex < buckets.length - 1 && timestampNum >= buckets[bucketIndex].end) {
|
// For daily data (> 30 days), timestamps are at start of day
|
||||||
bucketIndex++;
|
// We need to find which bucket this day belongs to
|
||||||
}
|
for (let i = 0; i < buckets.length; i++) {
|
||||||
|
const bucket = buckets[i];
|
||||||
|
|
||||||
const bucket = buckets[bucketIndex];
|
if (days > 30) {
|
||||||
if (bucket && timestampNum >= bucket.start && timestampNum < bucket.end && dataPoint) {
|
// For daily data, check if the timestamp falls within the bucket's day range
|
||||||
bucket.up += dataPoint.up || 0;
|
// Add 86400 (1 day in seconds) to include the whole day
|
||||||
bucket.down += dataPoint.down || 0;
|
if (timestampNum >= bucket.start && timestampNum < bucket.end) {
|
||||||
bucket.maintenance += 0; // UptimeCalculator treats maintenance as up
|
bucket.up += dataPoint.up || 0;
|
||||||
bucket.pending += 0; // UptimeCalculator doesn't track pending separately
|
bucket.down += dataPoint.down || 0;
|
||||||
|
bucket.maintenance += dataPoint.maintenance || 0;
|
||||||
|
bucket.pending += dataPoint.pending || 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// For minute/hourly data, use exact timestamp matching
|
||||||
|
if (timestampNum >= bucket.start && timestampNum < bucket.end && dataPoint) {
|
||||||
|
bucket.up += dataPoint.up || 0;
|
||||||
|
bucket.down += dataPoint.down || 0;
|
||||||
|
bucket.maintenance += 0; // UptimeCalculator treats maintenance as up
|
||||||
|
bucket.pending += 0; // UptimeCalculator doesn't track pending separately
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue