Graph fixes

This commit is contained in:
2026-06-26 01:31:19 -04:00
parent 738f13e745
commit efd08cbabe
5 changed files with 15 additions and 8 deletions

View File

@@ -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
};