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

[Jormun] expose cycle lane length in street information and fix cycle lane length #3913

Merged
merged 1 commit into from
Jan 27, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ def get_via_uri(self, obj):
class StreetInformationSerializer(PbNestedSerializer):
geojson_offset = jsonschema.MethodField(schema_type=int, display_none=False)
cycle_path_type = jsonschema.MethodField(schema_type=str, display_none=False)
length = jsonschema.MethodField(schema_type=float, display_none=False)

def get_cycle_path_type(self, obj):
if obj.HasField(str('cycle_path_type')):
Expand All @@ -232,6 +233,12 @@ def get_geojson_offset(self, obj):
else:
return None

def get_length(self, obj):
if obj.HasField(str('length')):
return float("{:.2f}".format(obj.length))
else:
return None


class ElevationSerializer(PbNestedSerializer):
distance_from_start = RoundedField(display_none=True)
Expand Down
22 changes: 13 additions & 9 deletions source/jormungandr/jormungandr/street_network/asgard.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,15 +255,19 @@ def _is_cycle_lane(path):

return False

# We have one journey and several sections in direct path
for section in response.journeys[0].sections:
# do not add cycle_lane_length for bss_rent/bss_return & walking sections
if section.type == response_pb2.STREET_NETWORK and section.street_network.mode == response_pb2.Bike:
cycle_lane_length = sum(
(s.length for s in section.street_network.street_information if _is_cycle_lane(s))
)
# Since path.length are doubles and we want an int32 in the proto
section.cycle_lane_length = int(cycle_lane_length)
# We have multiple journeys and multiple sections in direct path
for journey in response.journeys:
for section in journey.sections:
# do not add cycle_lane_length for bss_rent/bss_return & walking sections
if (
section.type == response_pb2.STREET_NETWORK
and section.street_network.mode == response_pb2.Bike
):
cycle_lane_length = sum(
(s.length for s in section.street_network.street_information if _is_cycle_lane(s))
)
# Since path.length are doubles and we want an int32 in the proto
section.cycle_lane_length = int(cycle_lane_length)

return response

Expand Down