Skip to content

Commit 86b8946

Browse files
authored
Merge pull request #4338 from hove-io/fix_traversal_time_parkmode
Fix traversal time parkmode
2 parents 6b5a427 + 7666ded commit 86b8946

File tree

3 files changed

+67
-4
lines changed

3 files changed

+67
-4
lines changed

source/jormungandr/jormungandr/interfaces/v1/serializer/journey.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ def get_to(self, obj):
367367
if obj.HasField(str('type')):
368368
enum = obj.DESCRIPTOR.fields_by_name['type'].enum_type.values_by_number
369369
ret_value = enum[getattr(obj, 'type')].name
370-
if ret_value == 'WAITING':
370+
if ret_value == 'WAITING' or (ret_value == 'PARK' and 'section_bike_park' in obj.id):
371371
return None
372372
return PlaceSerializer(obj.destination).data
373373

@@ -377,7 +377,7 @@ def get__from(self, obj):
377377
if obj.HasField(str('type')):
378378
enum = obj.DESCRIPTOR.fields_by_name['type'].enum_type.values_by_number
379379
ret_value = enum[getattr(obj, 'type')].name
380-
if ret_value == 'WAITING':
380+
if ret_value == 'WAITING' or (ret_value == 'PARK' and 'section_bike_park' in obj.id):
381381
return None
382382
return PlaceSerializer(obj.origin).data
383383

source/jormungandr/jormungandr/scenarios/helper_classes/helper_utils.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -597,9 +597,13 @@ def _update_fallback_with_bike_mode(
597597
[fallback_sections[-1].street_network.path_items[-1]]
598598
)
599599
fallback_sections[-1].street_network.path_items.pop()
600-
target_section.duration += via_pt_access.access_point.traversal_time
601-
target_section.length += via_pt_access.access_point.length
600+
# update the duration and length of the sections
601+
# the duration and length of the target section is the duration and length of the access point
602+
# 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
603+
target_section.duration = via_pt_access.access_point.traversal_time
604+
target_section.length = via_pt_access.access_point.length
602605
fallback_sections[-1].duration -= via_pt_access.access_point.traversal_time
606+
fallback_sections[-1].length -= via_pt_access.access_point.length
603607
else:
604608
fallback_sections[-1].vias.add().CopyFrom(via_pt_access.access_point)
605609

source/jormungandr/tests/routing_tests_experimental.py

+59
Original file line numberDiff line numberDiff line change
@@ -1706,3 +1706,62 @@ def test_bike_with_parking_penalty_multiple_first_section_mode_park_mode_park_an
17061706

17071707
assert journey['sections'][0]['mode'] in ['bike', 'walking']
17081708
assert journey['sections'][1]['type'] != 'park'
1709+
1710+
def test_bike_park_section_from_to_none(self):
1711+
query = (
1712+
sub_query
1713+
+ "&datetime=20120614T075000"
1714+
+ "&first_section_mode[]=bike"
1715+
+ "&bike_speed=0.05"
1716+
+ "&park_mode=on_street"
1717+
+ "&_access_points=true"
1718+
)
1719+
1720+
response = self.query_region(query)
1721+
check_best(response)
1722+
1723+
journeys = get_not_null(response, 'journeys')
1724+
pt_journeys = [j for j in journeys if 'bike' in j['tags'] and 'non_pt_bike' not in j['tags']]
1725+
assert len(pt_journeys) > 0
1726+
print("Blablab", len(pt_journeys[0]["sections"]))
1727+
for journey in pt_journeys:
1728+
assert journey['sections'][1]['type'] == 'park'
1729+
assert 'from' not in journey['sections'][1]
1730+
assert 'to' not in journey['sections'][1]
1731+
1732+
def test_bike_traversal_time(self):
1733+
query = (
1734+
sub_query
1735+
+ "&datetime=20120614T075000"
1736+
+ "&first_section_mode[]=bike"
1737+
+ "&bike_speed=0.05"
1738+
+ "&debug=true"
1739+
+ "&_access_points=true"
1740+
)
1741+
1742+
# We begin with a normal request to get the fallback duration without the park_mode
1743+
response = self.query_region(query)
1744+
check_best(response)
1745+
journeys = get_not_null(response, 'journeys')
1746+
pt_journeys = [j for j in journeys if 'bike' in j['tags'] and 'non_pt_bike' not in j['tags']]
1747+
assert len(pt_journeys) == 1
1748+
1749+
query = (
1750+
sub_query
1751+
+ "&datetime=20120614T075000"
1752+
+ "&first_section_mode[]=bike"
1753+
+ "&bike_speed=0.05"
1754+
+ "&park_mode=on_street"
1755+
+ "&_access_points=true"
1756+
)
1757+
1758+
# 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
1759+
response_2 = self.query_region(query)
1760+
check_best(response_2)
1761+
journeys_2 = get_not_null(response_2, 'journeys')
1762+
pt_journeys_2 = [j for j in journeys_2 if 'bike' in j['tags'] and 'non_pt_bike' not in j['tags']]
1763+
assert len(pt_journeys_2) == 1
1764+
assert (
1765+
pt_journeys[0]["sections"][0]["duration"]
1766+
== pt_journeys_2[0]["sections"][0]["duration"] + pt_journeys_2[0]["sections"][2]["duration"]
1767+
)

0 commit comments

Comments
 (0)