From efd08cbabe3cc32378ebb36e292631a08349fd4d Mon Sep 17 00:00:00 2001 From: ztimson Date: Fri, 26 Jun 2026 01:31:19 -0400 Subject: [PATCH] Graph fixes --- client/src/components/ForecastStrip.vue | 3 +-- client/src/views/Dashboard.vue | 4 ++-- server/src/forecast.mjs | 10 ++++++++++ server/src/openmeteo.mjs | 2 +- server/src/server.mjs | 4 +--- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/client/src/components/ForecastStrip.vue b/client/src/components/ForecastStrip.vue index 261e3a2..e1930ec 100644 --- a/client/src/components/ForecastStrip.vue +++ b/client/src/components/ForecastStrip.vue @@ -80,8 +80,7 @@ onMounted(async () => {
-
-
+
diff --git a/client/src/views/Dashboard.vue b/client/src/views/Dashboard.vue index 4aad0e2..2a27d46 100644 --- a/client/src/views/Dashboard.vue +++ b/client/src/views/Dashboard.vue @@ -171,9 +171,9 @@ onUnmounted(() => { - - + +
OpenAPI Docs | ZaksCode diff --git a/server/src/forecast.mjs b/server/src/forecast.mjs index 1365beb..708b0a2 100644 --- a/server/src/forecast.mjs +++ b/server/src/forecast.mjs @@ -2,10 +2,17 @@ import {queryHourly, getCoords, queryCurrent} from './influx.mjs'; import {getCelestialCurrent} from './celestial.mjs'; import {getWeatherCondition} from './openweather.mjs'; import {localDateStr} from './config.mjs'; +import {uvLabel} from './openmeteo.mjs'; export let lastForecast = { ts: 0, slots: [], summary: null } export const forecastTTL = 5 * 60 * 60_000 +function estimateUV(sunElevation, cloudFraction) { + if (sunElevation <= 0) return 0; + const clearSkyUV = Math.sin((sunElevation * Math.PI) / 180) * 12; + return Math.round(clearSkyUV * (1 - cloudFraction * 0.75) * 10) / 10; +} + function linearTrend(values) { const n = values.length; if (n < 2) return 0; @@ -117,6 +124,7 @@ export async function get24HourForecast(currentSensors) { const temperature = Math.round(bgTemp * 10) / 10; const humidity = forecastHumidity(seedAbsHum, temperature); const wind_speed = forecastWind(seedWind, pressureTrend); + const uv_index = estimateUV(celestial.sun_elevation ?? 0, clouds); const celestial = getCelestialCurrent(coords.latitude, coords.longitude, time); const snapshot = { @@ -131,6 +139,8 @@ export async function get24HourForecast(currentSensors) { wind_speed, clouds, precipitation_chance: Math.round(weather.precipChance * (1 - i * 0.02) * 100), + uv_index, + uv_index_label: uvLabel(uv_index), ...celestial }; diff --git a/server/src/openmeteo.mjs b/server/src/openmeteo.mjs index bbee248..56967c6 100644 --- a/server/src/openmeteo.mjs +++ b/server/src/openmeteo.mjs @@ -80,7 +80,7 @@ function absoluteHumidity(tempC, humidity) { return Math.round((humidity / 100 * svp * 2165) / (tempC + 273.15) * 1000) / 1000 } -function uvLabel(uv) { +export function uvLabel(uv) { if (uv < 3) return 'Low' if (uv < 6) return 'Moderate' if (uv < 8) return 'High' diff --git a/server/src/server.mjs b/server/src/server.mjs index 159f9e1..7c15f41 100644 --- a/server/src/server.mjs +++ b/server/src/server.mjs @@ -56,15 +56,13 @@ app.get('/api/current', async (req, res) => { const space = getCelestialCurrent(coords.latitude, coords.longitude) const condition = getWeatherCondition(Object.assign(sensors, space)) - console.time(); const forecast = await getForecast(); - console.timeEnd(); - console.log(forecast); const merged = { ...(forecast?.summary ? { precipitation_chance: forecast.summary.precipitation_chance, temperature_max: forecast.summary.temperature_max, temperature_min: forecast.summary.temperature_min, + uv_index_max: forecast.summary.uv_index, } : {}), ...condition, ...sensors,