From 801f962af94c737cca9c7a5b2714e30a90146c95 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Tue, 13 Aug 2024 15:33:07 -0700 Subject: [PATCH] Add empty checks if there are less than 60 mins worth of cehcks --- Server/db/mongo/modules/monitorModule.js | 28 ++++++++++++++---------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/Server/db/mongo/modules/monitorModule.js b/Server/db/mongo/modules/monitorModule.js index 44a1d6132..689521acd 100644 --- a/Server/db/mongo/modules/monitorModule.js +++ b/Server/db/mongo/modules/monitorModule.js @@ -126,16 +126,22 @@ const getIncidents = (checks) => { * @param {Array} checks Array of check objects. * @returns {Array} Array of booleans representing up/down. */ -const getStatusBarValues = (checks) => { - return checks - .map((check) => { - return { - status: check.status, - responseTime: check.responseTime, - value: 75, - }; - }) - .reverse(); +const getStatusBarValues = (monitor, checks) => { + const checksIn60Mins = Math.floor((60 * 60 * 1000) / monitor.interval); + const noBlankChecks = checksIn60Mins - checks.length; + + const statusBarValues = checks.map((check) => { + return { + status: check.status, + responseTime: check.responseTime, + value: 75, + }; + }); + + for (let i = 0; i < noBlankChecks; i++) { + statusBarValues.push({ status: false, responseTime: 0, value: 0 }); + } + return statusBarValues.reverse(); }; /** * Get stats by monitor ID @@ -211,7 +217,7 @@ const getMonitorStatsById = async (req) => { getAverageResponseTime24Hours(checks24Hours); monitorStats.uptime24Hours = getUptimePercentage(checks24Hours); monitorStats.uptime30Days = getUptimePercentage(checks30Days); - monitorStats.statusBar = getStatusBarValues(checks60Mins); + monitorStats.statusBar = getStatusBarValues(monitor, checks60Mins); } //Get checks for dateRange