Added the ability to download the data in CSV and refactored the codebase
This commit is contained in:
+13
-8
@@ -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 [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user