-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_data.ts
42 lines (37 loc) · 1.1 KB
/
_data.ts
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
export const layout = "layout.njk";
export const uptimeChartData = (() => {
try {
const LOGS: Array<{ time: string; status: string }> = [];
const ChartData: { labels: string[]; data: number[] } = {
labels: [],
data: [],
};
const logs_dir = Deno.readDirSync("logs");
Array.from(logs_dir).forEach(
(log) => {
if (log.isFile && log.name.endsWith(".json")) {
const DATA = JSON.parse(
new TextDecoder("utf-8").decode(
Deno.readFileSync(`logs/${log.name}`),
),
);
LOGS.push(DATA.tila);
}
},
);
LOGS.sort(function (a, b) {
return a.time.localeCompare(b.time);
});
LOGS.forEach((X) => {
ChartData.labels.push(new Date(X.time).toUTCString());
ChartData.data.push(X.status == "online" ? 1 : 0);
});
if (ChartData.labels.length == 1 && ChartData.data.length == 1) {
ChartData.labels = [...ChartData.labels, ...ChartData.labels];
ChartData.data = [...ChartData.data, ...ChartData.data];
}
return ChartData;
} catch {
return [];
}
})();