Skip to content
This repository was archived by the owner on Mar 29, 2025. It is now read-only.

fix(valhalla): Remove unit conversion logic #139

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
14 changes: 5 additions & 9 deletions routingpy/routers/valhalla.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,7 @@ def directions(
)

return self.parse_direction_json(
self.client._request("/route", post_params=params, dry_run=dry_run),
units,
self.client._request("/route", post_params=params, dry_run=dry_run)
)

@staticmethod
Expand Down Expand Up @@ -265,7 +264,7 @@ def get_direction_params(
return params

@staticmethod
def parse_direction_json(response, units):
def parse_direction_json(response):
if response is None: # pragma: no cover
return Direction()

Expand All @@ -274,8 +273,7 @@ def parse_direction_json(response, units):
geometry.extend(utils.decode_polyline6(leg["shape"]))
duration += leg["summary"]["time"]

factor = 0.621371 if units == "mi" else 1
distance += int(leg["summary"]["length"] * 1000 * factor)
distance += leg["summary"]["length"]

return Direction(geometry=geometry, duration=int(duration), distance=int(distance), raw=response)

Expand Down Expand Up @@ -577,7 +575,6 @@ def matrix(

return self.parse_matrix_json(
self.client._request("/sources_to_targets", post_params=params, dry_run=dry_run),
units,
)

@staticmethod
Expand Down Expand Up @@ -646,17 +643,16 @@ def get_matrix_params(
return params

@staticmethod
def parse_matrix_json(response, units):
def parse_matrix_json(response):
if response is None: # pragma: no cover
return Matrix()

factor = 0.621371 if units == "mi" else 1
durations = [
[destination["time"] for destination in origin] for origin in response["sources_to_targets"]
]
distances = [
[
int(destination["distance"] * 1000 * factor)
destination["distance"]
if destination["distance"] is not None
else None
for destination in origin
Expand Down