[Perl] DAQ system for the FAPG.
fix restore night shading with API sunrise/sunset
Check whether any point actually has sun data before using the API path. Fall back to fixed 21:00-06:00 when the database has no sunrise/sunset yet.
roles/dashboard/public/js/dashboard/weather-forecast.js
@@ -70,18 +70,21 @@
70
70
71
71
// Build night intervals from sunrise/sunset pairs
72
72
const nights = [];
73
Removed:
if (sunEvents && sunEvents.length) {
73
Added:
const hasSunData = sunEvents && sunEvents.some(s => s && s.sunrise && s.sunset);
74
Added:
75
Added:
if (hasSunData) {
74
76
// Each point carries the sunrise/sunset for its day
75
77
let nightStart = null;
76
78
for (let i = 0; i < timestamps.length; i++) {
77
79
const t = timestamps[i];
78
80
const sun = sunEvents[i];
79
Removed:
if (!sun || !sun.sunrise || !sun.sunset) continue;
80
Removed:
const sunrise = new Date(sun.sunrise).getTime();
81
Removed:
const sunset = new Date(sun.sunset).getTime();
82
Removed:
const isNight = t < sunrise || t >= sunset;
81
Added:
const sunrise = sun && sun.sunrise ? new Date(sun.sunrise).getTime() : null;
82
Added:
const sunset = sun && sun.sunset ? new Date(sun.sunset).getTime() : null;
83
Added:
const isNight = (sunrise && sunset) ? (t < sunrise || t >= sunset) : null;
83
84
84
Removed:
if (isNight && nightStart === null) {
85
Added:
if (isNight === null) {
86
Added:
// No sun data for this point — treat as continuation
87
Added:
} else if (isNight && nightStart === null) {
85
88
nightStart = i;
86
89
} else if (!isNight && nightStart !== null) {
87
90
nights.push([nightStart, i]);