chore: add prettier formatting
All checks were successful
CI / Lint, typecheck and build (push) Successful in 9m56s

This commit is contained in:
zv
2026-06-14 20:26:56 +02:00
parent 8bbd9397a1
commit ee55521803
79 changed files with 2451 additions and 969 deletions

View File

@@ -53,19 +53,27 @@ function hasNumericValue(value: unknown) {
}
function isFullWeatherRow(candidate: RawImgwHybridWeatherRow) {
return hasNumericValue(candidate.Temperature)
&& hasNumericValue(candidate.Chill)
&& hasNumericValue(candidate.Humidity)
&& hasNumericValue(candidate.Wind_Speed)
&& hasNumericValue(candidate.PressureMSL);
return (
hasNumericValue(candidate.Temperature) &&
hasNumericValue(candidate.Chill) &&
hasNumericValue(candidate.Humidity) &&
hasNumericValue(candidate.Wind_Speed) &&
hasNumericValue(candidate.PressureMSL)
);
}
function hasPrecipitationValue(candidate: RawImgwHybridWeatherRow) {
return hasNumericValue(candidate.Precipitation10m) || hasNumericValue(candidate.Rain10m) || hasNumericValue(candidate.Snow10m);
return (
hasNumericValue(candidate.Precipitation10m) ||
hasNumericValue(candidate.Rain10m) ||
hasNumericValue(candidate.Snow10m)
);
}
function pickFullWeatherRow(rows: NormalizedHybridRow[]) {
const tenMinuteRow = rows.find((candidate) => candidate.row.Type === "Type_Ten_Minutes" && isFullWeatherRow(candidate.row));
const tenMinuteRow = rows.find(
(candidate) => candidate.row.Type === "Type_Ten_Minutes" && isFullWeatherRow(candidate.row),
);
const hourlyRow = rows.find((candidate) => candidate.row.Type === "Type_Hour" && isFullWeatherRow(candidate.row));
if (!tenMinuteRow) return hourlyRow ?? null;
if (!hourlyRow) return tenMinuteRow;
@@ -74,25 +82,26 @@ function pickFullWeatherRow(rows: NormalizedHybridRow[]) {
function pickPrecipitationRow(rows: NormalizedHybridRow[], fullRow: NormalizedHybridRow | null) {
if (fullRow && hasPrecipitationValue(fullRow.row)) return fullRow;
const precipitationRows = rows.filter((candidate) => candidate.row.Type === "Type_Ten_Minutes" && hasPrecipitationValue(candidate.row));
const precipitationRows = rows.filter(
(candidate) => candidate.row.Type === "Type_Ten_Minutes" && hasPrecipitationValue(candidate.row),
);
if (!precipitationRows.length) return null;
if (!fullRow) return precipitationRows[0];
return precipitationRows.reduce((best, candidate) => (
Math.abs(candidate.timestamp - fullRow.timestamp) < Math.abs(best.timestamp - fullRow.timestamp) ? candidate : best
));
return precipitationRows.reduce((best, candidate) =>
Math.abs(candidate.timestamp - fullRow.timestamp) < Math.abs(best.timestamp - fullRow.timestamp) ? candidate : best,
);
}
export function normalizeImgwCurrentWeather(payload: RawImgwHybridWeatherResponse): ImgwCurrentWeather | null {
if (!payload.data?.Valid || !Array.isArray(payload.data.Data)) return null;
const rows = payload.data.Data
.flatMap((candidate): NormalizedHybridRow[] => {
if (!candidate || typeof candidate !== "object") return [];
const row = candidate as RawImgwHybridWeatherRow;
if (row.Type !== "Type_Ten_Minutes" && row.Type !== "Type_Hour") return [];
const normalizedRow = normalizeHybridRow(row);
return normalizedRow ? [normalizedRow] : [];
});
const rows = payload.data.Data.flatMap((candidate): NormalizedHybridRow[] => {
if (!candidate || typeof candidate !== "object") return [];
const row = candidate as RawImgwHybridWeatherRow;
if (row.Type !== "Type_Ten_Minutes" && row.Type !== "Type_Hour") return [];
const normalizedRow = normalizeHybridRow(row);
return normalizedRow ? [normalizedRow] : [];
});
const fullRow = pickFullWeatherRow(rows);
const precipitationRow = pickPrecipitationRow(rows, fullRow);
const row = fullRow ?? precipitationRow;
@@ -131,12 +140,17 @@ export async function fetchImgwCurrentWeather(latitude: number, longitude: numbe
const params = new URLSearchParams({ latitude: String(latitude), longitude: String(longitude) });
const response = await fetch(`/api/imgw-current?${params}`, { signal });
if (!response.ok) throw new Error("Nie udało się pobrać bieżącej analizy IMGW Hybrid.");
return normalizeImgwCurrentWeather(await response.json() as RawImgwHybridWeatherResponse);
return normalizeImgwCurrentWeather((await response.json()) as RawImgwHybridWeatherResponse);
}
export async function fetchCurrentWeather(latitude: number, longitude: number, region: WeatherRegion, signal?: AbortSignal) {
export async function fetchCurrentWeather(
latitude: number,
longitude: number,
region: WeatherRegion,
signal?: AbortSignal,
) {
const params = new URLSearchParams({ latitude: String(latitude), longitude: String(longitude), region });
const response = await fetch(`/api/current-weather?${params}`, { signal });
if (!response.ok) throw new Error("Nie udało się pobrać bieżących warunków pogodowych.");
return await response.json() as ImgwCurrentWeather | null;
return (await response.json()) as ImgwCurrentWeather | null;
}