Skip to content

Commit 4d869fa

Browse files
author
Patrick Qian
authored
Merge pull request #3913 from hove-io/fix_cycle_lane_length_2
[Jormun] expose cycle lane length in street information and fix cycle lane length
2 parents c4b704f + d72b036 commit 4d869fa

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

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

+7
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ def get_via_uri(self, obj):
219219
class StreetInformationSerializer(PbNestedSerializer):
220220
geojson_offset = jsonschema.MethodField(schema_type=int, display_none=False)
221221
cycle_path_type = jsonschema.MethodField(schema_type=str, display_none=False)
222+
length = jsonschema.MethodField(schema_type=float, display_none=False)
222223

223224
def get_cycle_path_type(self, obj):
224225
if obj.HasField(str('cycle_path_type')):
@@ -232,6 +233,12 @@ def get_geojson_offset(self, obj):
232233
else:
233234
return None
234235

236+
def get_length(self, obj):
237+
if obj.HasField(str('length')):
238+
return float("{:.2f}".format(obj.length))
239+
else:
240+
return None
241+
235242

236243
class ElevationSerializer(PbNestedSerializer):
237244
distance_from_start = RoundedField(display_none=True)

source/jormungandr/jormungandr/street_network/asgard.py

+13-9
Original file line numberDiff line numberDiff line change
@@ -255,15 +255,19 @@ def _is_cycle_lane(path):
255255

256256
return False
257257

258-
# We have one journey and several sections in direct path
259-
for section in response.journeys[0].sections:
260-
# do not add cycle_lane_length for bss_rent/bss_return & walking sections
261-
if section.type == response_pb2.STREET_NETWORK and section.street_network.mode == response_pb2.Bike:
262-
cycle_lane_length = sum(
263-
(s.length for s in section.street_network.street_information if _is_cycle_lane(s))
264-
)
265-
# Since path.length are doubles and we want an int32 in the proto
266-
section.cycle_lane_length = int(cycle_lane_length)
258+
# We have multiple journeys and multiple sections in direct path
259+
for journey in response.journeys:
260+
for section in journey.sections:
261+
# do not add cycle_lane_length for bss_rent/bss_return & walking sections
262+
if (
263+
section.type == response_pb2.STREET_NETWORK
264+
and section.street_network.mode == response_pb2.Bike
265+
):
266+
cycle_lane_length = sum(
267+
(s.length for s in section.street_network.street_information if _is_cycle_lane(s))
268+
)
269+
# Since path.length are doubles and we want an int32 in the proto
270+
section.cycle_lane_length = int(cycle_lane_length)
267271

268272
return response
269273

0 commit comments

Comments
 (0)