Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/helpers/aviationAlerts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const aviationAlerts: AviationAlertFeature[] = [
data: "GAIRMET",
product: "TANGO",
hazard: "TURB-LO",
tag: "1W",
severity: "MOD",
top: "060",
base: "SFC",
Expand Down Expand Up @@ -38,6 +39,7 @@ const aviationAlerts: AviationAlertFeature[] = [
data: "GAIRMET",
product: "TANGO",
hazard: "TURB-LO",
tag: "1W",
severity: "MOD",
top: "060",
base: "SFC",
Expand Down Expand Up @@ -71,6 +73,7 @@ const aviationAlerts: AviationAlertFeature[] = [
data: "GAIRMET",
product: "TANGO",
hazard: "TURB-LO",
tag: "1W",
severity: "MOD",
top: "060",
base: "SFC",
Expand Down Expand Up @@ -101,6 +104,7 @@ const aviationAlerts: AviationAlertFeature[] = [
data: "GAIRMET",
product: "TANGO",
hazard: "TURB-LO",
tag: "1W",
severity: "MOD",
top: "060",
base: "SFC",
Expand Down
10 changes: 5 additions & 5 deletions src/helpers/weather.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
54 changes: 42 additions & 12 deletions src/services/aviationWeather.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ export type GAirmetFeature = AbstractAviationAlertFeature<{

product: "SIERRA" | "TANGO" | "ZULU";

tag: string;

hazard:
| "TURB-HI"
| "TURB-LO"
Expand Down Expand Up @@ -242,19 +244,47 @@ export async function getAviationAlerts({
lat: number;
lon: number;
}): Promise<AviationAlertFeature[]> {
const response = await axios.get("/api/aviationalerts", {
params: {
lat,
lon,
},
});
const response = await axios.get<{
features: Omit<AviationAlertFeature, "id">[];
}>("/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<AviationAlertFeature, "id">): 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)}`;
}