Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test that logs skipped route_types #569

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
14 changes: 11 additions & 3 deletions aequilibrae/transit/lib_gtfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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.
Expand All @@ -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}"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
# 5: '',
# 6: '',
# 7: '',
11: 't',
11: "t",
# 12: "R",
}
6 changes: 4 additions & 2 deletions tests/aequilibrae/transit/test_lib_gtfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading