Skip to content

Commit

Permalink
♻️ Add daily minutes downtimes
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandChowdhary committed Dec 6, 2020
1 parent 4db4389 commit 3e74b0f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/helpers/calculate-uptime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const getDowntimeSecondsForSite = async (slug: string): Promise<Downtimes> => {
let month = 0;
let year = 0;
let all = 0;
const dailyMinutesDown: Record<string, number> = {};

// Get all the issues for this website
const { data } = await octokit.issues.listForRepo({
Expand All @@ -42,6 +43,19 @@ const getDowntimeSecondsForSite = async (slug: string): Promise<Downtimes> => {
};
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,
Expand All @@ -66,6 +80,7 @@ const getDowntimeSecondsForSite = async (slug: string): Promise<Downtimes> => {
month: Math.round(month / 1000),
year: Math.round(year / 1000),
all: Math.round(all / 1000),
dailyMinutesDown,
};
};

Expand Down
3 changes: 3 additions & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ export interface SiteStatus {
uptimeWeek: string;
uptimeMonth: string;
uptimeYear: string;
/** Summary for downtimes */
dailyMinutesDown: Record<string, number>;
}

export interface Downtimes {
Expand All @@ -126,6 +128,7 @@ export interface Downtimes {
month: number;
year: number;
all: number;
dailyMinutesDown: Record<string, number>;
}
export interface DownPecentages {
day: string;
Expand Down
1 change: 1 addition & 0 deletions src/summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down

0 comments on commit 3e74b0f

Please sign in to comment.