Commit 4d869fa Patrick Qian
authored
File tree 2 files changed +20
-9
lines changed
source/jormungandr/jormungandr
2 files changed +20
-9
lines changed Original file line number Diff line number Diff line change @@ -219,6 +219,7 @@ def get_via_uri(self, obj):
219
219
class StreetInformationSerializer (PbNestedSerializer ):
220
220
geojson_offset = jsonschema .MethodField (schema_type = int , display_none = False )
221
221
cycle_path_type = jsonschema .MethodField (schema_type = str , display_none = False )
222
+ length = jsonschema .MethodField (schema_type = float , display_none = False )
222
223
223
224
def get_cycle_path_type (self , obj ):
224
225
if obj .HasField (str ('cycle_path_type' )):
@@ -232,6 +233,12 @@ def get_geojson_offset(self, obj):
232
233
else :
233
234
return None
234
235
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
+
235
242
236
243
class ElevationSerializer (PbNestedSerializer ):
237
244
distance_from_start = RoundedField (display_none = True )
Original file line number Diff line number Diff line change @@ -255,15 +255,19 @@ def _is_cycle_lane(path):
255
255
256
256
return False
257
257
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 )
267
271
268
272
return response
269
273
You can’t perform that action at this time.
0 commit comments