Added the ability to download the data in CSV and refactored the codebase

This commit is contained in:
2026-05-08 00:48:04 +02:00
parent 02c1a4c58c
commit 6ccc856edc
10 changed files with 423 additions and 68 deletions
+13 -8
View File
@@ -7,13 +7,18 @@ export async function fetchStations() {
.sort((a, b) => b.pk - a.pk);
}
export async function fetchDay(id, date) {
try {
const res = await fetch(`/api/get_measurements/${id}?day=${date}`);
if (!res.ok) return [];
const data = await res.json();
return data.misure ?? [];
} catch {
return [];
export async function fetchDay(id, date, signal) {
// L'API risponde con 5xx transienti: tre tentativi limitano i buchi nel dataset scaricato.
for (let attempt = 0; attempt < 3; attempt++) {
try {
const res = await fetch(`/api/get_measurements/${id}?day=${date}`, { signal });
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const data = await res.json();
return data.misure ?? [];
} catch (e) {
// La cancellazione non è un errore: uscire subito senza consumare altri retry.
if (e.name === 'AbortError') return [];
if (attempt === 2) return [];
}
}
}