Skip to content

Commit

Permalink
handle ZERO_RESULTS in google matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
khamaileon committed Oct 27, 2023
1 parent 2f0594b commit 6b49883
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions routingpy/routers/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,13 +515,26 @@ def parse_matrix_json(response):
if response is None: # pragma: no cover
return Matrix()

durations = [
[destination["duration"]["value"] for destination in origin["elements"]]
for origin in response["rows"]
]
distances = [
[destination["distance"]["value"] for destination in origin["elements"]]
for origin in response["rows"]
]
@staticmethod
def parse_matrix_json(response):
if response is None: # pragma: no cover
return Matrix()

durations = []
distances = []
for row in response["rows"]:
row_durations = []
row_distances = []
for element in row["elements"]:
if element["status"] == "OK":
row_durations.append(element["duration"]["value"])
row_distances.append(element["distance"]["value"])

else:
row_durations.append(None)
row_distances.append(None)

durations.append(row_durations)
distances.append(row_distances)

return Matrix(durations, distances, response)

0 comments on commit 6b49883

Please sign in to comment.