Fix Turkey MGM panel history
This commit is contained in:
@@ -6,7 +6,11 @@ from src.data_collection.city_registry import ALIASES, CITY_REGISTRY
|
||||
from src.data_collection.city_time import CITY_TIME_ZONES, get_city_utc_offset_seconds
|
||||
from src.data_collection import metar_sources
|
||||
from src.data_collection.metar_sources import MetarSourceMixin
|
||||
from web.analysis_service import _build_city_detail_payload, _build_intraday_meteorology
|
||||
from web.analysis_service import (
|
||||
_build_city_detail_payload,
|
||||
_build_intraday_meteorology,
|
||||
_should_build_country_network_snapshot,
|
||||
)
|
||||
from web.core import CITIES
|
||||
|
||||
|
||||
@@ -166,6 +170,46 @@ def test_turkey_mgm_primary_today_obs_uses_mgm_airport_history_not_metar():
|
||||
assert snapshot["airport_primary_today_obs"] == [{"time": "14:56", "temp": 17.3}]
|
||||
|
||||
|
||||
def test_panel_mode_still_builds_turkey_mgm_airport_snapshot():
|
||||
raw = {
|
||||
"mgm": {
|
||||
"obs_time": "2026-05-29T11:56:00Z",
|
||||
"current": {"temp": 17.3},
|
||||
}
|
||||
}
|
||||
|
||||
assert (
|
||||
_should_build_country_network_snapshot(
|
||||
"ankara", raw, is_panel_mode=True, is_market_mode=False
|
||||
)
|
||||
is True
|
||||
)
|
||||
assert (
|
||||
_should_build_country_network_snapshot(
|
||||
"istanbul", raw, is_panel_mode=True, is_market_mode=False
|
||||
)
|
||||
is True
|
||||
)
|
||||
assert (
|
||||
_should_build_country_network_snapshot(
|
||||
"guangzhou", raw, is_panel_mode=True, is_market_mode=False
|
||||
)
|
||||
is False
|
||||
)
|
||||
assert (
|
||||
_should_build_country_network_snapshot(
|
||||
"ankara", raw, is_panel_mode=False, is_market_mode=False
|
||||
)
|
||||
is True
|
||||
)
|
||||
assert (
|
||||
_should_build_country_network_snapshot(
|
||||
"ankara", raw, is_panel_mode=True, is_market_mode=True
|
||||
)
|
||||
is False
|
||||
)
|
||||
|
||||
|
||||
def test_nearby_station_timing_marks_stale_rows_unusable_for_network_signal():
|
||||
anchor_time = datetime.now(timezone.utc).replace(microsecond=0)
|
||||
fresh_time = anchor_time + timedelta(minutes=20)
|
||||
|
||||
+30
-2
@@ -105,6 +105,29 @@ AMSC_SETTLEMENT_RUNWAY_TARGETS: Dict[str, str] = {
|
||||
}
|
||||
|
||||
|
||||
def _should_build_country_network_snapshot(
|
||||
city: str,
|
||||
raw: Dict[str, Any],
|
||||
*,
|
||||
is_panel_mode: bool,
|
||||
is_market_mode: bool,
|
||||
) -> bool:
|
||||
if is_market_mode:
|
||||
return False
|
||||
if not is_panel_mode:
|
||||
return True
|
||||
|
||||
city_lower = str(city or "").strip().lower()
|
||||
if city_lower not in TURKISH_MGM_CITIES:
|
||||
return False
|
||||
|
||||
return bool(
|
||||
(raw or {}).get("mgm")
|
||||
or (raw or {}).get("mgm_today_obs")
|
||||
or (raw or {}).get("mgm_nearby")
|
||||
)
|
||||
|
||||
|
||||
def _mgm_hourly_high(mgm: Dict[str, Any]) -> Optional[float]:
|
||||
hourly = mgm.get("hourly") if isinstance(mgm, dict) else []
|
||||
if not isinstance(hourly, list):
|
||||
@@ -492,6 +515,7 @@ def _build_intraday_meteorology(data: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"medium",
|
||||
"high",
|
||||
}
|
||||
|
||||
structural_cap = False
|
||||
if taf_signal.get("available") or taf_suppression:
|
||||
available_layers += 1
|
||||
@@ -815,7 +839,12 @@ def _analyze(
|
||||
risk = CITY_RISK_PROFILES.get(city, {})
|
||||
network_snapshot = (
|
||||
build_country_network_snapshot(city, raw)
|
||||
if not is_panel_mode and not is_market_mode
|
||||
if _should_build_country_network_snapshot(
|
||||
city,
|
||||
raw,
|
||||
is_panel_mode=is_panel_mode,
|
||||
is_market_mode=is_market_mode,
|
||||
)
|
||||
else {}
|
||||
)
|
||||
|
||||
@@ -2298,4 +2327,3 @@ def _build_city_market_scan_payload(
|
||||
"selected_date": target_date or local_date,
|
||||
"fetched_at": data.get("updated_at"),
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user