fix: preserve partial IMGW Hybrid coverage
This commit is contained in:
@@ -35,15 +35,15 @@ function getCondition(weatherCode: number | null, rainfall10m: number | null, sn
|
||||
export function normalizeImgwCurrentWeather(payload: RawImgwHybridWeatherResponse): ImgwCurrentWeather | null {
|
||||
if (!payload.data?.Valid || !Array.isArray(payload.data.Data)) return null;
|
||||
|
||||
const row = payload.data.Data
|
||||
const rows = payload.data.Data
|
||||
.filter((candidate): candidate is RawImgwHybridWeatherRow => {
|
||||
if (!candidate || typeof candidate !== "object") return false;
|
||||
return candidate.Type === "Type_Ten_Minutes"
|
||||
&& typeof candidate.MODEL === "string"
|
||||
&& candidate.MODEL.includes("AROME")
|
||||
&& normalizeDate(candidate.Date) !== null;
|
||||
return candidate.Type === "Type_Ten_Minutes" && normalizeDate(candidate.Date) !== null;
|
||||
})
|
||||
.sort((left, right) => String(right.Date).localeCompare(String(left.Date)))[0];
|
||||
.sort((left, right) => String(left.Date).localeCompare(String(right.Date)));
|
||||
const fullRow = rows.find((candidate) => typeof candidate.MODEL === "string" && candidate.MODEL.includes("AROME"));
|
||||
const precipitationRow = rows.find((candidate) => candidate.Precipitation10m !== undefined);
|
||||
const row = fullRow ?? precipitationRow;
|
||||
if (!row) return null;
|
||||
|
||||
const measuredAt = normalizeDate(row.Date);
|
||||
@@ -53,6 +53,7 @@ export function normalizeImgwCurrentWeather(payload: RawImgwHybridWeatherRespons
|
||||
const weatherCode = getWeatherCode(row.Icon10);
|
||||
|
||||
return {
|
||||
coverage: fullRow ? "full" : "precipitation-only",
|
||||
measuredAt,
|
||||
temperature: toCelsius(row.Temperature),
|
||||
feelsLike: toCelsius(row.Chill),
|
||||
|
||||
Reference in New Issue
Block a user