fix: peak hour sanity check (<6AM=invalid), wind direction always shown

This commit is contained in:
AmandaloveYang
2026-02-18 11:08:41 +08:00
parent 30f86eab89
commit 4464bb3cd4
+7 -2
View File
@@ -92,8 +92,14 @@ def analyze_weather_trend(weather_data, temp_symbol):
diff_max = forecast_high - curr_temp diff_max = forecast_high - curr_temp
# 1. 气温节奏判定 (动态参考峰值时刻) # 1. 气温节奏判定 (动态参考峰值时刻)
# 安全检查:峰值时段如果在凌晨6点前(不合理),使用默认值
last_peak_h = int(peak_hours[-1].split(":")[0]) if peak_hours else 15 last_peak_h = int(peak_hours[-1].split(":")[0]) if peak_hours else 15
first_peak_h = int(peak_hours[0].split(":")[0]) if peak_hours else 13 first_peak_h = int(peak_hours[0].split(":")[0]) if peak_hours else 13
if last_peak_h < 6:
last_peak_h = 15
first_peak_h = 13
# 清空不合理的峰值时段,避免误导
peak_hours = []
if local_hour > last_peak_h: if local_hour > last_peak_h:
# 已经过了预报的峰值时段 # 已经过了预报的峰值时段
@@ -175,8 +181,7 @@ def analyze_weather_trend(weather_data, temp_symbol):
elif fog_codes & set(wx_tokens): elif fog_codes & set(wx_tokens):
insights.append(f"🌫️ <b>有雾/霾</b>:阳光被挡住了,湿度也高,升温会很慢。") insights.append(f"🌫️ <b>有雾/霾</b>:阳光被挡住了,湿度也高,升温会很慢。")
# 6. 风向分析 (仅在未进入降温期前显示) # 6. 风向分析(始终显示,风向是重要参考信息)
if not is_peak_passed or local_hour <= last_peak_h + 2:
try: try:
# 优先 METAR,回退 MGM # 优先 METAR,回退 MGM
metar_wind = metar.get("current", {}).get("wind_dir") metar_wind = metar.get("current", {}).get("wind_dir")