From 7deafe425c85fac37eb1bf2679d517e6b94055e0 Mon Sep 17 00:00:00 2001 From: Mats Stottmeister Date: Tue, 10 Jun 2025 14:50:46 +0200 Subject: [PATCH] fix: percent number coloring --- server/routers/status-page-router.js | 27 ++++++++++++++++++++++++--- src/pages/StatusPage.vue | 7 +++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/server/routers/status-page-router.js b/server/routers/status-page-router.js index 930e99a26..caad9c399 100644 --- a/server/routers/status-page-router.js +++ b/server/routers/status-page-router.js @@ -200,6 +200,27 @@ router.get("/api/status-page/heartbeat-daily/:slug", cache("5 minutes"), async ( }); heartbeatList[monitorID] = processedData; + + // Calculate uptime based only on actual daily data (not including missing days) + if (processedData.length > 0) { + // Get recent data (last 30 days worth of actual data) + const recentData = processedData.slice(-30); + + let totalUp = 0; + let totalDown = 0; + + recentData.forEach(day => { + if (day.dailyStats) { + totalUp += day.dailyStats.up; + totalDown += day.dailyStats.down; + } + }); + + const totalChecks = totalUp + totalDown; + uptimeList[`${monitorID}_24`] = totalChecks > 0 ? (totalUp / totalChecks) : 0; + } else { + uptimeList[`${monitorID}_24`] = 0; + } } else { // Use regular heartbeat data (last 100 beats) let list = await R.getAll(` @@ -213,10 +234,10 @@ router.get("/api/status-page/heartbeat-daily/:slug", cache("5 minutes"), async ( list = R.convertToBeans("heartbeat", list); heartbeatList[monitorID] = list.reverse().map(row => row.toPublicJSON()); + + const uptimeCalculator = await UptimeCalculator.getUptimeCalculator(monitorID); + uptimeList[`${monitorID}_24`] = uptimeCalculator.get24Hour().uptime; } - - const uptimeCalculator = await UptimeCalculator.getUptimeCalculator(monitorID); - uptimeList[`${monitorID}_24`] = uptimeCalculator.get24Hour().uptime; } response.json({ diff --git a/src/pages/StatusPage.vue b/src/pages/StatusPage.vue index 0256085ae..abccc2755 100644 --- a/src/pages/StatusPage.vue +++ b/src/pages/StatusPage.vue @@ -785,6 +785,13 @@ export default { if (dailyViewSettings[monitorId]) { // This monitor uses daily view this.$root.dailyHeartbeatList[monitorId] = heartbeatList[monitorId]; + + // Set up lastHeartbeatList for uptime color calculation + if (heartbeatList[monitorId] && heartbeatList[monitorId].length > 0) { + const lastDailyBeat = heartbeatList[monitorId][heartbeatList[monitorId].length - 1]; + // Create a minimal heartbeat list with just the last beat for color calculation + this.$root.heartbeatList[monitorId] = [lastDailyBeat]; + } } else { // This monitor uses regular view this.$root.heartbeatList[monitorId] = heartbeatList[monitorId];