fix: wind analysis cross-validates METAR vs MGM with conflict detection

This commit is contained in:
AmandaloveYang
2026-02-16 11:08:09 +08:00
parent fef9094403
commit c4fc26314d
+46 -22
View File
@@ -178,29 +178,53 @@ def analyze_weather_trend(weather_data, temp_symbol):
# 6. 风向分析 (仅在未进入降温期前显示)
if not is_peak_passed or local_hour <= last_peak_h + 2:
try:
wind_dir = float(metar.get("current", {}).get("wind_dir", 0))
if 315 <= wind_dir or wind_dir <= 45:
# 北风:冷空气
insights.append(f"🌬️ <b>吹北风</b>:从北方来的冷空气,会压制升温。")
elif 135 <= wind_dir <= 225:
# 南风:暖空气
if diff_max > 0.5 or (is_breakthrough and curr_temp >= max_so_far):
if is_peak_passed and not is_breakthrough:
insights.append(f"🔥 <b>吹南风</b>:南方的暖空气还在吹过来,但最热时段已过,后劲不足了。")
# 优先 METAR,回退 MGM
metar_wind = metar.get("current", {}).get("wind_dir")
mgm_wind = mgm.get("current", {}).get("wind_dir")
if metar_wind is not None:
analysis_wind = float(metar_wind)
wind_source = "METAR"
elif mgm_wind is not None:
analysis_wind = float(mgm_wind)
wind_source = "MGM"
else:
analysis_wind = None
wind_source = None
# 两源矛盾检测
if metar_wind is not None and mgm_wind is not None:
metar_f = float(metar_wind)
mgm_f = float(mgm_wind)
diff_angle = abs(metar_f - mgm_f)
if diff_angle > 180:
diff_angle = 360 - diff_angle
if diff_angle > 90:
dirs_name = ["", "东北", "", "东南", "", "西南", "西", "西北"]
m_name = dirs_name[int((metar_f + 22.5) % 360 / 45)]
g_name = dirs_name[int((mgm_f + 22.5) % 360 / 45)]
insights.append(f"⚠️ <b>风向矛盾</b>METAR 测到{m_name}风({metar_f:.0f}°)MGM 测到{g_name}风({mgm_f:.0f}°),相差较大,风向不稳定。")
if analysis_wind is not None:
wd = analysis_wind
if 315 <= wd or wd <= 45:
insights.append(f"🌬️ <b>吹北风</b>{wind_source} {wd:.0f}°):从北方来的冷空气,会压制升温。")
elif 135 <= wd <= 225:
if diff_max > 0.5 or (is_breakthrough and curr_temp >= max_so_far):
if is_peak_passed and not is_breakthrough:
insights.append(f"🔥 <b>吹南风</b>{wind_source} {wd:.0f}°):南方的暖空气还在吹过来,但最热时段已过,后劲不足了。")
else:
status = "温度还有继续上涨的空间" if not is_breakthrough else "可能把温度推得更高"
insights.append(f"🔥 <b>吹南风</b>{wind_source} {wd:.0f}°):南方的暖空气正在吹过来,{status}")
elif 225 < wd < 315:
if wd <= 260:
insights.append(f"🌬️ <b>吹西南风</b>{wind_source} {wd:.0f}°):带有一定暖湿气流,对升温有轻微帮助。")
elif wd >= 280:
insights.append(f"🌬️ <b>吹西北风</b>{wind_source} {wd:.0f}°):偏冷的气流,会拖慢升温。")
else:
status = "温度还有继续上涨的空间" if not is_breakthrough else "可能把温度推得更高"
insights.append(f"🔥 <b>吹南风</b>:南方的暖空气正在吹过来,{status}")
elif 225 < wind_dir < 315:
# 西风/西南风/西北风
if wind_dir <= 260:
insights.append(f"🌬️ <b>吹西南风</b>:带有一定暖湿气流,对升温有轻微帮助。")
elif wind_dir >= 280:
insights.append(f"🌬️ <b>吹西北风</b>:偏冷的气流,会拖慢升温。")
else:
insights.append(f"🌬️ <b>吹西风</b>:对温度影响不大,主要取决于日照和云量。")
elif 45 < wind_dir < 135:
# 东风
insights.append(f"🌬️ <b>吹东风</b>:对温度影响较小,主要看日照和云量。")
insights.append(f"🌬️ <b>吹西风</b>{wind_source} {wd:.0f}°):对温度影响不大,主要取决于日照和云量。")
elif 45 < wd < 135:
insights.append(f"🌬️ <b>吹东风</b>{wind_source} {wd:.0f}°):对温度影响较小,主要看日照和云量。")
except (TypeError, ValueError):
pass