Next alpha stage commit

This commit is contained in:
2026-07-06 20:54:46 +02:00
parent e23387738b
commit 1d7ec956d2
42 changed files with 11603 additions and 2837 deletions

View File

@@ -6,7 +6,7 @@ from shapely.geometry import LineString
from sqlalchemy import select
from app.db import init_db, session_scope
from app.models import GtfsRoute, OsmFeature, RouteMatch, RoutePattern
from app.models import Dataset, GtfsRoute, OsmFeature, RouteMatch, RoutePattern, Source
from app.osm_classification import infer_osm_route_scope
from app.pipeline.gtfs import _gtfs_mode
from app.pipeline.matcher import _build_osm_route_index, _candidate_osm_routes, route_match_scope, run_route_matching, score_route_pair
@@ -53,6 +53,47 @@ def test_route_matching_preserves_unchanged_match_rows():
assert after == before
def test_route_matching_can_target_single_gtfs_dataset():
init_db()
with session_scope() as session:
load_sample_project(session)
source = Source(
name="Second feed",
kind="gtfs",
url="./second-feed.zip",
country="DE",
)
session.add(source)
session.flush()
dataset = Dataset(
source_id=source.id,
kind="gtfs",
local_path="second-feed.zip",
sha256="second-feed",
is_active=True,
status="imported",
)
session.add(dataset)
session.flush()
route = GtfsRoute(
dataset_id=dataset.id,
route_id="second-only",
short_name="ZZ",
mode="bus",
min_lon=13.0,
min_lat=52.0,
max_lon=13.1,
max_lat=52.1,
)
session.add(route)
session.flush()
result = run_route_matching(session, gtfs_dataset_ids=[dataset.id])
assert result["routes"] == 1
assert session.scalar(select(RouteMatch).where(RouteMatch.gtfs_route_id == route.id)) is not None
def test_route_layer_reuses_unchanged_route_patterns():
init_db()
with session_scope() as session:
@@ -241,6 +282,37 @@ def test_common_short_ref_candidates_are_spatially_ranked():
candidates = _candidate_osm_routes(route, _build_osm_route_index([far, near]))
assert candidates[0].osm_id == "near"
assert "far" not in {candidate.osm_id for candidate in candidates}
def test_known_bbox_route_does_not_fallback_to_global_mode_candidates():
route = GtfsRoute(
route_id="bus-x-berlin",
short_name="X",
mode="bus",
min_lon=13.30,
min_lat=52.40,
max_lon=13.40,
max_lat=52.50,
route_key="x",
)
far = OsmFeature(
id=1,
osm_type="relation",
osm_id="far-bus",
kind="route",
mode="bus",
ref="9",
min_lon=7.0,
min_lat=50.0,
max_lon=7.1,
max_lat=50.1,
route_key="9",
)
candidates = _candidate_osm_routes(route, _build_osm_route_index([far]))
assert candidates == []
def test_exact_ref_far_away_is_not_promoted_without_spatial_or_geometry_evidence():