今日实测最高改为从 airport_obs_log 取值,延长保留至 24h
不再依赖 city_weather.current.max_so_far(可能来自 METAR 等非机场源), 直接从 airport_obs_log 的机场站点观测历史中计算当日最高温及时间。 obs_log 保留期从 2h 延长到 24h 以支撑跨天查询。 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', '-2 hours')"
|
"DELETE FROM airport_obs_log WHERE created_at < datetime('now', '-24 hours')"
|
||||||
)
|
)
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
|
|||||||
@@ -763,14 +763,40 @@ 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 = current.get("max_so_far")
|
max_so_far, max_temp_time = _get_airport_daily_high(city)
|
||||||
max_temp_time = current.get("max_temp_time")
|
|
||||||
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):
|
||||||
|
"""Get today's observed high from airport_obs_log for this city."""
|
||||||
|
icao = HIGH_FREQ_AIRPORT_ICAO.get(city, "")
|
||||||
|
if not icao:
|
||||||
|
return None, None
|
||||||
|
try:
|
||||||
|
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:
|
||||||
|
from datetime import datetime
|
||||||
|
dt = datetime.fromisoformat(str(obs_time))
|
||||||
|
time_str = dt.strftime("%H:%M")
|
||||||
|
except Exception:
|
||||||
|
time_str = str(obs_time)[:5] if obs_time else ""
|
||||||
|
return round(float(temp_c), 1), time_str
|
||||||
|
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)
|
||||||
_AIRPORT_PUSH_INTERVAL = {
|
_AIRPORT_PUSH_INTERVAL = {
|
||||||
"seoul": 60, # AMOS 1-min
|
"seoul": 60, # AMOS 1-min
|
||||||
|
|||||||
Reference in New Issue
Block a user