optimized events
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { MarineForecast, RouteResult } from "@watermaps/shared";
|
||||
import { createRouteWeatherReport, summarizeRouteWeather } from "../src/routeWeatherReport";
|
||||
import {
|
||||
createRouteBridgeReport,
|
||||
createRouteWeatherReport,
|
||||
summarizeRouteWeather
|
||||
} from "../src/routeWeatherReport";
|
||||
|
||||
describe("route weather report", () => {
|
||||
it("samples start, middle and destination forecasts", async () => {
|
||||
@@ -81,7 +85,9 @@ describe("route weather report", () => {
|
||||
clearance_m: 2.7,
|
||||
clearance_label: "H 2.7 m",
|
||||
label: "Niedrige Brücke H 2.7 m",
|
||||
source: "OSM/Geofabrik"
|
||||
source: "OSM/Geofabrik",
|
||||
phone: "+49 491 234",
|
||||
website: "https://bridge.example"
|
||||
},
|
||||
geometry: {
|
||||
type: "LineString",
|
||||
@@ -120,6 +126,75 @@ describe("route weather report", () => {
|
||||
expect(report.bridgeReport?.checkedCount).toBe(2);
|
||||
expect(report.bridgeReport?.summary).toContain("Nicht passierbar");
|
||||
expect(report.bridgeReport?.bridges[0]?.name).toBe("Niedrige Brücke");
|
||||
expect(report.bridgeReport?.bridges[0]?.phone).toBe("+49 491 234");
|
||||
expect(report.bridgeReport?.bridges[0]?.website).toBe("https://bridge.example");
|
||||
});
|
||||
|
||||
it("deduplicates only conservatively matching bridge ways and keeps the richest safe assessment", async () => {
|
||||
const route: RouteResult = {
|
||||
...routeFixture,
|
||||
geometry: {
|
||||
type: "LineString",
|
||||
coordinates: [[0, 0], [1, 0]]
|
||||
},
|
||||
distanceNm: 60
|
||||
};
|
||||
const point = (
|
||||
id: string,
|
||||
lon: number,
|
||||
lat: number,
|
||||
properties: Record<string, unknown> = {}
|
||||
) => ({
|
||||
type: "Feature" as const,
|
||||
id,
|
||||
properties: { layer: "bridges", ...properties },
|
||||
geometry: { type: "Point" as const, coordinates: [lon, lat] }
|
||||
});
|
||||
|
||||
const report = await createRouteBridgeReport(
|
||||
route,
|
||||
{ airDraftM: 3 },
|
||||
async () => ({
|
||||
type: "FeatureCollection",
|
||||
features: [
|
||||
point("named-1", 0.2, 0, {
|
||||
name: "Am Tonnenhof",
|
||||
clearance_m: 4,
|
||||
phone: "+49 491 111"
|
||||
}),
|
||||
point("named-2", 0.2, 0.0003, {
|
||||
name: "Am Tonnenhof",
|
||||
clearance_m: 3.5,
|
||||
website: "https://tonnenhof.example"
|
||||
}),
|
||||
point("distinct-east", 0.4, 0, { name: "Klappbrücke Ost" }),
|
||||
point("distinct-west", 0.4, 0.0001, { name: "Klappbrücke West" }),
|
||||
point("unnamed-tight-1", 0.6, 0),
|
||||
point("unnamed-tight-2", 0.6, 0.00005),
|
||||
point("unnamed-separate-1", 0.8, 0),
|
||||
point("unnamed-separate-2", 0.8, 0.0001),
|
||||
point("named-with-way", 0.9, 0, { name: "Auricher Straße" }),
|
||||
point("unnamed-with-name", 0.9, 0.0001)
|
||||
]
|
||||
})
|
||||
);
|
||||
|
||||
expect(report.bridges).toHaveLength(7);
|
||||
const tonnenhof = report.bridges.find((bridge) => bridge.name === "Am Tonnenhof");
|
||||
expect(tonnenhof).toMatchObject({
|
||||
clearanceM: 3.5,
|
||||
clearanceLabel: "H 3.5 m",
|
||||
label: "Am Tonnenhof H 3.5 m",
|
||||
marginM: 0.5,
|
||||
phone: "+49 491 111",
|
||||
website: "https://tonnenhof.example"
|
||||
});
|
||||
expect(
|
||||
report.bridges.filter((bridge) => bridge.name?.startsWith("Klappbrücke"))
|
||||
).toHaveLength(2);
|
||||
expect(
|
||||
report.bridges.filter((bridge) => bridge.name === null)
|
||||
).toHaveLength(3);
|
||||
});
|
||||
|
||||
it("marks critical weather when wind or wave thresholds are exceeded", () => {
|
||||
|
||||
Reference in New Issue
Block a user