Updated forecast summary
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
// forecast.mjs
|
||||
import {queryHourly, getCoords, queryCurrent} from './influx.mjs';
|
||||
import { getCelestialForecast } from './celestial.mjs';
|
||||
import {getWeatherCondition} from './openweather.mjs';
|
||||
|
||||
export let lastForecast = { ts: 0, slots: [], summary: null }
|
||||
const TTL = 10 * 60 * 1000
|
||||
@@ -150,7 +151,7 @@ export async function get24HourForecast(currentSensors) {
|
||||
const humidity = forecastHumidity(seedAbsHum, temperature);
|
||||
const wind_speed = forecastWind(seedWind, pressureTrend);
|
||||
|
||||
return {
|
||||
const snapshot = {
|
||||
time: time.toISOString().slice(0, 16), // "YYYY-MM-DDTHH:MM"
|
||||
temperature,
|
||||
humidity,
|
||||
@@ -161,10 +162,10 @@ export async function get24HourForecast(currentSensors) {
|
||||
pressure_hpa: Math.round(pressure * 100) / 100,
|
||||
wind_speed,
|
||||
clouds,
|
||||
precip_chance: Math.round(weather.precipChance * (1 - i * 0.02) * 100), // confidence decays
|
||||
label: weather.label,
|
||||
code: weather.code,
|
||||
precipitation_chance: Math.round(weather.precipChance * (1 - i * 0.02) * 100), // confidence decays
|
||||
};
|
||||
|
||||
return Object.assign(snapshot, getWeatherCondition(snapshot));
|
||||
});
|
||||
|
||||
// Pass through getCelestialForecast to enrich sun/moon data
|
||||
@@ -188,7 +189,7 @@ export async function get24HourForecast(currentSensors) {
|
||||
function summarise(slots) {
|
||||
if (!slots.length) return null
|
||||
const temps = slots.map(s => s.temperature).filter(Number.isFinite)
|
||||
const precips = slots.map(s => s.precip_chance).filter(Number.isFinite)
|
||||
const precips = slots.map(s => s.precipitation_chance).filter(Number.isFinite)
|
||||
const winds = slots.map(s => s.wind_speed).filter(Number.isFinite)
|
||||
const gusts = slots.map(s => s.wind_gusts).filter(Number.isFinite)
|
||||
const uvs = slots.map(s => s.uv_index).filter(Number.isFinite)
|
||||
@@ -202,13 +203,13 @@ function summarise(slots) {
|
||||
|
||||
return {
|
||||
time: slots[0].time.slice(0, 10),
|
||||
label,
|
||||
label: dominant.label,
|
||||
code: dominant.code,
|
||||
icon: dominant.icon ?? null,
|
||||
temperature: Math.max(...temps),
|
||||
temperature_max: Math.max(...temps),
|
||||
temperature_min: Math.min(...temps),
|
||||
precip_chance: Math.round(Math.max(...precips)),
|
||||
precipitation_chance: Math.round(Math.max(...precips)),
|
||||
wind_speed: Math.round(Math.max(...winds) * 10) / 10,
|
||||
wind_gusts: gusts.length ? Math.round(Math.max(...gusts) * 10) / 10 : null,
|
||||
uv_index: uvs.length ? Math.max(...uvs) : null,
|
||||
|
||||
@@ -48,7 +48,7 @@ app.get('/api/current', async (req, res) => {
|
||||
// Merge forecast summary fields — sensor readings take priority
|
||||
const merged = {
|
||||
...(summary ? {
|
||||
precipitation_chance: summary.precip_chance,
|
||||
precipitation_chance: summary.precipitation_chance,
|
||||
temperature_max: summary.temperature_max,
|
||||
temperature_min: summary.temperature_min,
|
||||
uv_index_max: summary.uv_index,
|
||||
|
||||
Reference in New Issue
Block a user