From dedf653082d402d16e015f863df3536c0218e1c9 Mon Sep 17 00:00:00 2001 From: khamaileon Date: Fri, 28 Jul 2023 19:07:29 +0200 Subject: [PATCH 1/6] Handle ZERO_RESULTS value in matrix rows --- routingpy/routers/google.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/routingpy/routers/google.py b/routingpy/routers/google.py index c27e2c8..724fa32 100644 --- a/routingpy/routers/google.py +++ b/routingpy/routers/google.py @@ -519,13 +519,16 @@ 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"]: + for element in row["elements"]: + if element["status"] == "OK": + durations.append(element["duration"]["value"]) + distances.append(element["distance"]["value"]) + + else: + durations.append(None) + distances.append(None) return Matrix(durations, distances, response) From 5bd3fba7913efbb36aeefe750bcc7693bf4f3802 Mon Sep 17 00:00:00 2001 From: khamaileon Date: Fri, 28 Jul 2023 19:22:15 +0200 Subject: [PATCH 2/6] Get more itinerary info --- routingpy/routers/opentripplanner_v2.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/routingpy/routers/opentripplanner_v2.py b/routingpy/routers/opentripplanner_v2.py index dd32e05..009d53b 100644 --- a/routingpy/routers/opentripplanner_v2.py +++ b/routingpy/routers/opentripplanner_v2.py @@ -148,9 +148,14 @@ def directions( ) {{ itineraries {{ duration + startTime + endTime legs {{ + startTime + endTime duration distance + mode legGeometry {{ points }} @@ -283,13 +288,13 @@ def raster( use. Default: "WALK,TRANSIT" :type profile: str - :time: Departure date and time. The default value is now. + :time: Departure date and time (timezone aware). The default value is now (UTC). :type time: datetime.datetime :cutoff: The maximum travel duration in seconds. The default value is one hour. - :arrive_by: Whether the itinerary should depart at the specified time (False), or arrive to - the destination at the specified time (True). Default value: False. + :arrive_by: Set to False when searching from the location and True when searching to the + location. Default value: False. :type arrive_by: bool :param dry_run: Print URL and parameters without sending the request. From 0bbeb7727ef0277f400e4cc58647ed697b3f2827 Mon Sep 17 00:00:00 2001 From: khamaileon Date: Fri, 28 Jul 2023 19:22:56 +0200 Subject: [PATCH 3/6] Fix wrong coords order --- routingpy/routers/opentripplanner_v2.py | 1 + routingpy/routers/valhalla.py | 1 + 2 files changed, 2 insertions(+) diff --git a/routingpy/routers/opentripplanner_v2.py b/routingpy/routers/opentripplanner_v2.py index 009d53b..2bb3413 100644 --- a/routingpy/routers/opentripplanner_v2.py +++ b/routingpy/routers/opentripplanner_v2.py @@ -203,6 +203,7 @@ def _parse_legs(self, legs): geometry.extend(points) distance += int(leg["distance"]) + geometry = [coord[::-1] for coord in geometry] return geometry, distance def isochrones( diff --git a/routingpy/routers/valhalla.py b/routingpy/routers/valhalla.py index 3048b91..c52ca4d 100644 --- a/routingpy/routers/valhalla.py +++ b/routingpy/routers/valhalla.py @@ -282,6 +282,7 @@ def parse_direction_json(response, units): factor = 0.621371 if units == "mi" else 1 distance += int(leg["summary"]["length"] * 1000 * factor) + geometry = [coord[::-1] for coord in geometry] return Direction(geometry=geometry, duration=int(duration), distance=int(distance), raw=response) def isochrones( # noqa: C901 From fe242f5c83c4a49c23c0c9a8107f58ae73a89d73 Mon Sep 17 00:00:00 2001 From: khamaileon Date: Wed, 2 Aug 2023 10:42:16 +0200 Subject: [PATCH 4/6] Revert "Handle ZERO_RESULTS value in matrix rows" This reverts commit dedf653082d402d16e015f863df3536c0218e1c9. --- routingpy/routers/google.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/routingpy/routers/google.py b/routingpy/routers/google.py index 724fa32..c27e2c8 100644 --- a/routingpy/routers/google.py +++ b/routingpy/routers/google.py @@ -519,16 +519,13 @@ def parse_matrix_json(response): if response is None: # pragma: no cover return Matrix() - durations = [] - distances = [] - for row in response["rows"]: - for element in row["elements"]: - if element["status"] == "OK": - durations.append(element["duration"]["value"]) - distances.append(element["distance"]["value"]) - - else: - durations.append(None) - distances.append(None) + 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"] + ] return Matrix(durations, distances, response) From a98b1ccf6be2e5ebe9a74a6186dec7f043bed575 Mon Sep 17 00:00:00 2001 From: khamaileon Date: Wed, 2 Aug 2023 12:02:26 +0200 Subject: [PATCH 5/6] Remove api_key unused param --- routingpy/routers/opentripplanner_v2.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/routingpy/routers/opentripplanner_v2.py b/routingpy/routers/opentripplanner_v2.py index 2bb3413..177ca6e 100644 --- a/routingpy/routers/opentripplanner_v2.py +++ b/routingpy/routers/opentripplanner_v2.py @@ -32,7 +32,6 @@ class OpenTripPlannerV2: def __init__( self, - api_key: Optional[str] = None, base_url: Optional[str] = _DEFAULT_BASE_URL, user_agent: Optional[str] = None, timeout: Optional[int] = DEFAULT, @@ -45,8 +44,6 @@ def __init__( """ Initializes an OpenTripPlannerV2 client. - :param api_key: NOT USED, only for compatibility with other providers. - :param base_url: The base URL for the request. Defaults to localhost. Should not have a trailing slash. :type base_url: str From 91fa2c6eda87223e64c4d8162daf90a90ab52854 Mon Sep 17 00:00:00 2001 From: khamaileon Date: Wed, 2 Aug 2023 12:53:13 +0200 Subject: [PATCH 6/6] Fix coords order --- routingpy/routers/google.py | 8 ++------ routingpy/routers/opentripplanner_v2.py | 3 +-- routingpy/routers/valhalla.py | 1 - 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/routingpy/routers/google.py b/routingpy/routers/google.py index c27e2c8..d832179 100644 --- a/routingpy/routers/google.py +++ b/routingpy/routers/google.py @@ -369,12 +369,8 @@ def parse_direction_json(response, alternatives): duration += leg["duration"]["value"] distance += leg["distance"]["value"] for step in leg["steps"]: - geometry.extend( - [ - list(reversed(coords)) - for coords in utils.decode_polyline5(step["polyline"]["points"]) - ] - ) + geometry.extend(utils.decode_polyline5(step["polyline"]["points"])) + return Direction(geometry=geometry, duration=duration, distance=distance, raw=response) def isochrones(self): # pragma: no cover diff --git a/routingpy/routers/opentripplanner_v2.py b/routingpy/routers/opentripplanner_v2.py index 177ca6e..eb0a5bd 100644 --- a/routingpy/routers/opentripplanner_v2.py +++ b/routingpy/routers/opentripplanner_v2.py @@ -197,10 +197,9 @@ def _parse_legs(self, legs): geometry = [] for leg in legs: points = utils.decode_polyline5(leg["legGeometry"]["points"]) - geometry.extend(points) + geometry.extend(list(reversed(points))) distance += int(leg["distance"]) - geometry = [coord[::-1] for coord in geometry] return geometry, distance def isochrones( diff --git a/routingpy/routers/valhalla.py b/routingpy/routers/valhalla.py index c52ca4d..3048b91 100644 --- a/routingpy/routers/valhalla.py +++ b/routingpy/routers/valhalla.py @@ -282,7 +282,6 @@ def parse_direction_json(response, units): factor = 0.621371 if units == "mi" else 1 distance += int(leg["summary"]["length"] * 1000 * factor) - geometry = [coord[::-1] for coord in geometry] return Direction(geometry=geometry, duration=int(duration), distance=int(distance), raw=response) def isochrones( # noqa: C901