Prefer METAR over NMC for city observation display
This commit is contained in:
@@ -57,12 +57,26 @@ function pickMarkerTemperature(
|
|||||||
) {
|
) {
|
||||||
if (!snapshot) return null;
|
if (!snapshot) return null;
|
||||||
const detail = snapshot as Partial<CityDetail>;
|
const detail = snapshot as Partial<CityDetail>;
|
||||||
|
const currentSource = String(
|
||||||
|
snapshot.current?.settlement_source ||
|
||||||
|
snapshot.current?.settlement_source_label ||
|
||||||
|
"",
|
||||||
|
)
|
||||||
|
.trim()
|
||||||
|
.toLowerCase();
|
||||||
|
const currentTemp =
|
||||||
|
currentSource === "nmc" || currentSource.includes("nmc")
|
||||||
|
? null
|
||||||
|
: snapshot.current?.temp;
|
||||||
|
const isNmcStation = (station?: { source_label?: string | null }) =>
|
||||||
|
String(station?.source_label || "")
|
||||||
|
.trim()
|
||||||
|
.toLowerCase()
|
||||||
|
.includes("nmc");
|
||||||
const candidates = [
|
const candidates = [
|
||||||
snapshot.current?.temp,
|
currentTemp,
|
||||||
detail.airport_primary?.temp,
|
|
||||||
detail.airport_current?.temp,
|
detail.airport_current?.temp,
|
||||||
detail.center_station_candidate?.temp,
|
isNmcStation(detail.airport_primary) ? null : detail.airport_primary?.temp,
|
||||||
detail.official_nearby?.[0]?.temp,
|
|
||||||
detail.mgm_nearby?.[0]?.temp,
|
detail.mgm_nearby?.[0]?.temp,
|
||||||
];
|
];
|
||||||
for (const value of candidates) {
|
for (const value of candidates) {
|
||||||
|
|||||||
@@ -2993,30 +2993,48 @@ function getOfficialObservationCandidates(detail: CityDetail) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getObservedTemperatureProfile(detail: CityDetail, locale: Locale) {
|
function getObservedTemperatureProfile(detail: CityDetail, locale: Locale) {
|
||||||
const { centerStation, officialAnchor, officialNearby, mgmNearby } =
|
const { mgmNearby } = getOfficialObservationCandidates(detail);
|
||||||
getOfficialObservationCandidates(detail);
|
const currentSource = String(
|
||||||
const observedTemp = firstFiniteNumber([
|
detail.current?.settlement_source ||
|
||||||
detail.current?.temp,
|
detail.current?.settlement_source_label ||
|
||||||
detail.airport_primary?.temp,
|
"",
|
||||||
detail.airport_current?.temp,
|
)
|
||||||
centerStation?.temp,
|
.trim()
|
||||||
officialAnchor?.temp,
|
.toLowerCase();
|
||||||
officialNearby[0]?.temp,
|
const isNmcCurrent = currentSource === "nmc" || currentSource.includes("nmc");
|
||||||
mgmNearby[0]?.temp,
|
const isNmcAirport = String(detail.airport_primary?.source_label || "")
|
||||||
]);
|
.trim()
|
||||||
|
.toLowerCase()
|
||||||
|
.includes("nmc");
|
||||||
|
const candidates = [
|
||||||
|
{
|
||||||
|
sourceLabel: detail.airport_current?.source_label || "METAR",
|
||||||
|
temp: detail.airport_current?.temp,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
sourceLabel: detail.airport_primary?.source_label || "METAR",
|
||||||
|
temp: isNmcAirport ? null : detail.airport_primary?.temp,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
sourceLabel: detail.current?.settlement_source_label,
|
||||||
|
temp: isNmcCurrent ? null : detail.current?.temp,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
sourceLabel: mgmNearby[0]?.source_label,
|
||||||
|
temp: mgmNearby[0]?.temp,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
const selected = candidates.find((candidate) =>
|
||||||
|
Number.isFinite(Number(candidate.temp)),
|
||||||
|
);
|
||||||
|
|
||||||
if (observedTemp == null) {
|
if (!selected) {
|
||||||
return isEnglish(locale) ? "Unavailable" : "未提供";
|
return isEnglish(locale) ? "Unavailable" : "未提供";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const observedTemp = Number(selected.temp);
|
||||||
const sourceLabel = firstNonEmptyString([
|
const sourceLabel = firstNonEmptyString([
|
||||||
detail.current?.settlement_source_label,
|
selected.sourceLabel,
|
||||||
detail.airport_primary?.source_label,
|
|
||||||
detail.airport_current?.source_label,
|
|
||||||
centerStation?.source_label,
|
|
||||||
officialAnchor?.source_label,
|
|
||||||
officialNearby[0]?.source_label,
|
|
||||||
mgmNearby[0]?.source_label,
|
|
||||||
getObservationSourceTag(detail),
|
getObservationSourceTag(detail),
|
||||||
]);
|
]);
|
||||||
const rounded =
|
const rounded =
|
||||||
@@ -3030,28 +3048,23 @@ function getObservedTemperatureProfile(detail: CityDetail, locale: Locale) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getObservationUpdateProfile(detail: CityDetail, locale: Locale) {
|
function getObservationUpdateProfile(detail: CityDetail, locale: Locale) {
|
||||||
const { centerStation, officialAnchor, officialNearby, mgmNearby } =
|
const { mgmNearby } = getOfficialObservationCandidates(detail);
|
||||||
getOfficialObservationCandidates(detail);
|
|
||||||
const centerRecord = asRecord(centerStation);
|
|
||||||
const officialAnchorRecord = asRecord(officialAnchor);
|
|
||||||
const officialFirstRecord = asRecord(officialNearby[0]);
|
|
||||||
const mgmFirstRecord = asRecord(mgmNearby[0]);
|
const mgmFirstRecord = asRecord(mgmNearby[0]);
|
||||||
|
const currentSource = String(
|
||||||
|
detail.current?.settlement_source ||
|
||||||
|
detail.current?.settlement_source_label ||
|
||||||
|
"",
|
||||||
|
)
|
||||||
|
.trim()
|
||||||
|
.toLowerCase();
|
||||||
|
const isNmcCurrent = currentSource === "nmc" || currentSource.includes("nmc");
|
||||||
const rawValue = firstNonEmptyString([
|
const rawValue = firstNonEmptyString([
|
||||||
detail.current?.obs_time,
|
|
||||||
detail.current?.report_time,
|
|
||||||
detail.airport_primary?.obs_time,
|
detail.airport_primary?.obs_time,
|
||||||
detail.airport_primary?.report_time,
|
detail.airport_primary?.report_time,
|
||||||
detail.airport_current?.obs_time,
|
detail.airport_current?.obs_time,
|
||||||
detail.airport_current?.report_time,
|
detail.airport_current?.report_time,
|
||||||
centerRecord?.obs_time,
|
isNmcCurrent ? "" : detail.current?.obs_time,
|
||||||
centerRecord?.report_time,
|
isNmcCurrent ? "" : detail.current?.report_time,
|
||||||
centerRecord?.time,
|
|
||||||
officialAnchorRecord?.obs_time,
|
|
||||||
officialAnchorRecord?.report_time,
|
|
||||||
officialAnchorRecord?.time,
|
|
||||||
officialFirstRecord?.obs_time,
|
|
||||||
officialFirstRecord?.report_time,
|
|
||||||
officialFirstRecord?.time,
|
|
||||||
mgmFirstRecord?.obs_time,
|
mgmFirstRecord?.obs_time,
|
||||||
mgmFirstRecord?.report_time,
|
mgmFirstRecord?.report_time,
|
||||||
mgmFirstRecord?.time,
|
mgmFirstRecord?.time,
|
||||||
|
|||||||
Reference in New Issue
Block a user