Add localized meteorology text and filter implausible METAR temps
This commit is contained in:
@@ -205,6 +205,32 @@ function signalTone(signal?: IntradayMeteorologySignal | null) {
|
||||
return "blue";
|
||||
}
|
||||
|
||||
function localizedText(
|
||||
locale: string,
|
||||
primary?: string | null,
|
||||
english?: string | null,
|
||||
) {
|
||||
const en = String(english || "").trim();
|
||||
const value = String(primary || "").trim();
|
||||
if (locale === "en-US" && en) return en;
|
||||
return value || en;
|
||||
}
|
||||
|
||||
function localizedList(
|
||||
locale: string,
|
||||
primary?: string[] | null,
|
||||
english?: string[] | null,
|
||||
) {
|
||||
const en = Array.isArray(english)
|
||||
? english.filter((item) => String(item || "").trim())
|
||||
: [];
|
||||
const value = Array.isArray(primary)
|
||||
? primary.filter((item) => String(item || "").trim())
|
||||
: [];
|
||||
if (locale === "en-US" && en.length) return en;
|
||||
return value.length ? value : en;
|
||||
}
|
||||
|
||||
function getTrendMetricVisual(metric: {
|
||||
label?: string;
|
||||
value?: string;
|
||||
@@ -1115,14 +1141,22 @@ export function FutureForecastModal() {
|
||||
const meteorologySignals = Array.isArray(intradayMeteorology.signal_contributions)
|
||||
? intradayMeteorology.signal_contributions
|
||||
: [];
|
||||
const invalidationRules = Array.isArray(intradayMeteorology.invalidation_rules)
|
||||
? intradayMeteorology.invalidation_rules
|
||||
: [];
|
||||
const confirmationRules = Array.isArray(intradayMeteorology.confirmation_rules)
|
||||
? intradayMeteorology.confirmation_rules
|
||||
: [];
|
||||
const invalidationRules = localizedList(
|
||||
locale,
|
||||
intradayMeteorology.invalidation_rules,
|
||||
intradayMeteorology.invalidation_rules_en,
|
||||
);
|
||||
const confirmationRules = localizedList(
|
||||
locale,
|
||||
intradayMeteorology.confirmation_rules,
|
||||
intradayMeteorology.confirmation_rules_en,
|
||||
);
|
||||
const meteorologyHeadline =
|
||||
String(intradayMeteorology.headline || "").trim() ||
|
||||
localizedText(
|
||||
locale,
|
||||
intradayMeteorology.headline,
|
||||
intradayMeteorology.headline_en,
|
||||
) ||
|
||||
todayTradeSummaryLines[0] ||
|
||||
(locale === "en-US"
|
||||
? "Intraday meteorology layers are still syncing; use the next observation as the anchor."
|
||||
@@ -1650,13 +1684,17 @@ export function FutureForecastModal() {
|
||||
)}
|
||||
>
|
||||
<div className="future-v2-evidence-head">
|
||||
<strong>{signal.label || "--"}</strong>
|
||||
<strong>
|
||||
{localizedText(locale, signal.label, signal.label_en) || "--"}
|
||||
</strong>
|
||||
<span>
|
||||
{formatSignalDirection(signal.direction, locale)} ·{" "}
|
||||
{formatSignalStrength(signal.strength, locale)}
|
||||
</span>
|
||||
</div>
|
||||
<p>{signal.summary || "--"}</p>
|
||||
<p>
|
||||
{localizedText(locale, signal.summary, signal.summary_en) || "--"}
|
||||
</p>
|
||||
</div>
|
||||
))
|
||||
) : (
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user