From 3e74b0f252d8a00c1ff02106700cc9b475f08539 Mon Sep 17 00:00:00 2001 From: Anand Chowdhary Date: Sun, 6 Dec 2020 17:34:34 +0530 Subject: [PATCH] :recycle: Add daily minutes downtimes --- src/helpers/calculate-uptime.ts | 15 +++++++++++++++ src/interfaces.ts | 3 +++ src/summary.ts | 1 + 3 files changed, 19 insertions(+) diff --git a/src/helpers/calculate-uptime.ts b/src/helpers/calculate-uptime.ts index 43893bcf..a98a99fe 100644 --- a/src/helpers/calculate-uptime.ts +++ b/src/helpers/calculate-uptime.ts @@ -18,6 +18,7 @@ const getDowntimeSecondsForSite = async (slug: string): Promise => { let month = 0; let year = 0; let all = 0; + const dailyMinutesDown: Record = {}; // Get all the issues for this website const { data } = await octokit.issues.listForRepo({ @@ -42,6 +43,19 @@ const getDowntimeSecondsForSite = async (slug: string): Promise => { }; const end = dayjs().toDate().getTime(); + [...Array(365).keys()].forEach((day) => { + const date = dayjs().subtract(day, "day"); + const overlap = checkOverlap(issueOverlap, { + start: date.toDate().getTime(), + end, + }); + if (overlap) { + dailyMinutesDown[date.format("YYYY-MM-DD")] = + dailyMinutesDown[date.format("YYYY-MM-DD")] || 0; + dailyMinutesDown[date.format("YYYY-MM-DD")] += overlap; + } + }); + day += checkOverlap(issueOverlap, { start: dayjs().subtract(1, "day").toDate().getTime(), end, @@ -66,6 +80,7 @@ const getDowntimeSecondsForSite = async (slug: string): Promise => { month: Math.round(month / 1000), year: Math.round(year / 1000), all: Math.round(all / 1000), + dailyMinutesDown, }; }; diff --git a/src/interfaces.ts b/src/interfaces.ts index 2fbf98d6..f7355d0e 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -118,6 +118,8 @@ export interface SiteStatus { uptimeWeek: string; uptimeMonth: string; uptimeYear: string; + /** Summary for downtimes */ + dailyMinutesDown: Record; } export interface Downtimes { @@ -126,6 +128,7 @@ export interface Downtimes { month: number; year: number; all: number; + dailyMinutesDown: Record; } export interface DownPecentages { day: string; diff --git a/src/summary.ts b/src/summary.ts index eaa8f230..bf785963 100644 --- a/src/summary.ts +++ b/src/summary.ts @@ -67,6 +67,7 @@ export const generateSummary = async () => { timeWeek: responseTimes.week, timeMonth: responseTimes.month, timeYear: responseTimes.year, + dailyMinutesDown: responseTimes.dailyMinutesDown, }); if (responseTimes.currentStatus === "down") numberOfDown++; if (responseTimes.currentStatus === "degraded") numberOfDegraded++;