Drop stale observation fields during overlay

This commit is contained in:
2569718930@qq.com
2026-06-15 23:32:47 +08:00
parent 3984e12c44
commit ed0447f408
2 changed files with 13 additions and 3 deletions
+11
View File
@@ -1861,6 +1861,14 @@ def test_stale_ankara_chart_data_overlays_latest_mgm_canonical(monkeypatch):
"report_time": "2026-06-14T09:50:00+00:00", "report_time": "2026-06-14T09:50:00+00:00",
"raw_metar": "METAR LTAC 140950Z 06013KT 9999 16/11 Q1015", "raw_metar": "METAR LTAC 140950Z 06013KT 9999 16/11 Q1015",
}, },
"airport_current": {
"temp": 16.0,
"source_code": "mgm",
"source_label": "MGM",
"obs_time": "2026-06-14T09:50:00+00:00",
"report_time": "2026-06-14T09:50:00+00:00",
"raw_metar": "METAR LTAC 140950Z 06013KT 9999 16/11 Q1015",
},
"airport_primary_today_obs": [{"time": "12:50", "temp": 16.0}], "airport_primary_today_obs": [{"time": "12:50", "temp": 16.0}],
"metar_today_obs": [{"time": "12:50", "temp": 16.0}], "metar_today_obs": [{"time": "12:50", "temp": 16.0}],
"metar_recent_obs": [{"time": "12:50", "temp": 16.0}], "metar_recent_obs": [{"time": "12:50", "temp": 16.0}],
@@ -1918,7 +1926,10 @@ def test_stale_ankara_chart_data_overlays_latest_mgm_canonical(monkeypatch):
assert payload["local_time"] == "17:20" assert payload["local_time"] == "17:20"
assert payload["airport_primary_today_obs"] == [{"time": "17:20", "temp": 19.0}] assert payload["airport_primary_today_obs"] == [{"time": "17:20", "temp": 19.0}]
assert "raw_metar" not in payload["current"] assert "raw_metar" not in payload["current"]
assert "raw_metar" not in payload["airport_primary"]
assert "report_time" not in payload["airport_primary"] assert "report_time" not in payload["airport_primary"]
assert "raw_metar" not in payload["airport_current"]
assert "report_time" not in payload["airport_current"]
assert payload["metar_today_obs"] == [] assert payload["metar_today_obs"] == []
assert payload["metar_recent_obs"] == [] assert payload["metar_recent_obs"] == []
assert payload["metar_status"]["available_for_today"] is False assert payload["metar_status"]["available_for_today"] is False
+2 -3
View File
@@ -423,12 +423,11 @@ def _observation_source_code(block: Any) -> str:
def _merge_latest_observation_block(base_block: Any, latest_block: Dict[str, Any]) -> Dict[str, Any]: def _merge_latest_observation_block(base_block: Any, latest_block: Dict[str, Any]) -> Dict[str, Any]:
base = dict(base_block) if isinstance(base_block, dict) else {} base = dict(base_block) if isinstance(base_block, dict) else {}
latest_source = _observation_source_code(latest_block) latest_source = _observation_source_code(latest_block)
base_source = _observation_source_code(base) if latest_source:
if base_source and latest_source and base_source != latest_source:
base = { base = {
key: value key: value
for key, value in base.items() for key, value in base.items()
if key not in _SOURCE_BOUND_OBSERVATION_FIELDS if key not in _SOURCE_BOUND_OBSERVATION_FIELDS or key in latest_block
} }
return {**base, **latest_block} return {**base, **latest_block}