Fixes
This commit is contained in:
@@ -166,12 +166,14 @@ export async function get24HourForecast(currentSensors) {
|
||||
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));
|
||||
});
|
||||
|
||||
// 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 slots) {
|
||||
for (const slot of enriched) {
|
||||
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();
|
||||
@@ -191,27 +193,23 @@ export async function get24HourForecast(currentSensors) {
|
||||
slot.humidity_abs = absoluteHumidity(slot.temperature, slot.humidity);
|
||||
}
|
||||
|
||||
return slots;
|
||||
return enriched;
|
||||
}
|
||||
|
||||
function summarise(slots) {
|
||||
if (!slots.length) return null
|
||||
const daytimeSlots = slots.filter(s => s.daytime)
|
||||
const source = daytimeSlots.length ? daytimeSlots : slots // fallback if no daytime
|
||||
|
||||
const temps = source.map(s => s.temperature).filter(Number.isFinite)
|
||||
const precips = source.map(s => s.precipitation_chance).filter(Number.isFinite)
|
||||
const winds = source.map(s => s.wind_speed).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)
|
||||
const temps = slots.map(s => s.temperature).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)
|
||||
const solar = slots.map(s => s.solar_wm2).filter(Number.isFinite)
|
||||
|
||||
// Most frequent label/code by occurrence
|
||||
const labelCount = {}
|
||||
for (const s of source) {
|
||||
labelCount[s.label] = (labelCount[s.label] || 0) + 1
|
||||
}
|
||||
for (const s of slots) labelCount[s.label] = (labelCount[s.label] || 0) + 1
|
||||
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 {
|
||||
time: slots[0].time,
|
||||
|
||||
Reference in New Issue
Block a user