From bfeb37e1a6d5737a8d605a73d88c595ac0478e48 Mon Sep 17 00:00:00 2001 From: Jamie Cook Date: Fri, 6 Sep 2024 09:50:07 +1000 Subject: [PATCH 1/2] test that logs skipped route_types --- aequilibrae/transit/lib_gtfs.py | 14 +++++++++++--- tests/aequilibrae/transit/test_lib_gtfs.py | 6 ++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/aequilibrae/transit/lib_gtfs.py b/aequilibrae/transit/lib_gtfs.py index 8c59fc583..9dd505523 100644 --- a/aequilibrae/transit/lib_gtfs.py +++ b/aequilibrae/transit/lib_gtfs.py @@ -7,7 +7,8 @@ from pyproj import Transformer from shapely.geometry import Point, MultiLineString -from aequilibrae.context import get_active_project, get_logger +from aequilibrae.log import logger +from aequilibrae.context import get_active_project from aequilibrae.project.database_connection import database_connection from aequilibrae.transit.constants import Constants, PATTERN_ID_MULTIPLIER from aequilibrae.transit.functions.get_srid import get_srid @@ -39,7 +40,7 @@ def __init__( self.project = get_active_project(False) self.archive_dir = None # type: str self.day = day - self.logger = get_logger() + self.logger = logger self.gtfs_data = GTFSReader() self.srid = get_srid() @@ -123,7 +124,7 @@ def set_allow_map_match(self, allow=True): self.__do_execute_map_matching = allow - def map_match(self, route_types=[3]) -> None: # noqa: B006 + def map_match(self, route_types=(3)) -> None: # noqa: B006 """Performs map-matching for all routes of one or more types. Defaults to map-matching Bus routes (type 3) only. @@ -139,6 +140,13 @@ def map_match(self, route_types=[3]) -> None: # noqa: B006 if any(not isinstance(item, int) for item in route_types): raise TypeError("All route types must be integers") + if any(e not in mode_correspondence for e in route_types): + missing_route_types = [e for e in route_types if e not in mode_correspondence] + logger.warning( + f"Skipping the following route_types as they have no corresponding road mode: {missing_route_types}" + ) + route_types = [e for e in route_types if e in mode_correspondence] + self.signal.emit(["start", len(self.select_patterns), "Map-matching patterns"]) for i, pat in enumerate(self.select_patterns.values()): self.signal.emit(["update", i, f"Map-matching pattern {pat.pattern_id}"]) diff --git a/tests/aequilibrae/transit/test_lib_gtfs.py b/tests/aequilibrae/transit/test_lib_gtfs.py index 9ff39f585..4c7546b5e 100644 --- a/tests/aequilibrae/transit/test_lib_gtfs.py +++ b/tests/aequilibrae/transit/test_lib_gtfs.py @@ -47,10 +47,12 @@ def test_map_match_int_exception(system_builder): system_builder.map_match(route_types=[3.5]) -def test_map_match(transit_conn, system_builder): +def test_map_match(transit_conn, system_builder, caplog): system_builder.load_date("2016-04-13") system_builder.set_allow_map_match(True) - system_builder.map_match() + system_builder.map_match([3, 1, 2]) + assert "Skipping the following route_types as they have no corresponding road mode: [1, 2]" in caplog.text + system_builder.save_to_disk() assert transit_conn.execute("SELECT * FROM pattern_mapping;").fetchone()[0] > 1 From 7ab9c12298078f11f618199b4d55eae17ee38ad8 Mon Sep 17 00:00:00 2001 From: Jamie Cook Date: Fri, 6 Sep 2024 09:51:55 +1000 Subject: [PATCH 2/2] lint --- aequilibrae/transit/transit_elements/mode_correspondence.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aequilibrae/transit/transit_elements/mode_correspondence.py b/aequilibrae/transit/transit_elements/mode_correspondence.py index 730882f82..2ad241104 100644 --- a/aequilibrae/transit/transit_elements/mode_correspondence.py +++ b/aequilibrae/transit/transit_elements/mode_correspondence.py @@ -7,6 +7,6 @@ # 5: '', # 6: '', # 7: '', - 11: 't', + 11: "t", # 12: "R", }