2026-05-12 16:40:39 +02:00
|
|
|
let chart = null;
|
|
|
|
|
window.onload = init;
|
|
|
|
|
|
|
|
|
|
async function init() {
|
|
|
|
|
let start = new Date();
|
|
|
|
|
start.setDate(start.getDate() - 7);
|
|
|
|
|
const end = new Date();
|
|
|
|
|
|
|
|
|
|
document.getElementById("date-start").valueAsDate = start;
|
|
|
|
|
document.getElementById("date-end").valueAsDate = end;
|
|
|
|
|
document.getElementById("btn-refresh").addEventListener("click", loadData);
|
|
|
|
|
|
|
|
|
|
loadData();
|
|
|
|
|
}
|
2026-05-11 23:17:43 +02:00
|
|
|
|
|
|
|
|
async function loadData() {
|
2026-05-12 16:40:39 +02:00
|
|
|
const start = document.getElementById("date-start").value;
|
|
|
|
|
const end = document.getElementById("date-end").value;
|
|
|
|
|
const granularity = document.getElementById("granularity").value;
|
|
|
|
|
|
|
|
|
|
const points = await fetchConsumption({
|
|
|
|
|
start: start,
|
|
|
|
|
end: end,
|
|
|
|
|
granularity: granularity,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (chart) {
|
|
|
|
|
chart.destroy();
|
|
|
|
|
}
|
2026-05-12 19:51:50 +02:00
|
|
|
chart = renderChart(points, granularity);
|
2026-05-12 17:15:42 +02:00
|
|
|
updateKPIs(points);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function updateKPIs(points) {
|
|
|
|
|
const totalDisplay = document.getElementById("kpi-total");
|
|
|
|
|
const avgDisplay = document.getElementById("kpi-avg");
|
|
|
|
|
const countDisplay = document.getElementById("kpi-count");
|
|
|
|
|
|
|
|
|
|
if (!points || points.length === 0) {
|
|
|
|
|
total.textContent = "-";
|
|
|
|
|
avg.textContent = "-";
|
|
|
|
|
count.textContent = "-";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const totalValue = points.reduce((acc, p) => acc + p.delta_m3, 0);
|
|
|
|
|
const avgValue = totalValue / points.length;
|
|
|
|
|
|
|
|
|
|
totalDisplay.textContent = totalValue.toFixed(3);
|
|
|
|
|
avgDisplay.textContent = avgValue.toFixed(3);
|
|
|
|
|
countDisplay.textContent = points.length;
|
2026-05-12 16:40:39 +02:00
|
|
|
}
|