From 5781f78c7fafad2fa0f8bf9692cf06dcec320ab9 Mon Sep 17 00:00:00 2001 From: Mario de Frutos Date: Tue, 16 Jan 2018 11:04:29 +0100 Subject: [PATCH] Revert "Removed suspect import" This reverts commit 9c1ec1dddea87d40d40d3c5fc6ff497c0db2b0b7. --- .../cartodb_services/mapbox/isolines.py | 34 +++++-------------- .../cartodb_services/mapbox/matrix_client.py | 21 +++++++----- 2 files changed, 21 insertions(+), 34 deletions(-) diff --git a/server/lib/python/cartodb_services/cartodb_services/mapbox/isolines.py b/server/lib/python/cartodb_services/cartodb_services/mapbox/isolines.py index ab28edb..10c4209 100644 --- a/server/lib/python/cartodb_services/cartodb_services/mapbox/isolines.py +++ b/server/lib/python/cartodb_services/cartodb_services/mapbox/isolines.py @@ -6,23 +6,17 @@ Uses the Mapbox Time Matrix service. import json from cartodb_services.tools.spherical import (get_angles, calculate_dest_location) - -PROFILE_DRIVING_TRAFFIC = 'driving-traffic' -PROFILE_DRIVING = 'driving' -PROFILE_CYCLING = 'cycling' -PROFILE_WALKING = 'walking' -DEFAULT_PROFILE = PROFILE_DRIVING - -VALID_PROFILES = [PROFILE_DRIVING_TRAFFIC, - PROFILE_DRIVING, - PROFILE_CYCLING, - PROFILE_WALKING] +from cartodb_services.mapbox.matrix_client import (validate_profile, + DEFAULT_PROFILE, + PROFILE_WALKING, + PROFILE_DRIVING, + PROFILE_CYCLING, + ENTRY_DURATIONS) MAX_SPEEDS = { PROFILE_WALKING: 3.3333333, # In m/s, assuming 12km/h walking speed PROFILE_CYCLING: 16.67, # In m/s, assuming 60km/h max speed - PROFILE_DRIVING: 41.67, # In m/s, assuming 140km/h max speed - PROFILE_DRIVING_TRAFFIC: 41.67, # In m/s, assuming 140km/h max speed + PROFILE_DRIVING: 41.67 # In m/s, assuming 140km/h max speed } DEFAULT_NUM_ANGLES = 24 @@ -37,8 +31,6 @@ UNIT_FACTOR_ISOCHRONE = 1.0 UNIT_FACTOR_ISODISTANCE = 1000.0 DEFAULT_UNIT_FACTOR = UNIT_FACTOR_ISOCHRONE -ENTRY_DURATIONS = 'durations' - class MapboxIsolines(): ''' @@ -50,14 +42,6 @@ class MapboxIsolines(): self._matrix_client = matrix_client self._logger = logger - def _validate_profile(self, profile): - if profile not in VALID_PROFILES: - raise ValueError('{profile} is not a valid profile. ' - 'Valid profiles are: {valid_profiles}'.format( - profile=profile, - valid_profiles=', '.join( - [x for x in VALID_PROFILES]))) - def _calculate_matrix_cost(self, origin, targets, isorange, profile=DEFAULT_PROFILE, unit_factor=UNIT_FACTOR_ISOCHRONE, @@ -78,7 +62,7 @@ class MapboxIsolines(): def calculate_isochrone(self, origin, time_ranges, profile=DEFAULT_PROFILE): - self._validate_profile(profile) + validate_profile(profile) max_speed = MAX_SPEEDS[profile] @@ -101,7 +85,7 @@ class MapboxIsolines(): def calculate_isodistance(self, origin, distance_range, profile=DEFAULT_PROFILE): - self._validate_profile(profile) + validate_profile(profile) max_speed = MAX_SPEEDS[profile] time_range = distance_range / max_speed diff --git a/server/lib/python/cartodb_services/cartodb_services/mapbox/matrix_client.py b/server/lib/python/cartodb_services/cartodb_services/mapbox/matrix_client.py index c75dd8a..dfe0bde 100644 --- a/server/lib/python/cartodb_services/cartodb_services/mapbox/matrix_client.py +++ b/server/lib/python/cartodb_services/cartodb_services/mapbox/matrix_client.py @@ -29,6 +29,17 @@ VALID_PROFILES = [PROFILE_DRIVING_TRAFFIC, PROFILE_CYCLING, PROFILE_WALKING] +ENTRY_DURATIONS = 'durations' + + +def validate_profile(profile): + if profile not in VALID_PROFILES: + raise ValueError('{profile} is not a valid profile. ' + 'Valid profiles are: {valid_profiles}'.format( + profile=profile, + valid_profiles=', '.join( + [x for x in VALID_PROFILES]))) + class MapboxMatrixClient(Traceable): ''' @@ -40,21 +51,13 @@ class MapboxMatrixClient(Traceable): self._token = token self._logger = logger - def _validate_profile(self, profile): - if profile not in VALID_PROFILES: - raise ValueError('{profile} is not a valid profile. ' - 'Valid profiles are: {valid_profiles}'.format( - profile=profile, - valid_profiles=', '.join( - [x for x in VALID_PROFILES]))) - def _uri(self, coordinates, profile=DEFAULT_PROFILE): return BASEURI.format(profile=profile, coordinates=coordinates, token=self._token) @qps_retry(qps=1) def matrix(self, coordinates, profile=DEFAULT_PROFILE): - self._validate_profile(profile) + validate_profile(profile) validate_coordinates(coordinates, NUM_COORDINATES_MIN, NUM_COORDINATES_MAX)