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

handle ZERO_RESULTS in google matrix #122

Merged
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
24 changes: 16 additions & 8 deletions routingpy/routers/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,13 +515,21 @@ 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"]
]
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)
1 change: 1 addition & 0 deletions tests/test_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@
{
"elements": [
{
"status": "OK",
"distance": {"text": "225 mi", "value": 361957},
"duration": {"text": "3 hours 50 mins", "value": 13813},
}
Expand Down