Added frost risk

This commit is contained in:
2026-06-27 18:31:44 -04:00
parent 9471e904ce
commit 30c866b599
6 changed files with 93 additions and 145 deletions

View File

@@ -1,6 +1,7 @@
import {queryHourly, getCoords, queryCurrent} from './sensors.mjs';
import {getCelestialCurrent} from './celestial.mjs';
import {localDateStr} from './config.mjs';
import {frostRisk} from './openweather.mjs';
export let lastForecast = { ts: 0, slots: [], summary: null }
export const forecastTTL = 5 * 60 * 60_000
@@ -188,6 +189,7 @@ export async function get24HourForecast(currentSensors) {
slot.heat_index = Math.round(heatIndex(slot.temperature, slot.humidity) * 100) / 100;
slot.vapor_pressure_deficit = vaporPressureDeficit(slot.temperature, slot.humidity);
slot.humidity_abs = absoluteHumidity(slot.temperature, slot.humidity);
slot.frost_risk = frostRisk(slot.temperature, slot.dew_point, slot.humidity)
slot.solar_wm2 = slot.sun_elevation > 0
? Math.round(Math.sin((slot.sun_elevation * Math.PI) / 180) * 1000 * (1 - slot.clouds * 0.75) * 100) / 100
@@ -252,6 +254,7 @@ function summarise(slots) {
precipitation: avg(fin('precipitation')),
precipitation_chance: Math.round(peak(fin('precipitation_chance'))),
accumulation: finAll('precipitation').reduce((a, b) => a + b, 0),
frost_risk: slots.find(s => s.frost_risk !== 'None')?.frost_risk ?? slots.at(-1)?.frost_risk ?? 'None',
uv_index: peak(fin('uv_index')),
uv_dose: finAll('uv_dose').reduce((a, b) => a + b, 0),
solar_wm2: avg(fin('solar_wm2')),