feat: implement Open-Meteo weather integration with backfill scripts and updated lake data models.
continuous-integration/drone/push Build encountered an error

This commit is contained in:
David Fencl
2026-06-05 23:34:13 +02:00
parent 8193ce818a
commit 57e9bf12ca
24 changed files with 1122 additions and 758 deletions
+19 -3
View File
@@ -112,11 +112,27 @@ async function scrapeLake(lakeId: string, oid: string, internalId: string) {
}
if (records.length > 0) {
// Apply current values to the latest record
records[0].inflow = currentInflow;
records[0].volume = currentVolume;
if (currentTemp !== null) records[0].temperature = currentTemp;
if (currentPrecip !== null) records[0].precipitation = currentPrecip;
// Override weather from PVL completely using Open-Meteo
const config = lakesConfig.find(l => l.id.split('|')[0] === internalId);
if (config && config.coords) {
try {
const lat = config.coords[0];
const lon = config.coords[1];
const url = `https://api.open-meteo.com/v1/forecast?latitude=${lat}&longitude=${lon}&current=temperature_2m,precipitation`;
const weatherRes = await axios.get(url, { timeout: 5000 });
if (weatherRes.data && weatherRes.data.current) {
records[0].temperature = weatherRes.data.current.temperature_2m;
records[0].precipitation = weatherRes.data.current.precipitation;
}
// Small delay to prevent API rate limits
await new Promise(resolve => setTimeout(resolve, 200));
} catch (err: any) {
console.error(`Failed to fetch weather for ${internalId}:`, err.message);
}
}
}
let existingData: DataRecord[] = [];