Spaces:
Running
Running
feat: add station observation filtering and update sidebar summary stats with temporal context
Browse files- src/app/page.tsx +2 -0
- src/components/Sidebar.tsx +35 -16
src/app/page.tsx
CHANGED
|
@@ -408,6 +408,8 @@ function EuroMeteoApp() {
|
|
| 408 |
setParameter={setParameter}
|
| 409 |
isOpen={sidebarOpen}
|
| 410 |
setIsOpen={setSidebarOpen}
|
|
|
|
|
|
|
| 411 |
/>
|
| 412 |
|
| 413 |
{/* Main View Shell Container */}
|
|
|
|
| 408 |
setParameter={setParameter}
|
| 409 |
isOpen={sidebarOpen}
|
| 410 |
setIsOpen={setSidebarOpen}
|
| 411 |
+
selectedHour={selectedHour}
|
| 412 |
+
observations={areaObservations}
|
| 413 |
/>
|
| 414 |
|
| 415 |
{/* Main View Shell Container */}
|
src/components/Sidebar.tsx
CHANGED
|
@@ -36,6 +36,8 @@ interface SidebarProps {
|
|
| 36 |
setParameter: (param: string) => void;
|
| 37 |
isOpen: boolean;
|
| 38 |
setIsOpen: (isOpen: boolean) => void;
|
|
|
|
|
|
|
| 39 |
}
|
| 40 |
|
| 41 |
export const Sidebar: React.FC<SidebarProps> = ({
|
|
@@ -51,7 +53,9 @@ export const Sidebar: React.FC<SidebarProps> = ({
|
|
| 51 |
parameter,
|
| 52 |
setParameter,
|
| 53 |
isOpen,
|
| 54 |
-
setIsOpen
|
|
|
|
|
|
|
| 55 |
}) => {
|
| 56 |
// Extract unique countries sorted alphabetically
|
| 57 |
const countries = useMemo(() => {
|
|
@@ -65,8 +69,28 @@ export const Sidebar: React.FC<SidebarProps> = ({
|
|
| 65 |
return stations.filter(st => st.country === selectedCountry);
|
| 66 |
}, [stations, selectedCountry]);
|
| 67 |
|
| 68 |
-
// Count
|
| 69 |
-
const activeCount =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
// Date range constraints (max 31 days)
|
| 72 |
const handleStartDateChange = (newStart: string) => {
|
|
@@ -246,21 +270,16 @@ export const Sidebar: React.FC<SidebarProps> = ({
|
|
| 246 |
|
| 247 |
{/* Footer info & stats */}
|
| 248 |
<div className="border-t border-slate-100 pt-4 flex flex-col gap-3">
|
| 249 |
-
<div className="bg-slate-50 border border-slate-100 rounded-xl p-
|
| 250 |
-
<div className="
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
</div>
|
| 254 |
-
<div className="flex justify-between">
|
| 255 |
-
<span>Total in Domain:</span>
|
| 256 |
-
<span className="text-slate-600">{stations.length}</span>
|
| 257 |
-
</div>
|
| 258 |
</div>
|
| 259 |
|
| 260 |
-
<div className="
|
| 261 |
-
|
| 262 |
-
<
|
| 263 |
-
Includes: Temperature, Precip, Wind, Pressure.
|
| 264 |
</div>
|
| 265 |
</div>
|
| 266 |
</aside>
|
|
|
|
| 36 |
setParameter: (param: string) => void;
|
| 37 |
isOpen: boolean;
|
| 38 |
setIsOpen: (isOpen: boolean) => void;
|
| 39 |
+
selectedHour: number;
|
| 40 |
+
observations?: Record<string, number[]>;
|
| 41 |
}
|
| 42 |
|
| 43 |
export const Sidebar: React.FC<SidebarProps> = ({
|
|
|
|
| 53 |
parameter,
|
| 54 |
setParameter,
|
| 55 |
isOpen,
|
| 56 |
+
setIsOpen,
|
| 57 |
+
selectedHour,
|
| 58 |
+
observations
|
| 59 |
}) => {
|
| 60 |
// Extract unique countries sorted alphabetically
|
| 61 |
const countries = useMemo(() => {
|
|
|
|
| 69 |
return stations.filter(st => st.country === selectedCountry);
|
| 70 |
}, [stations, selectedCountry]);
|
| 71 |
|
| 72 |
+
// Count stations that have actual valid observations for the selected hour
|
| 73 |
+
const activeCount = useMemo(() => {
|
| 74 |
+
if (!observations || Object.keys(observations).length === 0) {
|
| 75 |
+
return filteredStations.length;
|
| 76 |
+
}
|
| 77 |
+
let count = 0;
|
| 78 |
+
filteredStations.forEach((st) => {
|
| 79 |
+
const val = observations[st.id]?.[selectedHour];
|
| 80 |
+
if (val !== undefined && val !== null && !isNaN(val)) {
|
| 81 |
+
count++;
|
| 82 |
+
}
|
| 83 |
+
});
|
| 84 |
+
return count;
|
| 85 |
+
}, [filteredStations, observations, selectedHour]);
|
| 86 |
+
|
| 87 |
+
const hoursAgo = useMemo(() => {
|
| 88 |
+
const selectedDateStr = `${endDate}T${selectedHour.toString().padStart(2, "0")}:00:00Z`;
|
| 89 |
+
const selectedTime = new Date(selectedDateStr).getTime();
|
| 90 |
+
const now = new Date().getTime();
|
| 91 |
+
const diff = now - selectedTime;
|
| 92 |
+
return Math.max(0, Math.floor(diff / (1000 * 60 * 60)));
|
| 93 |
+
}, [endDate, selectedHour]);
|
| 94 |
|
| 95 |
// Date range constraints (max 31 days)
|
| 96 |
const handleStartDateChange = (newStart: string) => {
|
|
|
|
| 270 |
|
| 271 |
{/* Footer info & stats */}
|
| 272 |
<div className="border-t border-slate-100 pt-4 flex flex-col gap-3">
|
| 273 |
+
<div className="bg-slate-50 border border-slate-100 rounded-xl p-4 flex flex-col gap-1.5 text-sm font-medium text-slate-600">
|
| 274 |
+
<div><span className="font-bold text-slate-800">{stations.length}</span> stations found</div>
|
| 275 |
+
<div className="text-blue-600 font-semibold border-b border-slate-200 pb-2 mb-1">Showing: {activeCount} stations</div>
|
| 276 |
+
<div className="text-slate-800 font-bold">{endDate} {selectedHour.toString().padStart(2, "0")}:00 UTC</div>
|
| 277 |
+
<div className="text-slate-500 text-xs">{hoursAgo} hour(s) ago</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 278 |
</div>
|
| 279 |
|
| 280 |
+
<div className="bg-blue-50/50 border border-blue-100/50 rounded-xl p-3 flex gap-2 items-start text-xs font-medium text-slate-600">
|
| 281 |
+
<Info size={14} className="text-blue-500 shrink-0 mt-0.5" />
|
| 282 |
+
<p>Tip: Click map points to view detailed weather plots.</p>
|
|
|
|
| 283 |
</div>
|
| 284 |
</div>
|
| 285 |
</aside>
|