diff --git a/scripts/check_amsc.py b/scripts/check_amsc.py deleted file mode 100644 index e492f36a..00000000 --- a/scripts/check_amsc.py +++ /dev/null @@ -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") diff --git a/src/utils/telegram_push.py b/src/utils/telegram_push.py index d7814c96..2563394b 100644 --- a/src/utils/telegram_push.py +++ b/src/utils/telegram_push.py @@ -1471,7 +1471,18 @@ def _build_airport_status_message( 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 {} max_so_far = airport.get("max_so_far") 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 +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 # read recent city cache instead of acting as an upstream observation producer. _AIRPORT_PUSH_INTERVAL = {