From 50eeb1c872ba4baf0049e5b4285643bd6b83d9da Mon Sep 17 00:00:00 2001 From: Pondonda Date: Mon, 30 Dec 2024 09:04:58 +0100 Subject: [PATCH 01/10] park section origin destination none --- .../jormungandr/scenarios/helper_classes/helper_utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/jormungandr/jormungandr/scenarios/helper_classes/helper_utils.py b/source/jormungandr/jormungandr/scenarios/helper_classes/helper_utils.py index 32dec3658e..97ab42b539 100644 --- a/source/jormungandr/jormungandr/scenarios/helper_classes/helper_utils.py +++ b/source/jormungandr/jormungandr/scenarios/helper_classes/helper_utils.py @@ -198,6 +198,8 @@ def _make_ending_car_park_sections( def _make_bike_park(begin_date_time, duration): bike_park_section = response_pb2.Section() bike_park_section.id = "section_bike_park" + bike_park_section.origin = None + bike_park_section.destination = None bike_park_section.duration = duration bike_park_section.type = response_pb2.PARK bike_park_section.begin_date_time = begin_date_time From 6ec5daa06324c49dd558c38090fdf722fd4c5c56 Mon Sep 17 00:00:00 2001 From: Pondonda Date: Mon, 30 Dec 2024 09:16:05 +0100 Subject: [PATCH 02/10] fix traversal time --- .../jormungandr/scenarios/helper_classes/helper_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/jormungandr/jormungandr/scenarios/helper_classes/helper_utils.py b/source/jormungandr/jormungandr/scenarios/helper_classes/helper_utils.py index 97ab42b539..49da25992e 100644 --- a/source/jormungandr/jormungandr/scenarios/helper_classes/helper_utils.py +++ b/source/jormungandr/jormungandr/scenarios/helper_classes/helper_utils.py @@ -599,8 +599,8 @@ def _update_fallback_with_bike_mode( [fallback_sections[-1].street_network.path_items[-1]] ) fallback_sections[-1].street_network.path_items.pop() - target_section.duration += via_pt_access.access_point.traversal_time - target_section.length += via_pt_access.access_point.length + target_section.duration = via_pt_access.access_point.traversal_time + target_section.length = via_pt_access.access_point.length fallback_sections[-1].duration -= via_pt_access.access_point.traversal_time else: fallback_sections[-1].vias.add().CopyFrom(via_pt_access.access_point) From f98f0830a88dc5383c83de6fbf10990c90300ab3 Mon Sep 17 00:00:00 2001 From: Pondonda Date: Mon, 6 Jan 2025 17:21:23 +0100 Subject: [PATCH 03/10] fix traversal time and serializer for park --- .../jormungandr/interfaces/v1/serializer/journey.py | 4 ++-- .../jormungandr/scenarios/helper_classes/helper_utils.py | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/source/jormungandr/jormungandr/interfaces/v1/serializer/journey.py b/source/jormungandr/jormungandr/interfaces/v1/serializer/journey.py index e93eca9457..36a435feaa 100644 --- a/source/jormungandr/jormungandr/interfaces/v1/serializer/journey.py +++ b/source/jormungandr/jormungandr/interfaces/v1/serializer/journey.py @@ -367,7 +367,7 @@ def get_to(self, obj): if obj.HasField(str('type')): enum = obj.DESCRIPTOR.fields_by_name['type'].enum_type.values_by_number ret_value = enum[getattr(obj, 'type')].name - if ret_value == 'WAITING': + if ret_value == 'WAITING' or ret_value == 'PARK': return None return PlaceSerializer(obj.destination).data @@ -377,7 +377,7 @@ def get__from(self, obj): if obj.HasField(str('type')): enum = obj.DESCRIPTOR.fields_by_name['type'].enum_type.values_by_number ret_value = enum[getattr(obj, 'type')].name - if ret_value == 'WAITING': + if ret_value == 'WAITING' or ret_value == 'PARK': return None return PlaceSerializer(obj.origin).data diff --git a/source/jormungandr/jormungandr/scenarios/helper_classes/helper_utils.py b/source/jormungandr/jormungandr/scenarios/helper_classes/helper_utils.py index 49da25992e..94d23c9432 100644 --- a/source/jormungandr/jormungandr/scenarios/helper_classes/helper_utils.py +++ b/source/jormungandr/jormungandr/scenarios/helper_classes/helper_utils.py @@ -602,6 +602,7 @@ def _update_fallback_with_bike_mode( target_section.duration = via_pt_access.access_point.traversal_time target_section.length = via_pt_access.access_point.length fallback_sections[-1].duration -= via_pt_access.access_point.traversal_time + fallback_sections[-1].length -= via_pt_access.access_point.length else: fallback_sections[-1].vias.add().CopyFrom(via_pt_access.access_point) From 6bc8efe5c17750a455dbab4b58f7672418e4526c Mon Sep 17 00:00:00 2001 From: Pondonda Date: Mon, 6 Jan 2025 17:22:44 +0100 Subject: [PATCH 04/10] remove parking mode none --- .../jormungandr/scenarios/helper_classes/helper_utils.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/source/jormungandr/jormungandr/scenarios/helper_classes/helper_utils.py b/source/jormungandr/jormungandr/scenarios/helper_classes/helper_utils.py index 94d23c9432..06853b5666 100644 --- a/source/jormungandr/jormungandr/scenarios/helper_classes/helper_utils.py +++ b/source/jormungandr/jormungandr/scenarios/helper_classes/helper_utils.py @@ -198,8 +198,6 @@ def _make_ending_car_park_sections( def _make_bike_park(begin_date_time, duration): bike_park_section = response_pb2.Section() bike_park_section.id = "section_bike_park" - bike_park_section.origin = None - bike_park_section.destination = None bike_park_section.duration = duration bike_park_section.type = response_pb2.PARK bike_park_section.begin_date_time = begin_date_time From 59081973ff7c2a80abb272ee30d3f89748a2aca9 Mon Sep 17 00:00:00 2001 From: Pondonda Date: Tue, 7 Jan 2025 08:37:31 +0100 Subject: [PATCH 05/10] add specification for serializer --- .../jormungandr/interfaces/v1/serializer/journey.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/jormungandr/jormungandr/interfaces/v1/serializer/journey.py b/source/jormungandr/jormungandr/interfaces/v1/serializer/journey.py index 36a435feaa..e5e54e4875 100644 --- a/source/jormungandr/jormungandr/interfaces/v1/serializer/journey.py +++ b/source/jormungandr/jormungandr/interfaces/v1/serializer/journey.py @@ -367,7 +367,7 @@ def get_to(self, obj): if obj.HasField(str('type')): enum = obj.DESCRIPTOR.fields_by_name['type'].enum_type.values_by_number ret_value = enum[getattr(obj, 'type')].name - if ret_value == 'WAITING' or ret_value == 'PARK': + if ret_value == 'WAITING' or (ret_value == 'PARK' and obj.id == 'section_bike_park_1'): return None return PlaceSerializer(obj.destination).data @@ -377,7 +377,7 @@ def get__from(self, obj): if obj.HasField(str('type')): enum = obj.DESCRIPTOR.fields_by_name['type'].enum_type.values_by_number ret_value = enum[getattr(obj, 'type')].name - if ret_value == 'WAITING' or ret_value == 'PARK': + if ret_value == 'WAITING' or (ret_value == 'PARK' and obj.id == 'section_bike_park_1'): return None return PlaceSerializer(obj.origin).data From 6581fbf61325e7e8e07fa966fd1da56fd9ac57de Mon Sep 17 00:00:00 2001 From: Pondonda Date: Thu, 9 Jan 2025 09:05:57 +0100 Subject: [PATCH 06/10] update serializer and comment function --- .../jormungandr/interfaces/v1/serializer/journey.py | 4 ++-- .../jormungandr/scenarios/helper_classes/helper_utils.py | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/source/jormungandr/jormungandr/interfaces/v1/serializer/journey.py b/source/jormungandr/jormungandr/interfaces/v1/serializer/journey.py index e5e54e4875..91c722ffb1 100644 --- a/source/jormungandr/jormungandr/interfaces/v1/serializer/journey.py +++ b/source/jormungandr/jormungandr/interfaces/v1/serializer/journey.py @@ -367,7 +367,7 @@ def get_to(self, obj): if obj.HasField(str('type')): enum = obj.DESCRIPTOR.fields_by_name['type'].enum_type.values_by_number ret_value = enum[getattr(obj, 'type')].name - if ret_value == 'WAITING' or (ret_value == 'PARK' and obj.id == 'section_bike_park_1'): + if ret_value == 'WAITING' or (ret_value == 'PARK' and 'section_bike_park' in obj.id): return None return PlaceSerializer(obj.destination).data @@ -377,7 +377,7 @@ def get__from(self, obj): if obj.HasField(str('type')): enum = obj.DESCRIPTOR.fields_by_name['type'].enum_type.values_by_number ret_value = enum[getattr(obj, 'type')].name - if ret_value == 'WAITING' or (ret_value == 'PARK' and obj.id == 'section_bike_park_1'): + if ret_value == 'WAITING' or (ret_value == 'PARK' and 'section_bike_park' in obj.id): return None return PlaceSerializer(obj.origin).data diff --git a/source/jormungandr/jormungandr/scenarios/helper_classes/helper_utils.py b/source/jormungandr/jormungandr/scenarios/helper_classes/helper_utils.py index 06853b5666..3688beb8f2 100644 --- a/source/jormungandr/jormungandr/scenarios/helper_classes/helper_utils.py +++ b/source/jormungandr/jormungandr/scenarios/helper_classes/helper_utils.py @@ -597,6 +597,9 @@ def _update_fallback_with_bike_mode( [fallback_sections[-1].street_network.path_items[-1]] ) fallback_sections[-1].street_network.path_items.pop() + # update the duration and length of the sections + # the duration and length of the target section is the duration and length of the access point + # the duration and length of the fallback section is the duration and length of the street network minus the duration and length of the access point target_section.duration = via_pt_access.access_point.traversal_time target_section.length = via_pt_access.access_point.length fallback_sections[-1].duration -= via_pt_access.access_point.traversal_time From a4f930c434a171ad5e68fc5931d5aa65de1b2f66 Mon Sep 17 00:00:00 2001 From: Pondonda Date: Mon, 13 Jan 2025 13:37:32 +0100 Subject: [PATCH 07/10] add section from to none tests --- .../tests/routing_tests_experimental.py | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/source/jormungandr/tests/routing_tests_experimental.py b/source/jormungandr/tests/routing_tests_experimental.py index 85e9a4736f..af58307d62 100644 --- a/source/jormungandr/tests/routing_tests_experimental.py +++ b/source/jormungandr/tests/routing_tests_experimental.py @@ -1706,3 +1706,25 @@ def test_bike_with_parking_penalty_multiple_first_section_mode_park_mode_park_an assert journey['sections'][0]['mode'] in ['bike', 'walking'] assert journey['sections'][1]['type'] != 'park' + + def test_bike_park_section_from_to_none(self): + query = ( + sub_query + + "&datetime=20120614T075000" + + "&first_section_mode[]=bike" + + "&bike_speed=0.05" + + "&park_mode=on_street" + + "&_access_points=true" + ) + + response = self.query_region(query) + check_best(response) + + journeys = get_not_null(response, 'journeys') + pt_journeys = [j for j in journeys if 'bike' in j['tags'] and 'non_pt_bike' not in j['tags']] + assert len(pt_journeys) > 0 + print("Blablab", pt_journeys[0]["sections"][1]) + for journey in pt_journeys: + assert journey['sections'][1]['type'] == 'park' + assert 'from' not in journey['sections'][1] + assert 'to' not in journey['sections'][1] From 6b105e62a624a6f6356b7565cba4361523147acf Mon Sep 17 00:00:00 2001 From: Pondonda Date: Mon, 13 Jan 2025 14:10:21 +0100 Subject: [PATCH 08/10] remove print statement --- source/jormungandr/tests/routing_tests_experimental.py | 1 - 1 file changed, 1 deletion(-) diff --git a/source/jormungandr/tests/routing_tests_experimental.py b/source/jormungandr/tests/routing_tests_experimental.py index af58307d62..080c6dbdab 100644 --- a/source/jormungandr/tests/routing_tests_experimental.py +++ b/source/jormungandr/tests/routing_tests_experimental.py @@ -1723,7 +1723,6 @@ def test_bike_park_section_from_to_none(self): journeys = get_not_null(response, 'journeys') pt_journeys = [j for j in journeys if 'bike' in j['tags'] and 'non_pt_bike' not in j['tags']] assert len(pt_journeys) > 0 - print("Blablab", pt_journeys[0]["sections"][1]) for journey in pt_journeys: assert journey['sections'][1]['type'] == 'park' assert 'from' not in journey['sections'][1] From f742c5cd0f367aaf31016cb4b7be2f35371f8e37 Mon Sep 17 00:00:00 2001 From: Pondonda Date: Mon, 13 Jan 2025 15:05:25 +0100 Subject: [PATCH 09/10] add traversal time tests --- .../tests/routing_tests_experimental.py | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/source/jormungandr/tests/routing_tests_experimental.py b/source/jormungandr/tests/routing_tests_experimental.py index 080c6dbdab..4eaff8da02 100644 --- a/source/jormungandr/tests/routing_tests_experimental.py +++ b/source/jormungandr/tests/routing_tests_experimental.py @@ -1723,7 +1723,45 @@ def test_bike_park_section_from_to_none(self): journeys = get_not_null(response, 'journeys') pt_journeys = [j for j in journeys if 'bike' in j['tags'] and 'non_pt_bike' not in j['tags']] assert len(pt_journeys) > 0 + print("Blablab", len(pt_journeys[0]["sections"])) for journey in pt_journeys: assert journey['sections'][1]['type'] == 'park' - assert 'from' not in journey['sections'][1] + assert 'from' in journey['sections'][1] assert 'to' not in journey['sections'][1] + + def test_bike_traversal_time(self): + query = ( + sub_query + + "&datetime=20120614T075000" + + "&first_section_mode[]=bike" + + "&bike_speed=0.05" + + "&debug=true" + + "&_access_points=true" + ) + + # We begin with a normal request to get the fallback duration without the park_mode + response = self.query_region(query) + check_best(response) + journeys = get_not_null(response, 'journeys') + pt_journeys = [j for j in journeys if 'bike' in j['tags'] and 'non_pt_bike' not in j['tags']] + assert len(pt_journeys) == 1 + + query = ( + sub_query + + "&datetime=20120614T075000" + + "&first_section_mode[]=bike" + + "&bike_speed=0.05" + + "&park_mode=on_street" + + "&_access_points=true" + ) + + # With a request with the park_mode, we expect the same duration as the previous request if we add the first and the street network section following the park section + response_2 = self.query_region(query) + check_best(response_2) + journeys_2 = get_not_null(response_2, 'journeys') + pt_journeys_2 = [j for j in journeys_2 if 'bike' in j['tags'] and 'non_pt_bike' not in j['tags']] + assert len(pt_journeys_2) == 1 + assert ( + pt_journeys[0]["sections"][0]["duration"] + == pt_journeys_2[0]["sections"][0]["duration"] + pt_journeys_2[0]["sections"][2]["duration"] + ) From 7666ded97c5f5ad9d7c3632e418b832fdffce310 Mon Sep 17 00:00:00 2001 From: Pondonda Date: Mon, 13 Jan 2025 15:52:08 +0100 Subject: [PATCH 10/10] fix tests --- source/jormungandr/tests/routing_tests_experimental.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/jormungandr/tests/routing_tests_experimental.py b/source/jormungandr/tests/routing_tests_experimental.py index 4eaff8da02..d41745c788 100644 --- a/source/jormungandr/tests/routing_tests_experimental.py +++ b/source/jormungandr/tests/routing_tests_experimental.py @@ -1726,7 +1726,7 @@ def test_bike_park_section_from_to_none(self): print("Blablab", len(pt_journeys[0]["sections"])) for journey in pt_journeys: assert journey['sections'][1]['type'] == 'park' - assert 'from' in journey['sections'][1] + assert 'from' not in journey['sections'][1] assert 'to' not in journey['sections'][1] def test_bike_traversal_time(self):