From e767a08bb519e6dfb6d19ad74a41d0fc94174a85 Mon Sep 17 00:00:00 2001 From: ztimson Date: Sat, 27 Jun 2026 01:19:43 -0400 Subject: [PATCH] Fixing hourly --- server/src/forecast.mjs | 27 ++++++++++++++------------- server/src/sensors.mjs | 5 +++-- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/server/src/forecast.mjs b/server/src/forecast.mjs index 4d0d91b..c9f151c 100644 --- a/server/src/forecast.mjs +++ b/server/src/forecast.mjs @@ -119,6 +119,7 @@ export async function get24HourForecast(currentSensors) { const weather = pressureRule(pressure3h, seedPressure); + let runningAccumulation = 0; const slots = Array.from({ length: 24 }, (_, i) => { const time = new Date(now.getTime() + (i + 1) * 3600 * 1000); time.setMinutes(0, 0, 0); @@ -134,6 +135,7 @@ export async function get24HourForecast(currentSensors) { const precipitation_chance = Math.round(weather.precipitation_chance * (1 - i * 0.02) * 100); const raining = precipitation_chance > 60 ? 'True' : 'False'; const precipitation = estimatePrecipitation(precipitation_chance, clouds); + runningAccumulation = Math.round((runningAccumulation + precipitation) * 100) / 100; const celestial = getCelestialCurrent(coords.latitude, coords.longitude, time); const uv_index = estimateUV(celestial.sun_elevation ?? 0, clouds); @@ -157,7 +159,7 @@ export async function get24HourForecast(currentSensors) { raining, precipitation, precipitation_chance, - accumulation: 0, + accumulation: runningAccumulation, uv_index, uv_dose: 0, solar_wm2: 0, @@ -229,7 +231,6 @@ function summarise(slots) { return { time: slots[0].time, label: dominant.label, - code: dominant.code ?? null, icon: dominant.icon, temperature: peak(fin('temperature')), temperature_max: peak(finAll('temperature')), @@ -250,7 +251,7 @@ function summarise(slots) { raining: peak(fin('precipitation_chance')) > 60 ? 'True' : 'False', precipitation: avg(fin('precipitation')), precipitation_chance: Math.round(peak(fin('precipitation_chance'))), - accumulation: 0, + accumulation: finAll('precipitation').reduce((a, b) => a + b, 0), uv_index: peak(fin('uv_index')), uv_dose: finAll('uv_dose').reduce((a, b) => a + b, 0), solar_wm2: avg(fin('solar_wm2')), @@ -287,20 +288,20 @@ export async function getForecast() { export function getWeatherCondition(data) { if(data.lightning_rate > 0 && data.raining === 'True') { - return {label: 'Thunderstorm', icon: '11d', code: 211}; + return {label: 'Thunderstorm', icon: '11d'}; } if(data.raining === 'True') { - if(data.precipitation > 7.6) return {label: 'Heavy Rain', icon: '10d', code: 502}; - if(data.precipitation > 2.5) return {label: 'Moderate Rain', icon: '10d', code: 501}; - return {label: 'Light Rain', icon: '09d', code: 500}; + if(data.precipitation > 7.6) return {label: 'Heavy Rain', icon: '10d'}; + if(data.precipitation > 2.5) return {label: 'Moderate Rain', icon: '10d'}; + return {label: 'Light Rain', icon: '09d'}; } - if(data.visibility < 10) return {label: 'Mist', icon: '50d', code: 701}; + if(data.visibility < 10) return {label: 'Mist', icon: '50d'}; const dayNight = data.daytime ? 'd' : 'n'; const c = data.clouds > 1 ? data.clouds / 100 : data.clouds; - if(c > 0.85) return {label: 'Overcast Clouds', icon: `04${dayNight}`, code: 804}; - if(c > 0.50) return {label: 'Broken Clouds', icon: `04${dayNight}`, code: 803}; - if(c > 0.25) return {label: 'Scattered Clouds', icon: `03${dayNight}`, code: 802}; - if(c > 0.10) return {label: 'Few Clouds', icon: `02${dayNight}`, code: 801}; - return {label: 'Clear Sky', icon: `01${dayNight}`, code: 800}; + if(c > 0.85) return {label: 'Overcast Clouds', icon: `04${dayNight}`}; + if(c > 0.50) return {label: 'Broken Clouds', icon: `04${dayNight}`}; + if(c > 0.25) return {label: 'Scattered Clouds', icon: `03${dayNight}`}; + if(c > 0.10) return {label: 'Few Clouds', icon: `02${dayNight}`}; + return {label: 'Clear Sky', icon: `01${dayNight}`}; } diff --git a/server/src/sensors.mjs b/server/src/sensors.mjs index fa2ce25..d61b33a 100644 --- a/server/src/sensors.mjs +++ b/server/src/sensors.mjs @@ -44,9 +44,10 @@ export async function queryHourly(start, end) { const results = await query(c, `avg_over_time({__name__!=""}[1h])`, s, e); results.forEach(r => { r.values.forEach(([ts, val]) => { + if(r.metric.__name__.startsWith('system_')) return; const time = new Date(ts * 1000).toISOString().slice(0, 13) + ':00'; if (!byTime[time]) byTime[time] = {time}; - byTime[time][r.metric.__name__] = parseFloat(val); + byTime[time][r.metric.__name__.replace('weather_', '')] = parseFloat(val); }); }); return Object.values(byTime).sort((a, b) => a.time.localeCompare(b.time)); @@ -68,7 +69,7 @@ export async function queryDaily(start, end) { r.values.forEach(([ts, val]) => { const time = new Date(ts * 1000).toISOString().slice(0, 10); if (!byTime[time]) byTime[time] = {time}; - byTime[time][r.metric.__name__] = parseFloat(val); + byTime[time][r.metric.__name__.replace('weather_', '')] = parseFloat(val); }); });