Fixes
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
// forecast.mjs
|
// forecast.mjs
|
||||||
import {queryHourly, getCoords, queryCurrent} from './influx.mjs';
|
import {queryHourly, getCoords, queryCurrent} from './influx.mjs';
|
||||||
import { getCelestialForecast } from './celestial.mjs';
|
import {getCelestialCurrent, getCelestialForecast} from './celestial.mjs';
|
||||||
import {getWeatherCondition} from './openweather.mjs';
|
import {getWeatherCondition} from './openweather.mjs';
|
||||||
|
|
||||||
export let lastForecast = { ts: 0, slots: [], summary: null }
|
export let lastForecast = { ts: 0, slots: [], summary: null }
|
||||||
@@ -151,9 +151,9 @@ export async function get24HourForecast(currentSensors) {
|
|||||||
const humidity = forecastHumidity(seedAbsHum, temperature);
|
const humidity = forecastHumidity(seedAbsHum, temperature);
|
||||||
const wind_speed = forecastWind(seedWind, pressureTrend);
|
const wind_speed = forecastWind(seedWind, pressureTrend);
|
||||||
|
|
||||||
|
const celestial = getCelestialCurrent(coords.latitude, coords.longitude, time);
|
||||||
const snapshot = {
|
const snapshot = {
|
||||||
time,
|
time,
|
||||||
daytime: false,
|
|
||||||
temperature,
|
temperature,
|
||||||
humidity,
|
humidity,
|
||||||
humidity_abs: absoluteHumidity(temperature, humidity),
|
humidity_abs: absoluteHumidity(temperature, humidity),
|
||||||
@@ -163,17 +163,15 @@ export async function get24HourForecast(currentSensors) {
|
|||||||
pressure_hpa: Math.round(pressure * 100) / 100,
|
pressure_hpa: Math.round(pressure * 100) / 100,
|
||||||
wind_speed,
|
wind_speed,
|
||||||
clouds,
|
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));
|
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
|
// 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) {
|
if (slot.sunrise && slot.sunset) {
|
||||||
const t = slot.time instanceof Date ? slot.time.getTime() : new Date(slot.time).getTime();
|
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();
|
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);
|
slot.humidity_abs = absoluteHumidity(slot.temperature, slot.humidity);
|
||||||
}
|
}
|
||||||
|
|
||||||
return enriched;
|
return slots;
|
||||||
}
|
}
|
||||||
|
|
||||||
function summarise(slots) {
|
function summarise(slots) {
|
||||||
|
|||||||
Reference in New Issue
Block a user