From 04bbb3284991e7afd71d748cffdeec1b122df2f1 Mon Sep 17 00:00:00 2001 From: Mario de Frutos Date: Thu, 29 Nov 2018 11:51:59 +0100 Subject: [PATCH] Added mode type to Tomtom routing functions --- .../cartodb_services/tomtom/routing.py | 10 ++++++---- .../cartodb_services/cartodb_services/tomtom/types.py | 6 ++++++ server/lib/python/cartodb_services/setup.py | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/server/lib/python/cartodb_services/cartodb_services/tomtom/routing.py b/server/lib/python/cartodb_services/cartodb_services/tomtom/routing.py index 71dfa22..bde251c 100644 --- a/server/lib/python/cartodb_services/cartodb_services/tomtom/routing.py +++ b/server/lib/python/cartodb_services/cartodb_services/tomtom/routing.py @@ -11,13 +11,14 @@ from cartodb_services.tools.coordinates import (validate_coordinates, marshall_coordinates) from cartodb_services.tools.exceptions import ServiceException from cartodb_services.tools.qps import qps_retry -from types import (DEFAULT_PROFILE, VALID_PROFILES, DEFAULT_DEPARTAT) +from types import (DEFAULT_PROFILE, DEFAULT_ROUTE_TYPE, VALID_PROFILES, DEFAULT_DEPARTAT) BASEURI = ('https://api.tomtom.com/routing/1/calculateRoute/' '{coordinates}' '/json' '?key={apikey}' '&travelMode={travelmode}' + '&routeType={route_type}' '&departAt={departat}' '&computeBestOrder=true') @@ -45,10 +46,11 @@ class TomTomRouting(Traceable): self._logger = logger def _uri(self, coordinates, profile=DEFAULT_PROFILE, - date_time=DEFAULT_DEPARTAT): + date_time=DEFAULT_DEPARTAT, route_type=DEFAULT_ROUTE_TYPE): uri = URITemplate(BASEURI).expand(apikey=self._apikey, coordinates=coordinates, travelmode=profile, + route_type=route_type, departat=date_time) return uri @@ -91,13 +93,13 @@ class TomTomRouting(Traceable): @qps_retry(qps=5, provider='tomtom') def directions(self, waypoints, profile=DEFAULT_PROFILE, - date_time=DEFAULT_DEPARTAT): + date_time=DEFAULT_DEPARTAT, route_type=DEFAULT_ROUTE_TYPE): self._validate_profile(profile) validate_coordinates(waypoints, NUM_WAYPOINTS_MIN, NUM_WAYPOINTS_MAX) coordinates = self._marshall_coordinates(waypoints) - uri = self._uri(coordinates, profile, date_time) + uri = self._uri(coordinates, profile, date_time, route_type) try: response = requests.get(uri) diff --git a/server/lib/python/cartodb_services/cartodb_services/tomtom/types.py b/server/lib/python/cartodb_services/cartodb_services/tomtom/types.py index 4a7f082..67b1f34 100644 --- a/server/lib/python/cartodb_services/cartodb_services/tomtom/types.py +++ b/server/lib/python/cartodb_services/cartodb_services/tomtom/types.py @@ -24,3 +24,9 @@ TRANSPORT_MODE_TO_TOMTOM = { 'walk': 'pedestrian', 'bicycle': 'bicycle', } + +DEFAULT_ROUTE_TYPE = 'shortest' +MODE_TYPE_TO_TOMTOM = { + 'shortest': 'shortest', + 'fastest': 'fastest' +} diff --git a/server/lib/python/cartodb_services/setup.py b/server/lib/python/cartodb_services/setup.py index 02323b8..5263621 100644 --- a/server/lib/python/cartodb_services/setup.py +++ b/server/lib/python/cartodb_services/setup.py @@ -10,7 +10,7 @@ from setuptools import setup, find_packages setup( name='cartodb_services', - version='0.20.2', + version='0.21.0', description='CartoDB Services API Python Library',