From 0bb3b573e15c70b59c13f67f31180730238d24f1 Mon Sep 17 00:00:00 2001 From: "2569718930@qq.com" <2569718930@qq.com> Date: Tue, 7 Apr 2026 13:02:45 +0800 Subject: [PATCH] Filter invalid NMC wind placeholders from map labels --- frontend/hooks/useLeafletMap.ts | 9 +++++++-- src/data_collection/nmc_sources.py | 11 +++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/frontend/hooks/useLeafletMap.ts b/frontend/hooks/useLeafletMap.ts index 17f13a7a..7a2b5a77 100644 --- a/frontend/hooks/useLeafletMap.ts +++ b/frontend/hooks/useLeafletMap.ts @@ -78,6 +78,11 @@ function createMarkerIcon( } function buildNearbyIconHtml(detail: CityDetail, station: NearbyStation) { + const sanitizeWindText = (value?: string | null) => { + const text = String(value || "").trim(); + if (!text || text === "9999") return ""; + return text; + }; const symbol = detail.temp_symbol || "°C"; const rawLabel = station.station_label || @@ -92,8 +97,8 @@ function buildNearbyIconHtml(detail: CityDetail, station: NearbyStation) { ? String(rawLabel).replace(/\s*\(NMC\)$/i, "区域实况 (NMC)") : rawLabel; let windHtml = ""; - const windDirectionText = String(station.wind_direction_text || "").trim(); - const windPowerText = String(station.wind_power_text || "").trim(); + const windDirectionText = sanitizeWindText(station.wind_direction_text); + const windPowerText = sanitizeWindText(station.wind_power_text); if (station.wind_dir != null) { const rotation = (Number(station.wind_dir) + 180) % 360; diff --git a/src/data_collection/nmc_sources.py b/src/data_collection/nmc_sources.py index 131a7e5e..066958ed 100644 --- a/src/data_collection/nmc_sources.py +++ b/src/data_collection/nmc_sources.py @@ -45,6 +45,13 @@ NMC_CITY_REFERENCES: Dict[str, Dict[str, Any]] = { class NmcSourceMixin: + @staticmethod + def _nmc_optional_text(value: Any) -> Optional[str]: + text = str(value or "").strip() + if text in ("", "9999"): + return None + return text + @staticmethod def _nmc_optional_float(value: Any) -> Optional[float]: if value in (None, "", "9999", 9999, 9999.0): @@ -138,8 +145,8 @@ class NmcSourceMixin: "rain": self._nmc_optional_float(weather.get("rain")), "airpressure": self._nmc_optional_float(weather.get("airpressure")), "wx_desc": weather.get("info"), - "wind_direction": (payload.get("wind") or {}).get("direct"), - "wind_power": (payload.get("wind") or {}).get("power"), + "wind_direction": self._nmc_optional_text((payload.get("wind") or {}).get("direct")), + "wind_power": self._nmc_optional_text((payload.get("wind") or {}).get("power")), }, } with self._nmc_cache_lock: