Add localized meteorology text and filter implausible METAR temps

This commit is contained in:
2569718930@qq.com
2026-04-16 17:34:39 +08:00
parent 2598c5ac98
commit 9823e3961f
7 changed files with 230 additions and 23 deletions
+5
View File
@@ -318,13 +318,16 @@ export interface MarketScan {
export interface IntradayMeteorologySignal {
label?: string | null;
label_en?: string | null;
direction?: "support" | "suppress" | "neutral" | string | null;
strength?: "weak" | "medium" | "strong" | string | null;
summary?: string | null;
summary_en?: string | null;
}
export interface IntradayMeteorology {
headline?: string | null;
headline_en?: string | null;
confidence?: "low" | "medium" | "high" | string | null;
base_case_bucket?: string | null;
upside_bucket?: string | null;
@@ -332,7 +335,9 @@ export interface IntradayMeteorology {
next_observation_time?: string | null;
peak_window?: string | null;
invalidation_rules?: string[] | null;
invalidation_rules_en?: string[] | null;
confirmation_rules?: string[] | null;
confirmation_rules_en?: string[] | null;
signal_contributions?: IntradayMeteorologySignal[] | null;
}
+27 -8
View File
@@ -696,15 +696,34 @@ export function getTemperatureChartData(
: []
: [];
const currentObservationFallback = buildCurrentObservationFallback(detail);
const metarObservationSource = detail.metar_today_obs?.length
? detail.metar_today_obs
: detail.trend?.recent?.length
? detail.trend.recent
: currentObservationFallback;
const minPlausibleObservationTemp = (() => {
const name = String(detail.name || "").trim().toLowerCase();
const icao = String(detail.risk?.icao || "").trim().toUpperCase();
if (name === "karachi" || name === "masroor air base" || icao === "OPKC" || icao === "OPMR") {
return detail.temp_symbol === "°F" ? 41 : 5;
}
return null;
})();
const filterPlausibleObservations = <T extends { temp?: number | null }>(
rows?: T[] | null,
) =>
(Array.isArray(rows) ? rows : []).filter((row) => {
const value = Number(row?.temp);
if (!Number.isFinite(value)) return false;
return minPlausibleObservationTemp == null || value >= minPlausibleObservationTemp;
});
const plausibleMetarTodayObs = filterPlausibleObservations(detail.metar_today_obs);
const plausibleTrendRecent = filterPlausibleObservations(detail.trend?.recent);
const plausibleCurrentFallback = filterPlausibleObservations(currentObservationFallback);
const metarObservationSource = plausibleMetarTodayObs.length
? plausibleMetarTodayObs
: plausibleTrendRecent.length
? plausibleTrendRecent
: plausibleCurrentFallback;
const usingCurrentObservationFallback =
!detail.metar_today_obs?.length &&
!detail.trend?.recent?.length &&
currentObservationFallback.length > 0;
!plausibleMetarTodayObs.length &&
!plausibleTrendRecent.length &&
plausibleCurrentFallback.length > 0;
const currentFallbackTag =
currentObservationFallback[0]?.sourceLabel ||
getObservationSourceTag(detail);