diff --git a/src/helpers/aviationAlerts.test.ts b/src/helpers/aviationAlerts.test.ts index cf4988a..986994a 100644 --- a/src/helpers/aviationAlerts.test.ts +++ b/src/helpers/aviationAlerts.test.ts @@ -8,6 +8,7 @@ const aviationAlerts: AviationAlertFeature[] = [ data: "GAIRMET", product: "TANGO", hazard: "TURB-LO", + tag: "1W", severity: "MOD", top: "060", base: "SFC", @@ -38,6 +39,7 @@ const aviationAlerts: AviationAlertFeature[] = [ data: "GAIRMET", product: "TANGO", hazard: "TURB-LO", + tag: "1W", severity: "MOD", top: "060", base: "SFC", @@ -71,6 +73,7 @@ const aviationAlerts: AviationAlertFeature[] = [ data: "GAIRMET", product: "TANGO", hazard: "TURB-LO", + tag: "1W", severity: "MOD", top: "060", base: "SFC", @@ -101,6 +104,7 @@ const aviationAlerts: AviationAlertFeature[] = [ data: "GAIRMET", product: "TANGO", hazard: "TURB-LO", + tag: "1W", severity: "MOD", top: "060", base: "SFC", diff --git a/src/helpers/weather.ts b/src/helpers/weather.ts index b8eb063..658c441 100644 --- a/src/helpers/weather.ts +++ b/src/helpers/weather.ts @@ -104,17 +104,17 @@ export function findRelatedAlerts( ); }) as GAirmetFeature[]; + potential.sort( + (a, b) => + Date.parse(a.properties.issueTime) - Date.parse(b.properties.issueTime), + ); + const baseAlertIndex = potential.findIndex( (potentialAlert) => potentialAlert.id === alert.id, ); if (baseAlertIndex === -1) return [alert]; - potential.sort( - (a, b) => - Date.parse(a.properties.issueTime) - Date.parse(b.properties.issueTime), - ); - return [ ...findPrev(alert, potential.slice(0, baseAlertIndex)), alert, diff --git a/src/services/aviationWeather.ts b/src/services/aviationWeather.ts index 339ea3e..51bfdc8 100644 --- a/src/services/aviationWeather.ts +++ b/src/services/aviationWeather.ts @@ -162,6 +162,8 @@ export type GAirmetFeature = AbstractAviationAlertFeature<{ product: "SIERRA" | "TANGO" | "ZULU"; + tag: string; + hazard: | "TURB-HI" | "TURB-LO" @@ -242,19 +244,47 @@ export async function getAviationAlerts({ lat: number; lon: number; }): Promise { - const response = await axios.get("/api/aviationalerts", { - params: { - lat, - lon, - }, - }); + const response = await axios.get<{ + features: Omit[]; + }>("/api/aviationalerts", { params: { lat, lon } }); + + return response.data.features + .filter((feature) => { + if ( + "altitudeLow1" in feature.properties && + feature.properties.altitudeLow1 > 3000 + ) + return false; + + return true; + }) + .map( + (feature) => + ({ + ...feature, + id: generateFeatureId(feature), + }) as AviationAlertFeature, + ); +} - // eslint-disable-next-line @typescript-eslint/no-explicit-any - return response.data.features.filter((feature: any) => { - if (!feature.properties.altitudeLow1) return true; +function generateFeatureId(feature: Omit): string { + const p = feature.properties; - if (feature.properties.altitudeLow1 > 3000) return false; + if ("product" in p) { + return `gairmet-${p.product}-${p.hazard}-${p.tag}-${p.validTime}`; + } - return true; - }); + if ("airSigmetType" in p) { + return `sigmet-${p.icaoId}-${p.alphaChar}-${p.hazard}-${p.validTimeFrom}`; + } + + if ("data" in p && p.data === "ISIGMET") { + return `isigmet-${p.icaoId}-${p.hazard}-${p.validTimeFrom}`; + } + + if ("cwsu" in p) { + return `cwa-${p.cwsu}-${p.seriesId}-${p.validTimeFrom}`; + } + + return `aviation-alert-${JSON.stringify(p)}`; }