This commit is contained in:
David Fencl
2026-06-09 20:45:08 +02:00
parent c4cad149ea
commit c8fe97078d
56 changed files with 50749 additions and 48947 deletions
+6 -4
View File
@@ -25,9 +25,10 @@ async function backfill() {
try {
const lat = lake.coords[0];
const lon = lake.coords[1];
const url = `https://api.open-meteo.com/v1/forecast?latitude=${lat}&longitude=${lon}&past_days=7&hourly=temperature_2m,precipitation&timezone=GMT`;
// Fetch maximum past days supported by the forecast API (92 days)
const url = `https://api.open-meteo.com/v1/forecast?latitude=${lat}&longitude=${lon}&past_days=92&hourly=temperature_2m,precipitation&timezone=GMT`;
const res = await axios.get(url, { timeout: 10000 });
const res = await axios.get(url, { timeout: 15000 });
const hourly = res.data.hourly;
// Build lookup map for O(1) matching: '2026-06-02T04:00' -> { temp, precip }
@@ -43,9 +44,10 @@ async function backfill() {
let updatedCount = 0;
for (const record of data) {
// record.timestamp is like "2026-06-02T04:00:00.000Z"
// record.timestamp is like "2026-06-02T04:10:00.000Z"
// Open-Meteo time is like "2026-06-02T04:00"
const hourKey = record.timestamp.substring(0, 16); // Extract up to minutes
// Convert to hourly key to match weatherMap
const hourKey = record.timestamp.substring(0, 13) + ':00';
if (weatherMap.has(hourKey)) {
const w = weatherMap.get(hourKey);