Use METAR fallback for sparse official observation charts

This commit is contained in:
2569718930@qq.com
2026-03-22 22:43:06 +08:00
parent 60785471e2
commit e2c51f5125
2 changed files with 42 additions and 22 deletions
+37 -11
View File
@@ -240,15 +240,34 @@ export function getTemperatureChartData(
const observationCode = getObservationSourceCode(detail);
const settlementSource =
observationCode === "hko" || observationCode === "cwa";
const officialObservationSource =
settlementSource
? detail.settlement_today_obs?.length
? detail.settlement_today_obs
: detail.current?.obs_time && detail.current?.temp != null
? [{ time: detail.current.obs_time, temp: detail.current.temp }]
: []
: [];
const metarObservationSource = detail.metar_today_obs?.length
? detail.metar_today_obs
: detail.trend?.recent || [];
const shouldUseMetarFallback =
settlementSource &&
officialObservationSource.length > 0 &&
officialObservationSource.length < 3 &&
metarObservationSource.length >= 3;
const observationSource = settlementSource
? detail.settlement_today_obs?.length
? detail.settlement_today_obs
: detail.current?.obs_time && detail.current?.temp != null
? [{ time: detail.current.obs_time, temp: detail.current.temp }]
: []
: detail.metar_today_obs?.length
? detail.metar_today_obs
: detail.trend?.recent || [];
? shouldUseMetarFallback
? metarObservationSource
: officialObservationSource
: metarObservationSource;
const metarFallbackTag = (() => {
const icao = String(detail.risk?.icao || "").trim().toUpperCase();
if (!icao) return "METAR";
return `${icao} METAR`;
})();
const observationDisplayTag =
settlementSource && shouldUseMetarFallback ? metarFallbackTag : observationTag;
const metarPoints = new Array(times.length).fill(null);
observationSource.forEach((item) => {
@@ -329,7 +348,14 @@ export function getTemperatureChartData(
.reverse()
.map((item) => `${item.temp}${detail.temp_symbol}@${item.time}`)
.join(" -> ");
legendParts.push(`${observationTag}: ${recentText}`);
legendParts.push(`${observationDisplayTag}: ${recentText}`);
}
if (shouldUseMetarFallback) {
legendParts.push(
isEnglish(locale)
? `Official ${observationTag} feed is sparse today, so the continuous observation line switches to ${metarFallbackTag}.`
: `今日官方 ${observationTag} 点位较稀疏,连续实测线改用 ${metarFallbackTag}`,
);
}
return {
@@ -344,8 +370,8 @@ export function getTemperatureChartData(
temps,
},
observationLabel: isEnglish(locale)
? `${observationTag} Observation`
: `${observationTag} 实况`,
? `${observationDisplayTag} Observation`
: `${observationDisplayTag} 实况`,
legendText: legendParts.join(" | "),
max,
min,
+5 -11
View File
@@ -147,17 +147,11 @@ def _analyze(city: str, force_refresh: bool = False) -> Dict[str, Any]:
):
settlement_today_obs.append({"time": str(max_temp_time), "temp": max_so_far})
metar_today_obs_payload = (
[]
if use_settlement_current
else [
{"time": t, "temp": v}
for t, v in (metar.get("today_obs", []) if metar else [])
]
)
metar_recent_obs_payload = (
[] if use_settlement_current else (metar.get("recent_obs", []) if metar else [])
)
metar_today_obs_payload = [
{"time": t, "temp": v}
for t, v in (metar.get("today_obs", []) if metar else [])
]
metar_recent_obs_payload = metar.get("recent_obs", []) if metar else []
# ── 3. Local time parsing ──
local_time_full = om.get("current", {}).get("local_time", "")