修复电报推送跑道高点使用机场METAR而非跑道传感器数据
_get_airport_daily_high 对 AMSC/AMOS 跑道城市优先从 runway_plate_history 取结算跑道的历史最高温
This commit is contained in:
@@ -1,12 +0,0 @@
|
|||||||
from src.database.db_manager import DBManager
|
|
||||||
db = DBManager()
|
|
||||||
for c in ["beijing","guangzhou","shanghai","chengdu","chongqing"]:
|
|
||||||
r = db.get_latest_raw_observation("amsc_awos", c)
|
|
||||||
if r:
|
|
||||||
p = r["payload"]
|
|
||||||
o = p.get("observation_time", "?")
|
|
||||||
pts = p.get("runway_obs", {}).get("point_temperatures", [])
|
|
||||||
tmax = [x["target_runway_max"] for x in pts if x.get("target_runway_max")]
|
|
||||||
print(c, o[:19], "tmax=", max(tmax) if tmax else "?")
|
|
||||||
else:
|
|
||||||
print(c, "no data")
|
|
||||||
@@ -1471,7 +1471,18 @@ def _build_airport_status_message(
|
|||||||
|
|
||||||
|
|
||||||
def _get_airport_daily_high(city_weather: Dict[str, Any]):
|
def _get_airport_daily_high(city_weather: Dict[str, Any]):
|
||||||
"""Get today's observed high from METAR/AMOS airport history."""
|
"""Get today's observed high from METAR/AMOS airport history.
|
||||||
|
|
||||||
|
For runway cities, prefers the settlement runway's max from runway_plate_history.
|
||||||
|
Otherwise falls back to airport_current.max_so_far.
|
||||||
|
"""
|
||||||
|
amos = city_weather.get("amos") or {}
|
||||||
|
has_runway = bool((amos.get("runway_obs") or {}).get("point_temperatures"))
|
||||||
|
if has_runway:
|
||||||
|
runway_max = _runway_history_daily_max(city_weather, city_weather.get("city") or "")
|
||||||
|
if runway_max is not None:
|
||||||
|
return runway_max, None
|
||||||
|
|
||||||
airport = city_weather.get("airport_current") or {}
|
airport = city_weather.get("airport_current") or {}
|
||||||
max_so_far = airport.get("max_so_far")
|
max_so_far = airport.get("max_so_far")
|
||||||
max_time = airport.get("max_temp_time")
|
max_time = airport.get("max_temp_time")
|
||||||
@@ -1483,6 +1494,27 @@ def _get_airport_daily_high(city_weather: Dict[str, Any]):
|
|||||||
return max_so_far, max_time
|
return max_so_far, max_time
|
||||||
|
|
||||||
|
|
||||||
|
def _runway_history_daily_max(city_weather: Dict[str, Any], city: str) -> Optional[float]:
|
||||||
|
"""Compute today's runway high from runway_plate_history."""
|
||||||
|
history = city_weather.get("runway_plate_history")
|
||||||
|
if not isinstance(history, dict) or not history:
|
||||||
|
return None
|
||||||
|
settlement_pair = _settlement_runway_for_city(city)
|
||||||
|
if settlement_pair:
|
||||||
|
settlement_key = f"{settlement_pair[0]}/{settlement_pair[1]}"
|
||||||
|
settlement_pts = history.get(settlement_key)
|
||||||
|
if settlement_pts:
|
||||||
|
temps = [p.get("temp") for p in settlement_pts if isinstance(p, dict) and p.get("temp") is not None]
|
||||||
|
if temps:
|
||||||
|
return round(max(temps), 1)
|
||||||
|
# Fallback: max across all runways
|
||||||
|
all_temps = []
|
||||||
|
for pts in history.values():
|
||||||
|
if isinstance(pts, list):
|
||||||
|
all_temps.extend(p.get("temp") for p in pts if isinstance(p, dict) and p.get("temp") is not None)
|
||||||
|
return round(max(all_temps), 1) if all_temps else None
|
||||||
|
|
||||||
|
|
||||||
# Per-city push interval. The loop wakes every minute, but Telegram should
|
# Per-city push interval. The loop wakes every minute, but Telegram should
|
||||||
# read recent city cache instead of acting as an upstream observation producer.
|
# read recent city cache instead of acting as an upstream observation producer.
|
||||||
_AIRPORT_PUSH_INTERVAL = {
|
_AIRPORT_PUSH_INTERVAL = {
|
||||||
|
|||||||
Reference in New Issue
Block a user