This commit is contained in:
2026-06-24 17:16:53 -04:00
parent 968cd1a669
commit 704424530b

View File

@@ -166,12 +166,14 @@ export async function get24HourForecast(currentSensors) {
precipitation_chance: Math.round(weather.precipChance * (1 - i * 0.02) * 100), // confidence decays precipitation_chance: Math.round(weather.precipChance * (1 - i * 0.02) * 100), // confidence decays
}; };
Object.assign(snapshot, getCelestialForecast(coords.latitude, coords.longitude, time))
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 slots) { for (const slot of enriched) {
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();
@@ -191,27 +193,23 @@ export async function get24HourForecast(currentSensors) {
slot.humidity_abs = absoluteHumidity(slot.temperature, slot.humidity); slot.humidity_abs = absoluteHumidity(slot.temperature, slot.humidity);
} }
return slots; return enriched;
} }
function summarise(slots) { function summarise(slots) {
if (!slots.length) return null if (!slots.length) return null
const daytimeSlots = slots.filter(s => s.daytime) const temps = slots.map(s => s.temperature).filter(Number.isFinite)
const source = daytimeSlots.length ? daytimeSlots : slots // fallback if no daytime const precips = slots.map(s => s.precipitation_chance).filter(Number.isFinite)
const winds = slots.map(s => s.wind_speed).filter(Number.isFinite)
const temps = source.map(s => s.temperature).filter(Number.isFinite) const gusts = slots.map(s => s.wind_gusts).filter(Number.isFinite)
const precips = source.map(s => s.precipitation_chance).filter(Number.isFinite) const uvs = slots.map(s => s.uv_index).filter(Number.isFinite)
const winds = source.map(s => s.wind_speed).filter(Number.isFinite) const solar = slots.map(s => s.solar_wm2).filter(Number.isFinite)
const gusts = source.map(s => s.wind_gusts).filter(Number.isFinite)
const uvs = source.map(s => s.uv_index).filter(Number.isFinite)
const solar = source.map(s => s.solar_wm2).filter(Number.isFinite)
// Most frequent label/code by occurrence
const labelCount = {} const labelCount = {}
for (const s of source) { for (const s of slots) labelCount[s.label] = (labelCount[s.label] || 0) + 1
labelCount[s.label] = (labelCount[s.label] || 0) + 1
}
const label = Object.entries(labelCount).sort((a, b) => b[1] - a[1])[0][0] const label = Object.entries(labelCount).sort((a, b) => b[1] - a[1])[0][0]
const dominant = source.find(s => s.label === label) const dominant = slots.find(s => s.label === label)
return { return {
time: slots[0].time, time: slots[0].time,