Normalize Wunderground labels to METAR

This commit is contained in:
2569718930@qq.com
2026-04-22 23:43:27 +08:00
parent e3a9f7fb00
commit fe804bc915
8 changed files with 81 additions and 34 deletions
+5 -1
View File
@@ -1,4 +1,5 @@
import type { CityDetail } from "@/lib/dashboard-types";
import { normalizeObservationSourceLabel } from "@/lib/source-labels";
export type OfficialSourceLink = {
label: string;
@@ -749,7 +750,10 @@ export function getOfficialSourceLinks(detail: CityDetail): OfficialSourceLink[]
}),
};
}
return link;
return {
...link,
label: normalizeObservationSourceLabel(link.label, link.label),
};
});
const seen = new Set<string>();
return links.filter((link) => {
+5 -1
View File
@@ -5,6 +5,7 @@ import {
HistoryPoint,
NearbyStation,
} from "@/lib/dashboard-types";
import { normalizeObservationSourceLabel } from "@/lib/source-labels";
const METAR_WX_MAP: Record<
string,
@@ -98,7 +99,10 @@ function getObservationSourceCode(detail: CityDetail): string {
}
function getObservationSourceTag(detail: CityDetail): string {
const label = String(detail.current?.settlement_source_label || "")
const label = normalizeObservationSourceLabel(
detail.current?.settlement_source_label,
"",
)
.trim()
.toUpperCase();
if (label) return label;
+4 -4
View File
@@ -63,9 +63,9 @@ const MESSAGES: Record<Locale, Record<string, string>> = {
"history.loading": "正在获取历史数据...",
"history.error": "获取历史信息失败",
"history.empty": "近 15 天暂无该城市历史数据",
"history.hitRate": "DEB 结算胜率 (WU)",
"history.hitRate": "DEB 结算胜率 (METAR)",
"history.mae": "DEB MAE",
"history.debHitRate": "DEB 结算胜率 (WU)",
"history.debHitRate": "DEB 结算胜率 (METAR)",
"history.debMae": "DEB MAE",
"history.muMae": "μ MAE",
"history.bestModelMae": "最佳单模型 MAE",
@@ -230,9 +230,9 @@ const MESSAGES: Record<Locale, Record<string, string>> = {
"history.loading": "Loading historical data...",
"history.error": "Failed to load historical data",
"history.empty": "No historical records for this city in the last 15 days",
"history.hitRate": "DEB Settlement Hit Rate (WU)",
"history.hitRate": "DEB Settlement Hit Rate (METAR)",
"history.mae": "DEB MAE",
"history.debHitRate": "DEB Settlement Hit Rate (WU)",
"history.debHitRate": "DEB Settlement Hit Rate (METAR)",
"history.debMae": "DEB MAE",
"history.muMae": "μ MAE",
"history.bestModelMae": "Best Single-model MAE",
+24
View File
@@ -0,0 +1,24 @@
export function normalizeObservationSourceLabel(
value?: string | null,
fallback = "METAR",
) {
const raw = String(value || "").trim();
if (!raw) return fallback;
const lowered = raw.toLowerCase();
if (
lowered === "wu" ||
lowered === "wunderground"
) {
return "METAR";
}
if (lowered.includes("wunderground")) {
return raw.replace(/wunderground/gi, "METAR");
}
return raw;
}
export function normalizeObservationSourceCode(value?: string | null) {
const code = String(value || "").trim().toLowerCase();
if (code === "wu" || code === "wunderground") return "metar";
return code;
}