Add empty checks if there are less than 60 mins worth of cehcks

This commit is contained in:
Alex Holliday committed 2024-08-13 15:33:07 -07:00
1 parent 7336287a9c
commit 801f962af9
1 file changed
+17 -11
+17 -11
View File
@@ -126,16 +126,22 @@ const getIncidents = (checks) => {
* @param {Array} checks Array of check objects. * @param {Array} checks Array of check objects.
* @returns {Array<Boolean>} Array of booleans representing up/down. * @returns {Array<Boolean>} Array of booleans representing up/down.
*/ */
const getStatusBarValues = (checks) => { const getStatusBarValues = (monitor, checks) => {
return checks const checksIn60Mins = Math.floor((60 * 60 * 1000) / monitor.interval);
.map((check) => { const noBlankChecks = checksIn60Mins - checks.length;
return {
status: check.status, const statusBarValues = checks.map((check) => {
responseTime: check.responseTime, return {
value: 75, status: check.status,
}; responseTime: check.responseTime,
}) value: 75,
.reverse(); };
});
for (let i = 0; i < noBlankChecks; i++) {
statusBarValues.push({ status: false, responseTime: 0, value: 0 });
}
return statusBarValues.reverse();
}; };
/** /**
* Get stats by monitor ID * Get stats by monitor ID
@@ -211,7 +217,7 @@ const getMonitorStatsById = async (req) => {
getAverageResponseTime24Hours(checks24Hours); getAverageResponseTime24Hours(checks24Hours);
monitorStats.uptime24Hours = getUptimePercentage(checks24Hours); monitorStats.uptime24Hours = getUptimePercentage(checks24Hours);
monitorStats.uptime30Days = getUptimePercentage(checks30Days); monitorStats.uptime30Days = getUptimePercentage(checks30Days);
monitorStats.statusBar = getStatusBarValues(checks60Mins); monitorStats.statusBar = getStatusBarValues(monitor, checks60Mins);
} }
//Get checks for dateRange //Get checks for dateRange