今日实测最高改用 airport_current.max_so_far(METAR历史观测)
项目已有 airport_current 字段存储 METAR/AMOS 当天最高温及时间, 无需从 obs_log 自建。obs_log 保留期恢复为 2 小时。 Tested: pytest 176 passed, ruff check 通过
This commit is contained in:
@@ -1861,7 +1861,7 @@ class DBManager:
|
|||||||
temp_c, wind_kt, pressure_hpa, str(obs_time)),
|
temp_c, wind_kt, pressure_hpa, str(obs_time)),
|
||||||
)
|
)
|
||||||
conn.execute(
|
conn.execute(
|
||||||
"DELETE FROM airport_obs_log WHERE created_at < datetime('now', '-24 hours')"
|
"DELETE FROM airport_obs_log WHERE created_at < datetime('now', '-2 hours')"
|
||||||
)
|
)
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
|
|||||||
+10
-24
@@ -763,38 +763,24 @@ def _build_airport_status_message(
|
|||||||
lines.append(f"当前实测:{station_temp:.1f}°C")
|
lines.append(f"当前实测:{station_temp:.1f}°C")
|
||||||
if deb_pred is not None:
|
if deb_pred is not None:
|
||||||
lines.append(f"今日DEB预报最高:{deb_pred:.1f}°C")
|
lines.append(f"今日DEB预报最高:{deb_pred:.1f}°C")
|
||||||
max_so_far, max_temp_time = _get_airport_daily_high(city)
|
max_so_far, max_temp_time = _get_airport_daily_high(city_weather)
|
||||||
if max_so_far is not None:
|
if max_so_far is not None:
|
||||||
time_str = f"({max_temp_time})" if max_temp_time else ""
|
time_str = f"({max_temp_time})" if max_temp_time else ""
|
||||||
lines.append(f"今日实测最高:{max_so_far:.1f}°C{time_str}")
|
lines.append(f"今日实测最高:{max_so_far:.1f}°C{time_str}")
|
||||||
return "\n".join(lines)
|
return "\n".join(lines)
|
||||||
|
|
||||||
|
|
||||||
def _get_airport_daily_high(city: str):
|
def _get_airport_daily_high(city_weather: Dict[str, Any]):
|
||||||
"""Get today's observed high from airport_obs_log for this city."""
|
"""Get today's observed high from METAR/AMOS airport history."""
|
||||||
icao = HIGH_FREQ_AIRPORT_ICAO.get(city, "")
|
airport = city_weather.get("airport_current") or {}
|
||||||
if not icao:
|
max_so_far = airport.get("max_so_far")
|
||||||
return None, None
|
max_time = airport.get("max_temp_time")
|
||||||
try:
|
if max_so_far is not None:
|
||||||
from src.database.db_manager import DBManager
|
|
||||||
db = DBManager()
|
|
||||||
obs = db.get_airport_obs_recent(icao, minutes=1440) # last 24h
|
|
||||||
if not obs:
|
|
||||||
return None, None
|
|
||||||
best = max(obs, key=lambda r: r.get("temp_c") or -999)
|
|
||||||
temp_c = best.get("temp_c")
|
|
||||||
obs_time = best.get("obs_time") or ""
|
|
||||||
if temp_c is None:
|
|
||||||
return None, None
|
|
||||||
try:
|
try:
|
||||||
from datetime import datetime
|
max_so_far = round(float(max_so_far), 1)
|
||||||
dt = datetime.fromisoformat(str(obs_time))
|
|
||||||
time_str = dt.strftime("%H:%M")
|
|
||||||
except Exception:
|
except Exception:
|
||||||
time_str = str(obs_time)[:5] if obs_time else ""
|
max_so_far = None
|
||||||
return round(float(temp_c), 1), time_str
|
return max_so_far, max_time
|
||||||
except Exception:
|
|
||||||
return None, None
|
|
||||||
|
|
||||||
|
|
||||||
# Per-city push interval matching native data refresh rate (seconds)
|
# Per-city push interval matching native data refresh rate (seconds)
|
||||||
|
|||||||
Reference in New Issue
Block a user