This commit is contained in:
2026-06-24 17:18:49 -04:00
parent 704424530b
commit fdb752073f

View File

@@ -1,6 +1,6 @@
// forecast.mjs
import {queryHourly, getCoords, queryCurrent} from './influx.mjs';
import { getCelestialForecast } from './celestial.mjs';
import {getCelestialCurrent, getCelestialForecast} from './celestial.mjs';
import {getWeatherCondition} from './openweather.mjs';
export let lastForecast = { ts: 0, slots: [], summary: null }
@@ -151,9 +151,9 @@ export async function get24HourForecast(currentSensors) {
const humidity = forecastHumidity(seedAbsHum, temperature);
const wind_speed = forecastWind(seedWind, pressureTrend);
const celestial = getCelestialCurrent(coords.latitude, coords.longitude, time);
const snapshot = {
time,
daytime: false,
temperature,
humidity,
humidity_abs: absoluteHumidity(temperature, humidity),
@@ -163,17 +163,15 @@ export async function get24HourForecast(currentSensors) {
pressure_hpa: Math.round(pressure * 100) / 100,
wind_speed,
clouds,
precipitation_chance: Math.round(weather.precipChance * (1 - i * 0.02) * 100), // confidence decays
precipitation_chance: Math.round(weather.precipChance * (1 - i * 0.02) * 100),
...celestial
};
return Object.assign(snapshot, getWeatherCondition(snapshot));
});
// Pass through getCelestialForecast to enrich sun/moon data
const enriched = getCelestialForecast(coords.latitude, coords.longitude, slots);
// Second pass — apply solar heating now that we have sun_elevation per slot
for (const slot of enriched) {
for (const slot of slots) {
if (slot.sunrise && slot.sunset) {
const t = slot.time instanceof Date ? slot.time.getTime() : new Date(slot.time).getTime();
const rise = slot.sunrise instanceof Date ? slot.sunrise.getTime() : new Date(slot.sunrise).getTime();
@@ -193,7 +191,7 @@ export async function get24HourForecast(currentSensors) {
slot.humidity_abs = absoluteHumidity(slot.temperature, slot.humidity);
}
return enriched;
return slots;
}
function summarise(slots) {