reminder-bot/web/static/js/admin.js

132 lines
4.8 KiB
JavaScript
Raw Normal View History

2023-06-21 14:09:24 +00:00
document.addEventListener("DOMContentLoaded", () => {
fetch("/admin/data")
.then((resp) => resp.json())
.then((data) => {
document.querySelector("#backlog").textContent = data.backlog;
document.querySelector("#reminders").textContent = data.count.reminders;
document.querySelector("#intervals").textContent = data.count.intervals;
2023-06-21 14:09:24 +00:00
let historySent = data.historyLong.sent.reduce(
(iv, frame) => iv + frame.count,
0
);
let historyFailed = data.historyLong.failed.reduce(
(iv, frame) => iv + frame.count,
0
);
document.querySelector("#historySent").textContent = historySent;
document.querySelector("#historyFailed").textContent = historyFailed;
document.querySelector("#failRate").textContent = `${
(historyFailed / (historySent + historyFailed)) * 100
}%`;
2023-06-21 14:09:24 +00:00
new Chart(document.getElementById("schedule"), {
type: "bar",
data: {
2023-06-21 14:24:43 +00:00
labels: [
...data.scheduleShort.once,
...data.scheduleShort.interval,
].map((row) => luxon.DateTime.fromISO(row.time_key)),
2023-06-21 14:09:24 +00:00
datasets: [
{
label: "Reminders",
2023-06-21 14:24:43 +00:00
data: data.scheduleShort.once.map((row) => row.count),
},
{
label: "Intervals",
data: data.scheduleShort.interval.map((row) => row.count),
2023-06-21 14:09:24 +00:00
},
],
},
options: {
responsive: true,
maintainAspectRatio: false,
scales: {
x: {
2023-06-21 14:24:43 +00:00
stacked: true,
2023-06-21 14:09:24 +00:00
type: "time",
time: {
unit: "minute",
},
},
2023-06-21 14:24:43 +00:00
y: {
stacked: true,
},
2023-06-21 14:09:24 +00:00
},
},
});
new Chart(document.getElementById("scheduleLong"), {
type: "bar",
data: {
2023-06-21 14:24:43 +00:00
labels: [
...data.scheduleLong.once,
...data.scheduleLong.interval,
].map((row) => luxon.DateTime.fromISO(row.time_key)),
2023-06-21 14:09:24 +00:00
datasets: [
{
label: "Reminders",
2023-06-21 14:24:43 +00:00
data: data.scheduleLong.once.map((row) => row.count),
},
{
label: "Intervals",
data: data.scheduleLong.interval.map((row) => row.count),
2023-06-21 14:09:24 +00:00
},
],
},
options: {
responsive: true,
maintainAspectRatio: false,
scales: {
x: {
2023-06-21 14:24:43 +00:00
stacked: true,
2023-06-21 14:09:24 +00:00
type: "time",
time: {
unit: "day",
},
},
2023-06-21 14:24:43 +00:00
y: {
stacked: true,
},
2023-06-21 14:09:24 +00:00
},
},
});
new Chart(document.getElementById("historyLong"), {
type: "bar",
data: {
labels: [...data.historyLong.sent, ...data.historyLong.failed].map(
(row) => luxon.DateTime.fromISO(row.time_key)
),
datasets: [
{
label: "Success",
data: data.historyLong.sent.map((row) => row.count),
},
{
label: "Fail",
data: data.historyLong.failed.map((row) => row.count),
},
],
},
options: {
responsive: true,
maintainAspectRatio: false,
scales: {
x: {
stacked: true,
type: "time",
time: {
unit: "day",
},
},
y: {
stacked: true,
},
},
},
});
2023-06-21 14:09:24 +00:00
});
});