refactor simplify index weather card summary

Show a single natural sentence: "Today 15–28°C, dry." or "Tomorrow 12–22°C, 3.2 mm rain." Switch to tomorrow after 4 PM. Remove the static heading and verbose multi-part conditions.

Commit
b9ef6e91516876c82c190a1142fff22ed310e08f
Author
gpt-5.6-sol high <agent@openai.com>
Author date
Committer
gpt-5.6-sol high <agent@openai.com>
Committer date
Changed files
roles/dashboard/public/js/dashboard/weather-forecast.js
index 58829a97..d41c929d 100644..100644
@@ -7,53 +7,40 @@
7 7 const summaryEl = document.querySelector("[data-weather-summary]");
8 8 if (!summaryEl) return;
9 9
10 Removed: const now = Date.now();
11 Removed:
12 Removed: // Find current point
13 Removed: let closest = points[0];
14 Removed: let minDiff = Infinity;
15 Removed: for (const p of points) {
16 Removed: const diff = Math.abs(new Date(p.timestamp).getTime() - now);
17 Removed: if (diff < minDiff) {
18 Removed: minDiff = diff;
19 Removed: closest = p;
20 Removed: }
10 Added: const now = new Date();
11 Added: // Summarise today if before 4 PM, otherwise tomorrow
12 Added: const targetDate = new Date(now);
13 Added: if (now.getHours() >= 16) {
14 Added: targetDate.setDate(targetDate.getDate() + 1);
21 15 }
22 16
23 Removed: if (!closest || closest.temperature == null) {
24 Removed: summaryEl.textContent = "No weather data available.";
25 Removed: return;
26 Removed: }
17 Added: const dayPoints = points.filter(p => {
18 Added: const d = new Date(p.timestamp);
19 Added: return d.getFullYear() === targetDate.getFullYear()
20 Added: && d.getMonth() === targetDate.getMonth()
21 Added: && d.getDate() === targetDate.getDate();
22 Added: });
27 23
28 Removed: // Current conditions sentence
29 Removed: const currentTemp = closest.temperature.toFixed(0);
30 Removed: const currentHumidity = closest.humidity != null ? Math.round(closest.humidity) : null;
31 Removed: let currentSentence = `Currently ${currentTemp}°C`;
32 Removed: if (currentHumidity != null) currentSentence += `, ${currentHumidity}% humidity`;
33 Removed: if (closest.rain != null && closest.rain > 0) currentSentence += `, ${closest.rain.toFixed(1)} mm rain`;
34 Removed: currentSentence += ".";
35 Removed:
36 Removed: // 48h trend: compute min, max temp and total rain
37 Removed: const futurePoints = points.filter(p => new Date(p.timestamp).getTime() >= now);
38 Removed: if (!futurePoints.length) {
39 Removed: summaryEl.textContent = currentSentence;
24 Added: if (!dayPoints.length) {
25 Added: summaryEl.textContent = "No forecast available.";
40 26 return;
41 27 }
42 28
43 Removed: const temps = futurePoints.map(p => p.temperature).filter(t => t != null);
44 Removed: const rains = futurePoints.map(p => p.rain || 0);
45 Removed: const minTemp = Math.min(...temps).toFixed(0);
46 Removed: const maxTemp = Math.max(...temps).toFixed(0);
29 Added: const temps = dayPoints.map(p => p.temperature).filter(t => t != null);
30 Added: const rains = dayPoints.map(p => p.rain || 0);
47 31 const totalRain = rains.reduce((a, b) => a + b, 0);
32 Added: const minTemp = Math.round(Math.min(...temps));
33 Added: const maxTemp = Math.round(Math.max(...temps));
48 34
49 Removed: let trendSentence = `Next 48h: ${minTemp}–${maxTemp}°C`;
35 Added: const label = now.getHours() >= 16 ? "Tomorrow" : "Today";
36 Added: let sentence = `${label} ${minTemp}–${maxTemp}°C`;
50 37 if (totalRain > 0.5) {
51 Removed: trendSentence += `, ${totalRain.toFixed(1)} mm rain expected.`;
38 Added: sentence += `, ${totalRain.toFixed(1)} mm rain.`;
52 39 } else {
53 Removed: trendSentence += ", dry.";
40 Added: sentence += ", dry.";
54 41 }
55 42
56 Removed: summaryEl.textContent = `${currentSentence} ${trendSentence}`;
43 Added: summaryEl.textContent = sentence;
57 44 }
58 45
59 46 // Chart.js plugin to shade night periods (21:00–06:00)
roles/dashboard/templates/dashboard/index.html.ep
index 716aca39..87ffc1df 100644..100644
@@ -34,10 +34,7 @@
34 34 <a href="/weather" class="text-decoration-none text-reset d-block">
35 35 <div class="card" data-weather-forecast>
36 36 <div class="card-body py-2 px-3">
37 Removed: <div class="mb-1">
38 Removed: <h2 class="h6 fw-bold mb-0">Weather in Versonnex</h2>
39 Removed: <p class="text-body-secondary small mb-0" data-weather-summary>Loading forecast…</p>
40 Removed: </div>
37 Added: <p class="text-body-secondary small fw-semibold mb-1" data-weather-summary>Loading forecast…</p>
41 38 <div class="chart-wrap" style="height: 180px;">
42 39 <canvas id="chart-weather-forecast" role="img" aria-label="48-hour weather forecast"></canvas>
43 40 </div>