Added mode type to Tomtom routing functions
This commit is contained in:
@@ -11,13 +11,14 @@ from cartodb_services.tools.coordinates import (validate_coordinates,
|
|||||||
marshall_coordinates)
|
marshall_coordinates)
|
||||||
from cartodb_services.tools.exceptions import ServiceException
|
from cartodb_services.tools.exceptions import ServiceException
|
||||||
from cartodb_services.tools.qps import qps_retry
|
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/'
|
BASEURI = ('https://api.tomtom.com/routing/1/calculateRoute/'
|
||||||
'{coordinates}'
|
'{coordinates}'
|
||||||
'/json'
|
'/json'
|
||||||
'?key={apikey}'
|
'?key={apikey}'
|
||||||
'&travelMode={travelmode}'
|
'&travelMode={travelmode}'
|
||||||
|
'&routeType={route_type}'
|
||||||
'&departAt={departat}'
|
'&departAt={departat}'
|
||||||
'&computeBestOrder=true')
|
'&computeBestOrder=true')
|
||||||
|
|
||||||
@@ -45,10 +46,11 @@ class TomTomRouting(Traceable):
|
|||||||
self._logger = logger
|
self._logger = logger
|
||||||
|
|
||||||
def _uri(self, coordinates, profile=DEFAULT_PROFILE,
|
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,
|
uri = URITemplate(BASEURI).expand(apikey=self._apikey,
|
||||||
coordinates=coordinates,
|
coordinates=coordinates,
|
||||||
travelmode=profile,
|
travelmode=profile,
|
||||||
|
route_type=route_type,
|
||||||
departat=date_time)
|
departat=date_time)
|
||||||
return uri
|
return uri
|
||||||
|
|
||||||
@@ -91,13 +93,13 @@ class TomTomRouting(Traceable):
|
|||||||
|
|
||||||
@qps_retry(qps=5, provider='tomtom')
|
@qps_retry(qps=5, provider='tomtom')
|
||||||
def directions(self, waypoints, profile=DEFAULT_PROFILE,
|
def directions(self, waypoints, profile=DEFAULT_PROFILE,
|
||||||
date_time=DEFAULT_DEPARTAT):
|
date_time=DEFAULT_DEPARTAT, route_type=DEFAULT_ROUTE_TYPE):
|
||||||
self._validate_profile(profile)
|
self._validate_profile(profile)
|
||||||
validate_coordinates(waypoints, NUM_WAYPOINTS_MIN, NUM_WAYPOINTS_MAX)
|
validate_coordinates(waypoints, NUM_WAYPOINTS_MIN, NUM_WAYPOINTS_MAX)
|
||||||
|
|
||||||
coordinates = self._marshall_coordinates(waypoints)
|
coordinates = self._marshall_coordinates(waypoints)
|
||||||
|
|
||||||
uri = self._uri(coordinates, profile, date_time)
|
uri = self._uri(coordinates, profile, date_time, route_type)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = requests.get(uri)
|
response = requests.get(uri)
|
||||||
|
|||||||
@@ -24,3 +24,9 @@ TRANSPORT_MODE_TO_TOMTOM = {
|
|||||||
'walk': 'pedestrian',
|
'walk': 'pedestrian',
|
||||||
'bicycle': 'bicycle',
|
'bicycle': 'bicycle',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DEFAULT_ROUTE_TYPE = 'shortest'
|
||||||
|
MODE_TYPE_TO_TOMTOM = {
|
||||||
|
'shortest': 'shortest',
|
||||||
|
'fastest': 'fastest'
|
||||||
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ from setuptools import setup, find_packages
|
|||||||
setup(
|
setup(
|
||||||
name='cartodb_services',
|
name='cartodb_services',
|
||||||
|
|
||||||
version='0.20.2',
|
version='0.21.0',
|
||||||
|
|
||||||
description='CartoDB Services API Python Library',
|
description='CartoDB Services API Python Library',
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user