Weather Station / ECOWITT / DNT
0

Configure Feed

Select the types of activity you want to include in your feed.

forcast analysis

+28 -6
+28 -6
src/instrumentation.ts
··· 160 160 * Store forecasts for a single station by calling the internal store API 161 161 */ 162 162 export async function storeForecastForStation(stationId: string) { 163 + console.log(`[forecast-store] ========================================`); 164 + console.log(`[forecast-store] START: Storing forecasts for station ${stationId}`); 165 + console.log(`[forecast-store] ========================================`); 166 + 163 167 try { 164 168 const { getDuckConn } = await import("@/lib/db/duckdb"); 165 169 const conn = await getDuckConn(); 166 170 const storageDate = new Date().toISOString().split('T')[0]; 171 + console.log(`[forecast-store] ✓ Database connection established`); 167 172 168 173 // Create forecast table if not exists 169 174 await conn.run(` ··· 181 186 PRIMARY KEY(storage_date, station_id, forecast_date, source) 182 187 ) 183 188 `); 189 + console.log(`[forecast-store] ✓ Forecast table created/verified`); 184 190 185 191 // Get station coordinates first 192 + console.log(`[forecast-store] Fetching station metadata...`); 186 193 const stationsResponse = await fetch('https://dataset.api.hub.geosphere.at/v1/station/current/tawes-v1-10min/metadata'); 194 + 195 + if (!stationsResponse.ok) { 196 + throw new Error(`Failed to fetch station metadata: ${stationsResponse.status} ${stationsResponse.statusText}`); 197 + } 198 + 187 199 const stationsData = await stationsResponse.json(); 188 200 const station = stationsData.stations.find((s: any) => s.id === stationId); 189 201 190 202 if (!station) { 191 - console.error(`[forecast] Station ${stationId} not found`); 192 - return; 203 + throw new Error(`Station ${stationId} not found in metadata`); 193 204 } 205 + 206 + console.log(`[forecast-store] ✓ Station found: ${station.name} (${station.lat}, ${station.lon})`); 207 + 194 208 195 209 const lat = station.lat; 196 210 const lon = station.lon; ··· 393 407 `, [storageDate, stationId, day.date, 'openmeteo', day.tempMin, day.tempMax, day.precipitation, day.windSpeed, day.windGust]); 394 408 } 395 409 } 396 - } catch (e) { 397 - console.error(`[forecast] Failed to store ${sourceName}:`, e); 410 + } catch (e: any) { 411 + console.error(`[forecast-store] ✗ Failed to store ${sourceName}:`, e?.message || e); 398 412 } 399 413 } 400 - } catch (e) { 401 - console.error("[forecast] Storage failed:", e); 414 + 415 + console.log(`[forecast-store] ========================================`); 416 + console.log(`[forecast-store] DONE: Forecasts stored for station ${stationId}`); 417 + console.log(`[forecast-store] ========================================`); 418 + } catch (e: any) { 419 + console.error(`[forecast-store] ========================================`); 420 + console.error(`[forecast-store] ✗✗✗ STORAGE FAILED ✗✗✗`); 421 + console.error(`[forecast-store] ========================================`); 422 + console.error(`[forecast-store] Error:`, e?.message || e); 423 + console.error(`[forecast-store] Stack:`, e?.stack); 402 424 throw e; 403 425 } 404 426 }