Use METAR fallback for sparse official observation charts
This commit is contained in:
@@ -240,15 +240,34 @@ export function getTemperatureChartData(
|
|||||||
const observationCode = getObservationSourceCode(detail);
|
const observationCode = getObservationSourceCode(detail);
|
||||||
const settlementSource =
|
const settlementSource =
|
||||||
observationCode === "hko" || observationCode === "cwa";
|
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
|
const observationSource = settlementSource
|
||||||
? detail.settlement_today_obs?.length
|
? shouldUseMetarFallback
|
||||||
? detail.settlement_today_obs
|
? metarObservationSource
|
||||||
: detail.current?.obs_time && detail.current?.temp != null
|
: officialObservationSource
|
||||||
? [{ time: detail.current.obs_time, temp: detail.current.temp }]
|
: metarObservationSource;
|
||||||
: []
|
const metarFallbackTag = (() => {
|
||||||
: detail.metar_today_obs?.length
|
const icao = String(detail.risk?.icao || "").trim().toUpperCase();
|
||||||
? detail.metar_today_obs
|
if (!icao) return "METAR";
|
||||||
: detail.trend?.recent || [];
|
return `${icao} METAR`;
|
||||||
|
})();
|
||||||
|
const observationDisplayTag =
|
||||||
|
settlementSource && shouldUseMetarFallback ? metarFallbackTag : observationTag;
|
||||||
|
|
||||||
const metarPoints = new Array(times.length).fill(null);
|
const metarPoints = new Array(times.length).fill(null);
|
||||||
observationSource.forEach((item) => {
|
observationSource.forEach((item) => {
|
||||||
@@ -329,7 +348,14 @@ export function getTemperatureChartData(
|
|||||||
.reverse()
|
.reverse()
|
||||||
.map((item) => `${item.temp}${detail.temp_symbol}@${item.time}`)
|
.map((item) => `${item.temp}${detail.temp_symbol}@${item.time}`)
|
||||||
.join(" -> ");
|
.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 {
|
return {
|
||||||
@@ -344,8 +370,8 @@ export function getTemperatureChartData(
|
|||||||
temps,
|
temps,
|
||||||
},
|
},
|
||||||
observationLabel: isEnglish(locale)
|
observationLabel: isEnglish(locale)
|
||||||
? `${observationTag} Observation`
|
? `${observationDisplayTag} Observation`
|
||||||
: `${observationTag} 实况`,
|
: `${observationDisplayTag} 实况`,
|
||||||
legendText: legendParts.join(" | "),
|
legendText: legendParts.join(" | "),
|
||||||
max,
|
max,
|
||||||
min,
|
min,
|
||||||
|
|||||||
+5
-11
@@ -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})
|
settlement_today_obs.append({"time": str(max_temp_time), "temp": max_so_far})
|
||||||
|
|
||||||
metar_today_obs_payload = (
|
metar_today_obs_payload = [
|
||||||
[]
|
{"time": t, "temp": v}
|
||||||
if use_settlement_current
|
for t, v in (metar.get("today_obs", []) if metar else [])
|
||||||
else [
|
]
|
||||||
{"time": t, "temp": v}
|
metar_recent_obs_payload = metar.get("recent_obs", []) if metar else []
|
||||||
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 [])
|
|
||||||
)
|
|
||||||
|
|
||||||
# ── 3. Local time parsing ──
|
# ── 3. Local time parsing ──
|
||||||
local_time_full = om.get("current", {}).get("local_time", "")
|
local_time_full = om.get("current", {}).get("local_time", "")
|
||||||
|
|||||||
Reference in New Issue
Block a user