Added daytime property
This commit is contained in:
@@ -153,6 +153,7 @@ export async function get24HourForecast(currentSensors) {
|
||||
|
||||
const snapshot = {
|
||||
time: time.toISOString().slice(0, 16), // "YYYY-MM-DDTHH:MM"
|
||||
daytime: false,
|
||||
temperature,
|
||||
humidity,
|
||||
humidity_abs: absoluteHumidity(temperature, humidity),
|
||||
@@ -173,6 +174,13 @@ export async function get24HourForecast(currentSensors) {
|
||||
|
||||
// Second pass — apply solar heating now that we have sun_elevation per slot
|
||||
for (const slot of enriched) {
|
||||
if (slot.sunrise && slot.sunset) {
|
||||
const t = new Date(slot.time).getTime();
|
||||
slot.daytime = t >= new Date(slot.sunrise).getTime() && t < new Date(slot.sunset).getTime();
|
||||
} else {
|
||||
slot.daytime = (slot.sun_elevation ?? 0) > 0;
|
||||
}
|
||||
|
||||
const solar = solarTempDelta(slot.sun_elevation ?? 0, slot.clouds);
|
||||
const cool = slot.daytime ? 0 : nocturnalCooling(slot.clouds);
|
||||
slot.temperature = Math.round((slot.temperature + solar - cool) * 10) / 10;
|
||||
@@ -198,7 +206,8 @@ function summarise(slots) {
|
||||
// Most frequent label/code by occurrence
|
||||
const labelCount = {}
|
||||
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 label = Object.entries(labelCount).filter(row => row.daytime)
|
||||
.sort((a, b) => b[1] - a[1])[0][0]
|
||||
const dominant = slots.find(s => s.label === label)
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user