-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
172 lines (152 loc) · 4.07 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<html lang="en"><head>
<meta charset="UTF-8">
<title>GitHub Status - Incident History</title>
<style>
body {
background-color: rgb(13, 17, 23);
color: rgb(230, 237, 243);
}
.month {
max-width: 0;
}
.dayName {
bottom: -3px;
height: 19px;
font-size: 12px;
}
.day {
width: 10px;
border-radius: 2px;
border-spacing: 3px;
}
.count-0 {
background-color: rgb(22, 27, 34);
}
.count-1 {
background-color: rgb(14, 68, 41);
}
.count-2 {
background-color: rgb(0, 109, 50);
}
.count-3 {
background-color: rgb(38, 166, 65);
}
.count-4,
.count-5,
.count-6,
.count-7,
.count-8,
.count-9 {
background-color: rgb(57, 211, 83);
}
</style>
</head>
<body>
<h1><a href="https://www.githubstatus.com/">GitHub Status</a> - Incident History</h1>
<div id="app">
<table>
<tr>
<th v-for="month in months" class="month">{{month}}</th>
</tr>
<tr v-for="(days, name) in week">
<td class="dayName">{{daysOfWeek[name]}}</td>
<td v-for="day in days" class="day" :class="[`count-${day}`]" :title="day"></td>
</tr>
</table>
<table>
<tr>
<td>Less</td>
<td class="day count-0" title="0"></td>
<td class="day count-1" title="1"></td>
<td class="day count-2" title="2"></td>
<td class="day count-3" title="3"></td>
<td class="day count-4" title="4+"></td>
<td>More</td>
</tr>
</table>
</div>
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
<script>
const { createApp, ref } = Vue;
async function getIncidents() {
const response = await fetch(
`https://www.githubstatus.com/api/v2/incidents.json`
);
const incidents = await response.json();
// console.log(incidents);
return incidents;
}
async function run() {
const daysOfWeek = {
0: "",
1: "Mon",
2: "",
3: "Wed",
4: "",
5: "Fri",
6: ""
};
const weekInMillis = 7 * 24 * 60 * 60 * 1000; // Number of milliseconds in a week
const present = new Date();
const monthNames = [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
];
const months = new Array(52)
.fill(0)
.map((_, i) => new Date(present.getTime() - (52 - i) * weekInMillis))
.map((x) => (x.getDate() <= 7 ? monthNames[x.getMonth()] : ""));
const allIncidents = await getIncidents();
// const allIncidents = {
// incidents: [
// {started_at: "2023-07-26T14:49:19.644Z"},
// {started_at: "2023-07-28T09:31:01.989Z"},
// ]
// };
// console.log(allIncidents);
createApp({
setup() {
const incidentDates = allIncidents.incidents.map(
(i) => new Date(i.started_at)
);
// console.log(incidentDates);
const week = Object.fromEntries(
Object.entries(daysOfWeek).map(([dayIndex, dayName]) => [
dayIndex,
incidentDates
.filter(
(x) =>
String(x.getDay()) === dayIndex &&
x.getFullYear() >= present.getFullYear() - 1
)
.reduce((acc, date) => {
const timeDifference = present - date;
const weekNumber = Math.floor(timeDifference / weekInMillis);
if (weekNumber >= 0 && weekNumber < 52) {
acc[52 - weekNumber - 1]++;
}
return acc;
}, new Array(52).fill(0))
])
);
return {
week: week,
months: months,
daysOfWeek: daysOfWeek
};
}
}).mount("#app");
}
run();
</script>
</body></html>