Compare commits
38 Commits
python-0.1
...
python-0.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d9c569881a | ||
|
|
244d579f6f | ||
|
|
c90859e58b | ||
|
|
f216b6d922 | ||
|
|
573a304bd2 | ||
|
|
f5cbc195cc | ||
|
|
e324afd77f | ||
|
|
0196292093 | ||
|
|
f652a52a8d | ||
|
|
b279fafbc5 | ||
|
|
07ed2a4112 | ||
|
|
35f743164e | ||
|
|
4308b5f351 | ||
|
|
9fb04fdc24 | ||
|
|
a2fd0bf142 | ||
|
|
6534b12606 | ||
|
|
8d9c3a4bf7 | ||
|
|
ad46de1156 | ||
|
|
97f1611d62 | ||
|
|
bc4c9fea33 | ||
|
|
e110ab4cc3 | ||
|
|
e646000f24 | ||
|
|
05e2cc981e | ||
|
|
cbc19b869c | ||
|
|
199788748b | ||
|
|
e3f23adfdd | ||
|
|
39dabffb85 | ||
|
|
03e1d1ca61 | ||
|
|
c14fb057d3 | ||
|
|
9e247685b8 | ||
|
|
1fdb4d3b3a | ||
|
|
029541f298 | ||
|
|
45d9edbba6 | ||
|
|
39c54f3e0c | ||
|
|
54e40645fa | ||
|
|
a86b8e86f9 | ||
|
|
8674dabeb2 | ||
|
|
080a386b8f |
30
NEWS.md
30
NEWS.md
@@ -1,3 +1,33 @@
|
|||||||
|
|
||||||
|
March 14th, 2018
|
||||||
|
================
|
||||||
|
* Version `0.17.4` of the python library
|
||||||
|
* Fix bug with previous version when checking quotas
|
||||||
|
* Version `0.17.3` of the python library
|
||||||
|
* Fix bug with Mapbox routing not using the proper quota value
|
||||||
|
|
||||||
|
February 22th, 2018
|
||||||
|
==================
|
||||||
|
* Version `0.17.2` of the python library
|
||||||
|
* Fix bug with Mapbox isolines not stopping at the seacoast
|
||||||
|
|
||||||
|
February 27th, 2018
|
||||||
|
==================
|
||||||
|
* Version `0.17.1` of the python library
|
||||||
|
* Fix bug when the mapzen credentials are not in the db config and we keep getting them
|
||||||
|
|
||||||
|
February 22th, 2018
|
||||||
|
==================
|
||||||
|
* Version `0.17.0` of the python library
|
||||||
|
* Change default provider to Mapbox
|
||||||
|
* Remove the obligatory nature of the Mapzen configuration due to its deprecation as provider
|
||||||
|
|
||||||
|
February 13th, 2018
|
||||||
|
==================
|
||||||
|
* Version `0.16.7` of the python library
|
||||||
|
* Pick the first result when Mapbox geocoder returns multiple results #462
|
||||||
|
* Normalize input for Mapbox geocoder #462
|
||||||
|
|
||||||
February 12th, 2018
|
February 12th, 2018
|
||||||
==================
|
==================
|
||||||
* Version `0.16.6` of the python library
|
* Version `0.16.6` of the python library
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
-- Only show warning or error messages in the tests output
|
||||||
|
SET client_min_messages TO WARNING;
|
||||||
-- Install dependencies
|
-- Install dependencies
|
||||||
CREATE EXTENSION postgis;
|
CREATE EXTENSION postgis;
|
||||||
CREATE EXTENSION plpythonu;
|
CREATE EXTENSION plpythonu;
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
-- Only show warning or error messages in the tests output
|
||||||
|
SET client_min_messages TO WARNING;
|
||||||
-- Install dependencies
|
-- Install dependencies
|
||||||
CREATE EXTENSION postgis;
|
CREATE EXTENSION postgis;
|
||||||
CREATE EXTENSION plpythonu;
|
CREATE EXTENSION plpythonu;
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
-- Only show warning or error messages in the tests output
|
||||||
|
SET client_min_messages TO WARNING;
|
||||||
-- Install dependencies
|
-- Install dependencies
|
||||||
CREATE EXTENSION postgis;
|
CREATE EXTENSION postgis;
|
||||||
CREATE EXTENSION plpythonu;
|
CREATE EXTENSION plpythonu;
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
-- Only show warning or error messages in the tests output
|
||||||
|
SET client_min_messages TO WARNING;
|
||||||
-- Install dependencies
|
-- Install dependencies
|
||||||
CREATE EXTENSION postgis;
|
CREATE EXTENSION postgis;
|
||||||
CREATE EXTENSION plpythonu;
|
CREATE EXTENSION plpythonu;
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ NOTE: a system installation is required at present because the library is meant
|
|||||||
|
|
||||||
|
|
||||||
## Running the unit tests
|
## Running the unit tests
|
||||||
Just run `nosetests test/`
|
Just run `MAPBOX_API_KEY=xxx nosetests test/`
|
||||||
```shell
|
```shell
|
||||||
$ nosetests test/
|
$ nosetests test/
|
||||||
......................................................................................................
|
......................................................................................................
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ from mapbox import Geocoder
|
|||||||
from cartodb_services.metrics import Traceable
|
from cartodb_services.metrics import Traceable
|
||||||
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 cartodb_services.tools.normalize import normalize
|
||||||
|
|
||||||
GEOCODER_NAME = 'geocoder_name'
|
GEOCODER_NAME = 'geocoder_name'
|
||||||
EPHEMERAL_GEOCODER = 'mapbox.places'
|
EPHEMERAL_GEOCODER = 'mapbox.places'
|
||||||
@@ -39,10 +40,16 @@ class MapboxGeocoder(Traceable):
|
|||||||
def _parse_geocoder_response(self, response):
|
def _parse_geocoder_response(self, response):
|
||||||
json_response = json.loads(response)
|
json_response = json.loads(response)
|
||||||
|
|
||||||
if json_response and json_response[ENTRY_FEATURES]:
|
# If Mapbox returns more that one result, take the first one
|
||||||
feature = json_response[ENTRY_FEATURES][0]
|
if json_response:
|
||||||
|
if type(json_response) == list:
|
||||||
|
json_response = json_response[0]
|
||||||
|
|
||||||
return self._extract_lng_lat_from_feature(feature)
|
if json_response[ENTRY_FEATURES]:
|
||||||
|
feature = json_response[ENTRY_FEATURES][0]
|
||||||
|
return self._extract_lng_lat_from_feature(feature)
|
||||||
|
else:
|
||||||
|
return []
|
||||||
else:
|
else:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
@@ -61,11 +68,11 @@ class MapboxGeocoder(Traceable):
|
|||||||
def geocode(self, searchtext, city=None, state_province=None,
|
def geocode(self, searchtext, city=None, state_province=None,
|
||||||
country=None):
|
country=None):
|
||||||
if searchtext and searchtext.strip():
|
if searchtext and searchtext.strip():
|
||||||
address = [searchtext]
|
address = [normalize(searchtext)]
|
||||||
if city:
|
if city:
|
||||||
address.append(city)
|
address.append(normalize(city))
|
||||||
if state_province:
|
if state_province:
|
||||||
address.append(state_province)
|
address.append(normalize(state_province))
|
||||||
else:
|
else:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ Uses the Mapbox Time Matrix service.
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
from cartodb_services.tools import Coordinate
|
||||||
from cartodb_services.tools.spherical import (get_angles,
|
from cartodb_services.tools.spherical import (get_angles,
|
||||||
calculate_dest_location)
|
calculate_dest_location)
|
||||||
from cartodb_services.mapbox.matrix_client import (validate_profile,
|
from cartodb_services.mapbox.matrix_client import (validate_profile,
|
||||||
@@ -11,7 +12,9 @@ from cartodb_services.mapbox.matrix_client import (validate_profile,
|
|||||||
PROFILE_WALKING,
|
PROFILE_WALKING,
|
||||||
PROFILE_DRIVING,
|
PROFILE_DRIVING,
|
||||||
PROFILE_CYCLING,
|
PROFILE_CYCLING,
|
||||||
ENTRY_DURATIONS)
|
ENTRY_DURATIONS,
|
||||||
|
ENTRY_DESTINATIONS,
|
||||||
|
ENTRY_LOCATION)
|
||||||
|
|
||||||
MAX_SPEEDS = {
|
MAX_SPEEDS = {
|
||||||
PROFILE_WALKING: 3.3333333, # In m/s, assuming 12km/h walking speed
|
PROFILE_WALKING: 3.3333333, # In m/s, assuming 12km/h walking speed
|
||||||
@@ -53,6 +56,7 @@ class MapboxIsolines():
|
|||||||
return []
|
return []
|
||||||
|
|
||||||
costs = [None] * number_of_angles
|
costs = [None] * number_of_angles
|
||||||
|
destinations = [None] * number_of_angles
|
||||||
|
|
||||||
for idx, cost in enumerate(json_response[ENTRY_DURATIONS][0][1:]):
|
for idx, cost in enumerate(json_response[ENTRY_DURATIONS][0][1:]):
|
||||||
if cost:
|
if cost:
|
||||||
@@ -60,7 +64,11 @@ class MapboxIsolines():
|
|||||||
else:
|
else:
|
||||||
costs[idx] = isorange
|
costs[idx] = isorange
|
||||||
|
|
||||||
return costs
|
for idx, destination in enumerate(json_response[ENTRY_DESTINATIONS][1:]):
|
||||||
|
destinations[idx] = Coordinate(destination[ENTRY_LOCATION][0],
|
||||||
|
destination[ENTRY_LOCATION][1])
|
||||||
|
|
||||||
|
return costs, destinations
|
||||||
|
|
||||||
def calculate_isochrone(self, origin, time_ranges,
|
def calculate_isochrone(self, origin, time_ranges,
|
||||||
profile=DEFAULT_PROFILE):
|
profile=DEFAULT_PROFILE):
|
||||||
@@ -122,10 +130,12 @@ class MapboxIsolines():
|
|||||||
# NOTE: sometimes it cannot calculate the cost and returns None.
|
# NOTE: sometimes it cannot calculate the cost and returns None.
|
||||||
# Just assume isorange and stop the calculations there
|
# Just assume isorange and stop the calculations there
|
||||||
|
|
||||||
costs = cost_method(origin=origin, targets=location_estimates,
|
costs, destinations = cost_method(origin=origin,
|
||||||
isorange=isorange, profile=profile,
|
targets=location_estimates,
|
||||||
unit_factor=unit_factor,
|
isorange=isorange,
|
||||||
number_of_angles=number_of_angles)
|
profile=profile,
|
||||||
|
unit_factor=unit_factor,
|
||||||
|
number_of_angles=number_of_angles)
|
||||||
|
|
||||||
if not costs:
|
if not costs:
|
||||||
continue
|
continue
|
||||||
@@ -152,8 +162,8 @@ class MapboxIsolines():
|
|||||||
# delete points that got None
|
# delete points that got None
|
||||||
location_estimates_filtered = []
|
location_estimates_filtered = []
|
||||||
for i, c in enumerate(costs):
|
for i, c in enumerate(costs):
|
||||||
if c != isorange:
|
if c != isorange and c < isorange * (1 + tolerance):
|
||||||
location_estimates_filtered.append(location_estimates[i])
|
location_estimates_filtered.append(destinations[i])
|
||||||
|
|
||||||
return location_estimates_filtered
|
return location_estimates_filtered
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ VALID_PROFILES = [PROFILE_DRIVING_TRAFFIC,
|
|||||||
PROFILE_WALKING]
|
PROFILE_WALKING]
|
||||||
|
|
||||||
ENTRY_DURATIONS = 'durations'
|
ENTRY_DURATIONS = 'durations'
|
||||||
|
ENTRY_DESTINATIONS = 'destinations'
|
||||||
|
ENTRY_LOCATION = 'location'
|
||||||
|
|
||||||
|
|
||||||
def validate_profile(profile):
|
def validate_profile(profile):
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ class RoutingConfig(ServiceConfig):
|
|||||||
ROUTING_PROVIDER_KEY = 'routing_provider'
|
ROUTING_PROVIDER_KEY = 'routing_provider'
|
||||||
MAPZEN_PROVIDER = 'mapzen'
|
MAPZEN_PROVIDER = 'mapzen'
|
||||||
MAPBOX_PROVIDER = 'mapbox'
|
MAPBOX_PROVIDER = 'mapbox'
|
||||||
DEFAULT_PROVIDER = MAPZEN_PROVIDER
|
DEFAULT_PROVIDER = MAPBOX_PROVIDER
|
||||||
QUOTA_KEY = 'mapzen_routing_quota'
|
QUOTA_KEY = 'mapzen_routing_quota'
|
||||||
SOFT_LIMIT_KEY = 'soft_mapzen_routing_limit'
|
SOFT_LIMIT_KEY = 'soft_mapzen_routing_limit'
|
||||||
METRICS_LOG_KEY = 'routing_log_path'
|
METRICS_LOG_KEY = 'routing_log_path'
|
||||||
@@ -147,11 +147,13 @@ class RoutingConfig(ServiceConfig):
|
|||||||
self._routing_provider = self._redis_config[self.ROUTING_PROVIDER_KEY]
|
self._routing_provider = self._redis_config[self.ROUTING_PROVIDER_KEY]
|
||||||
if not self._routing_provider:
|
if not self._routing_provider:
|
||||||
self._routing_provider = self.DEFAULT_PROVIDER
|
self._routing_provider = self.DEFAULT_PROVIDER
|
||||||
self._mapzen_api_key = self._db_config.mapzen_routing_api_key
|
if self._routing_provider == self.MAPZEN_PROVIDER:
|
||||||
self._mapzen_service_params = self._db_config.mapzen_routing_service_params
|
self._mapzen_api_key = self._db_config.mapzen_routing_api_key
|
||||||
self._mapbox_api_keys = self._db_config.mapbox_routing_api_keys
|
self._mapzen_service_params = self._db_config.mapzen_routing_service_params
|
||||||
self._mapbox_service_params = self._db_config.mapbox_routing_service_params
|
elif self._routing_provider == self.MAPBOX_PROVIDER:
|
||||||
self._set_monthly_quota()
|
self._mapbox_api_keys = self._db_config.mapbox_routing_api_keys
|
||||||
|
self._mapbox_service_params = self._db_config.mapbox_routing_service_params
|
||||||
|
self._routing_quota = self._get_effective_monthly_quota(self.QUOTA_KEY)
|
||||||
self._set_soft_limit()
|
self._set_soft_limit()
|
||||||
self._period_end_date = date_parse(self._redis_config[self.PERIOD_END_DATE])
|
self._period_end_date = date_parse(self._redis_config[self.PERIOD_END_DATE])
|
||||||
|
|
||||||
@@ -190,9 +192,13 @@ class RoutingConfig(ServiceConfig):
|
|||||||
def mapbox_service_params(self):
|
def mapbox_service_params(self):
|
||||||
return self._mapbox_service_params
|
return self._mapbox_service_params
|
||||||
|
|
||||||
|
@property
|
||||||
|
def routing_quota(self):
|
||||||
|
return self._routing_quota
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def monthly_quota(self):
|
def monthly_quota(self):
|
||||||
return self._monthly_quota
|
return self._routing_quota
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def period_end_date(self):
|
def period_end_date(self):
|
||||||
@@ -202,9 +208,6 @@ class RoutingConfig(ServiceConfig):
|
|||||||
def soft_limit(self):
|
def soft_limit(self):
|
||||||
return self._soft_limit
|
return self._soft_limit
|
||||||
|
|
||||||
def _set_monthly_quota(self):
|
|
||||||
self._monthly_quota = self._get_effective_monthly_quota(self.QUOTA_KEY)
|
|
||||||
|
|
||||||
def _set_soft_limit(self):
|
def _set_soft_limit(self):
|
||||||
if self.SOFT_LIMIT_KEY in self._redis_config and self._redis_config[self.SOFT_LIMIT_KEY].lower() == 'true':
|
if self.SOFT_LIMIT_KEY in self._redis_config and self._redis_config[self.SOFT_LIMIT_KEY].lower() == 'true':
|
||||||
self._soft_limit = True
|
self._soft_limit = True
|
||||||
@@ -226,7 +229,7 @@ class IsolinesRoutingConfig(ServiceConfig):
|
|||||||
MAPZEN_PROVIDER = 'mapzen'
|
MAPZEN_PROVIDER = 'mapzen'
|
||||||
MAPBOX_PROVIDER = 'mapbox'
|
MAPBOX_PROVIDER = 'mapbox'
|
||||||
HEREMAPS_PROVIDER = 'heremaps'
|
HEREMAPS_PROVIDER = 'heremaps'
|
||||||
DEFAULT_PROVIDER = MAPZEN_PROVIDER
|
DEFAULT_PROVIDER = MAPBOX_PROVIDER
|
||||||
METRICS_LOG_KEY = 'isolines_log_path'
|
METRICS_LOG_KEY = 'isolines_log_path'
|
||||||
|
|
||||||
def __init__(self, redis_connection, db_conn, username, orgname=None):
|
def __init__(self, redis_connection, db_conn, username, orgname=None):
|
||||||
@@ -391,7 +394,7 @@ class GeocoderConfig(ServiceConfig):
|
|||||||
USERNAME_KEY = 'username'
|
USERNAME_KEY = 'username'
|
||||||
ORGNAME_KEY = 'orgname'
|
ORGNAME_KEY = 'orgname'
|
||||||
PERIOD_END_DATE = 'period_end_date'
|
PERIOD_END_DATE = 'period_end_date'
|
||||||
DEFAULT_PROVIDER = MAPZEN_GEOCODER
|
DEFAULT_PROVIDER = MAPBOX_GEOCODER
|
||||||
METRICS_LOG_KEY = 'geocoder_log_path'
|
METRICS_LOG_KEY = 'geocoder_log_path'
|
||||||
|
|
||||||
def __init__(self, redis_connection, db_conn, username, orgname=None, forced_provider=None):
|
def __init__(self, redis_connection, db_conn, username, orgname=None, forced_provider=None):
|
||||||
@@ -576,50 +579,51 @@ class ServicesDBConfig:
|
|||||||
heremaps_conf_json = self._get_conf('heremaps_conf')
|
heremaps_conf_json = self._get_conf('heremaps_conf')
|
||||||
if not heremaps_conf_json:
|
if not heremaps_conf_json:
|
||||||
raise ConfigException('Here maps configuration missing')
|
raise ConfigException('Here maps configuration missing')
|
||||||
else:
|
|
||||||
heremaps_conf = json.loads(heremaps_conf_json)
|
heremaps_conf = json.loads(heremaps_conf_json)
|
||||||
self._heremaps_geocoder_app_id = heremaps_conf['geocoder']['app_id']
|
self._heremaps_geocoder_app_id = heremaps_conf['geocoder']['app_id']
|
||||||
self._heremaps_geocoder_app_code = heremaps_conf['geocoder']['app_code']
|
self._heremaps_geocoder_app_code = heremaps_conf['geocoder']['app_code']
|
||||||
self._heremaps_geocoder_cost_per_hit = heremaps_conf['geocoder'][
|
self._heremaps_geocoder_cost_per_hit = heremaps_conf['geocoder'][
|
||||||
'geocoder_cost_per_hit']
|
'geocoder_cost_per_hit']
|
||||||
self._heremaps_geocoder_service_params = heremaps_conf['geocoder'].get('service', {})
|
self._heremaps_geocoder_service_params = heremaps_conf['geocoder'].get('service', {})
|
||||||
self._heremaps_isolines_app_id = heremaps_conf['isolines']['app_id']
|
self._heremaps_isolines_app_id = heremaps_conf['isolines']['app_id']
|
||||||
self._heremaps_isolines_app_code = heremaps_conf['isolines']['app_code']
|
self._heremaps_isolines_app_code = heremaps_conf['isolines']['app_code']
|
||||||
self._heremaps_isolines_service_params = heremaps_conf['isolines'].get('service', {})
|
self._heremaps_isolines_service_params = heremaps_conf['isolines'].get('service', {})
|
||||||
|
|
||||||
def _get_mapzen_config(self):
|
def _get_mapzen_config(self):
|
||||||
mapzen_conf_json = self._get_conf('mapzen_conf')
|
mapzen_conf_json = self._get_conf('mapzen_conf')
|
||||||
|
# We dont use mapzen anymore so we don't need to check for its configuration
|
||||||
if not mapzen_conf_json:
|
if not mapzen_conf_json:
|
||||||
raise ConfigException('Mapzen configuration missing')
|
return
|
||||||
else:
|
|
||||||
mapzen_conf = json.loads(mapzen_conf_json)
|
mapzen_conf = json.loads(mapzen_conf_json)
|
||||||
self._mapzen_matrix_api_key = mapzen_conf['matrix']['api_key']
|
self._mapzen_matrix_api_key = mapzen_conf['matrix']['api_key']
|
||||||
self._mapzen_matrix_quota = mapzen_conf['matrix']['monthly_quota']
|
self._mapzen_matrix_quota = mapzen_conf['matrix']['monthly_quota']
|
||||||
self._mapzen_matrix_service_params = mapzen_conf['matrix'].get('service', {})
|
self._mapzen_matrix_service_params = mapzen_conf['matrix'].get('service', {})
|
||||||
self._mapzen_isochrones_service_params = mapzen_conf.get('isochrones', {}).get('service', {})
|
self._mapzen_isochrones_service_params = mapzen_conf.get('isochrones', {}).get('service', {})
|
||||||
self._mapzen_routing_api_key = mapzen_conf['routing']['api_key']
|
self._mapzen_routing_api_key = mapzen_conf['routing']['api_key']
|
||||||
self._mapzen_routing_quota = mapzen_conf['routing']['monthly_quota']
|
self._mapzen_routing_quota = mapzen_conf['routing']['monthly_quota']
|
||||||
self._mapzen_routing_service_params = mapzen_conf['routing'].get('service', {})
|
self._mapzen_routing_service_params = mapzen_conf['routing'].get('service', {})
|
||||||
self._mapzen_geocoder_api_key = mapzen_conf['geocoder']['api_key']
|
self._mapzen_geocoder_api_key = mapzen_conf['geocoder']['api_key']
|
||||||
self._mapzen_geocoder_quota = mapzen_conf['geocoder']['monthly_quota']
|
self._mapzen_geocoder_quota = mapzen_conf['geocoder']['monthly_quota']
|
||||||
self._mapzen_geocoder_service_params = mapzen_conf['geocoder'].get('service', {})
|
self._mapzen_geocoder_service_params = mapzen_conf['geocoder'].get('service', {})
|
||||||
|
|
||||||
def _get_mapbox_config(self):
|
def _get_mapbox_config(self):
|
||||||
mapbox_conf_json = self._get_conf('mapbox_conf')
|
mapbox_conf_json = self._get_conf('mapbox_conf')
|
||||||
if not mapbox_conf_json:
|
if not mapbox_conf_json:
|
||||||
raise ConfigException('Mapbox configuration missing')
|
raise ConfigException('Mapbox configuration missing')
|
||||||
else:
|
|
||||||
mapbox_conf = json.loads(mapbox_conf_json)
|
mapbox_conf = json.loads(mapbox_conf_json)
|
||||||
self._mapbox_matrix_api_keys = mapbox_conf['matrix']['api_keys']
|
self._mapbox_matrix_api_keys = mapbox_conf['matrix']['api_keys']
|
||||||
self._mapbox_matrix_quota = mapbox_conf['matrix']['monthly_quota']
|
self._mapbox_matrix_quota = mapbox_conf['matrix']['monthly_quota']
|
||||||
self._mapbox_matrix_service_params = mapbox_conf['matrix'].get('service', {})
|
self._mapbox_matrix_service_params = mapbox_conf['matrix'].get('service', {})
|
||||||
self._mapbox_isochrones_service_params = mapbox_conf.get('isochrones', {}).get('service', {})
|
self._mapbox_isochrones_service_params = mapbox_conf.get('isochrones', {}).get('service', {})
|
||||||
self._mapbox_routing_api_keys = mapbox_conf['routing']['api_keys']
|
self._mapbox_routing_api_keys = mapbox_conf['routing']['api_keys']
|
||||||
self._mapbox_routing_quota = mapbox_conf['routing']['monthly_quota']
|
self._mapbox_routing_quota = mapbox_conf['routing']['monthly_quota']
|
||||||
self._mapbox_routing_service_params = mapbox_conf['routing'].get('service', {})
|
self._mapbox_routing_service_params = mapbox_conf['routing'].get('service', {})
|
||||||
self._mapbox_geocoder_api_keys = mapbox_conf['geocoder']['api_keys']
|
self._mapbox_geocoder_api_keys = mapbox_conf['geocoder']['api_keys']
|
||||||
self._mapbox_geocoder_quota = mapbox_conf['geocoder']['monthly_quota']
|
self._mapbox_geocoder_quota = mapbox_conf['geocoder']['monthly_quota']
|
||||||
self._mapbox_geocoder_service_params = mapbox_conf['geocoder'].get('service', {})
|
self._mapbox_geocoder_service_params = mapbox_conf['geocoder'].get('service', {})
|
||||||
|
|
||||||
def _get_data_observatory_config(self):
|
def _get_data_observatory_config(self):
|
||||||
do_conf_json = self._get_conf('data_observatory_conf')
|
do_conf_json = self._get_conf('data_observatory_conf')
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ class QuotaChecker:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def __check_routing_quota(self):
|
def __check_routing_quota(self):
|
||||||
user_quota = self._user_service_config.monthly_quota
|
user_quota = self._user_service_config.routing_quota
|
||||||
today = date.today()
|
today = date.today()
|
||||||
service_type = self._user_service_config.service_type
|
service_type = self._user_service_config.service_type
|
||||||
current_used = self._user_service.used_quota(service_type, today)
|
current_used = self._user_service.used_quota(service_type, today)
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
def normalize(str_input):
|
||||||
|
return str_input.replace('"', '"') \
|
||||||
|
.replace(';', ',')
|
||||||
@@ -10,7 +10,7 @@ from setuptools import setup, find_packages
|
|||||||
setup(
|
setup(
|
||||||
name='cartodb_services',
|
name='cartodb_services',
|
||||||
|
|
||||||
version='0.16.6',
|
version='0.17.4',
|
||||||
|
|
||||||
description='CartoDB Services API Python Library',
|
description='CartoDB Services API Python Library',
|
||||||
|
|
||||||
|
|||||||
6
server/lib/python/cartodb_services/test/credentials.py
Normal file
6
server/lib/python/cartodb_services/test/credentials.py
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
def mapbox_api_key():
|
||||||
|
"""Returns Mapbox API key. Requires setting MAPBOX_API_KEY environment variable."""
|
||||||
|
return os.environ['MAPBOX_API_KEY']
|
||||||
|
|
||||||
@@ -301,7 +301,7 @@ class TestRoutingConfig(TestCase):
|
|||||||
self._redis_conn.hset(self._user_key, 'mapzen_routing_quota', 1000)
|
self._redis_conn.hset(self._user_key, 'mapzen_routing_quota', 1000)
|
||||||
orgname = None
|
orgname = None
|
||||||
config = RoutingConfig(self._redis_conn, self._db_conn, self._username, orgname)
|
config = RoutingConfig(self._redis_conn, self._db_conn, self._username, orgname)
|
||||||
assert config.monthly_quota == 1000
|
assert config.routing_quota == 1000
|
||||||
|
|
||||||
def test_org_quota_overrides_user_quota(self):
|
def test_org_quota_overrides_user_quota(self):
|
||||||
self._redis_conn.hset(self._user_key, 'mapzen_routing_quota', 1000)
|
self._redis_conn.hset(self._user_key, 'mapzen_routing_quota', 1000)
|
||||||
@@ -315,7 +315,7 @@ class TestRoutingConfig(TestCase):
|
|||||||
self._redis_conn.hset(orgname_key, 'here_isolines_quota', 0)
|
self._redis_conn.hset(orgname_key, 'here_isolines_quota', 0)
|
||||||
|
|
||||||
config = RoutingConfig(self._redis_conn, self._db_conn, self._username, orgname)
|
config = RoutingConfig(self._redis_conn, self._db_conn, self._username, orgname)
|
||||||
assert config.monthly_quota == 5000
|
assert config.routing_quota == 5000
|
||||||
|
|
||||||
def test_should_have_soft_limit_false_by_default(self):
|
def test_should_have_soft_limit_false_by_default(self):
|
||||||
orgname = None
|
orgname = None
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ class TestQuotaChecker(TestCase):
|
|||||||
username = self.username,
|
username = self.username,
|
||||||
organization = None,
|
organization = None,
|
||||||
service_type = self.service_type,
|
service_type = self.service_type,
|
||||||
monthly_quota = 1000,
|
routing_quota = 1000,
|
||||||
period_end_date = datetime.today(),
|
period_end_date = datetime.today(),
|
||||||
soft_limit = False
|
soft_limit = False
|
||||||
)
|
)
|
||||||
@@ -43,7 +43,7 @@ class TestQuotaChecker(TestCase):
|
|||||||
username = self.username,
|
username = self.username,
|
||||||
organization = None,
|
organization = None,
|
||||||
service_type = self.service_type,
|
service_type = self.service_type,
|
||||||
monthly_quota = 1000,
|
routing_quota = 1000,
|
||||||
period_end_date = datetime.today(),
|
period_end_date = datetime.today(),
|
||||||
soft_limit = False
|
soft_limit = False
|
||||||
)
|
)
|
||||||
@@ -61,7 +61,7 @@ class TestQuotaChecker(TestCase):
|
|||||||
username = self.username,
|
username = self.username,
|
||||||
organization = None,
|
organization = None,
|
||||||
service_type = self.service_type,
|
service_type = self.service_type,
|
||||||
monthly_quota = 1000,
|
routing_quota = 1000,
|
||||||
period_end_date = datetime.today(),
|
period_end_date = datetime.today(),
|
||||||
soft_limit = False
|
soft_limit = False
|
||||||
)
|
)
|
||||||
@@ -75,7 +75,7 @@ class TestQuotaChecker(TestCase):
|
|||||||
username = self.username,
|
username = self.username,
|
||||||
organization = None,
|
organization = None,
|
||||||
service_type = self.service_type,
|
service_type = self.service_type,
|
||||||
monthly_quota = 1000,
|
routing_quota = 1000,
|
||||||
period_end_date = datetime.today(),
|
period_end_date = datetime.today(),
|
||||||
soft_limit = True
|
soft_limit = True
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ import unittest
|
|||||||
from mock import Mock
|
from mock import Mock
|
||||||
from cartodb_services.mapbox import MapboxGeocoder
|
from cartodb_services.mapbox import MapboxGeocoder
|
||||||
from cartodb_services.tools.exceptions import ServiceException
|
from cartodb_services.tools.exceptions import ServiceException
|
||||||
|
from credentials import mapbox_api_key
|
||||||
|
|
||||||
VALID_TOKEN = 'pk.eyJ1IjoiYWNhcmxvbiIsImEiOiJjamJuZjQ1Zjc0Ymt4Mnh0YmFrMmhtYnY4In0.gt9cw0VeKc3rM2mV5pcEmg'
|
|
||||||
INVALID_TOKEN = 'invalid_token'
|
INVALID_TOKEN = 'invalid_token'
|
||||||
VALID_ADDRESS = 'Calle Siempreviva 3, Valladolid'
|
VALID_ADDRESS = 'Calle Siempreviva 3, Valladolid'
|
||||||
WELL_KNOWN_LONGITUDE = -4.730947
|
WELL_KNOWN_LONGITUDE = -4.730947
|
||||||
@@ -12,7 +12,7 @@ WELL_KNOWN_LATITUDE = 41.668654
|
|||||||
|
|
||||||
class MapboxGeocoderTestCase(unittest.TestCase):
|
class MapboxGeocoderTestCase(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.geocoder = MapboxGeocoder(token=VALID_TOKEN, logger=Mock())
|
self.geocoder = MapboxGeocoder(token=mapbox_api_key(), logger=Mock())
|
||||||
|
|
||||||
def test_invalid_token(self):
|
def test_invalid_token(self):
|
||||||
invalid_geocoder = MapboxGeocoder(token=INVALID_TOKEN, logger=Mock())
|
invalid_geocoder = MapboxGeocoder(token=INVALID_TOKEN, logger=Mock())
|
||||||
@@ -35,6 +35,11 @@ class MapboxGeocoderTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
assert place
|
assert place
|
||||||
|
|
||||||
|
def test_odd_characters(self):
|
||||||
|
place = self.geocoder.geocode(searchtext='Barcelona; "Spain"')
|
||||||
|
|
||||||
|
assert place
|
||||||
|
|
||||||
def test_empty_request(self):
|
def test_empty_request(self):
|
||||||
place = self.geocoder.geocode(searchtext='', country=None, city=None, state_province=None)
|
place = self.geocoder.geocode(searchtext='', country=None, city=None, state_province=None)
|
||||||
|
|
||||||
|
|||||||
@@ -7,15 +7,15 @@ from cartodb_services.mapbox.routing import MapboxRouting
|
|||||||
from cartodb_services.tools import Coordinate
|
from cartodb_services.tools import Coordinate
|
||||||
from cartodb_services.tools.coordinates import (validate_coordinates,
|
from cartodb_services.tools.coordinates import (validate_coordinates,
|
||||||
marshall_coordinates)
|
marshall_coordinates)
|
||||||
|
from credentials import mapbox_api_key
|
||||||
|
|
||||||
VALID_TOKEN = 'pk.eyJ1IjoiYWNhcmxvbiIsImEiOiJjamJuZjQ1Zjc0Ymt4Mnh0YmFrMmhtYnY4In0.gt9cw0VeKc3rM2mV5pcEmg'
|
|
||||||
VALID_ORIGIN = Coordinate(-73.989, 40.733)
|
VALID_ORIGIN = Coordinate(-73.989, 40.733)
|
||||||
|
|
||||||
|
|
||||||
class MapboxIsolinesTestCase(unittest.TestCase):
|
class MapboxIsolinesTestCase(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
matrix_client = MapboxMatrixClient(token=VALID_TOKEN, logger=Mock())
|
matrix_client = MapboxMatrixClient(token=mapbox_api_key(), logger=Mock())
|
||||||
self.mapbox_isolines = MapboxIsolines(matrix_client, logger=Mock())
|
self.mapbox_isolines = MapboxIsolines(matrix_client, logger=Mock())
|
||||||
|
|
||||||
def test_calculate_isochrone(self):
|
def test_calculate_isochrone(self):
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ from cartodb_services.mapbox import MapboxMatrixClient
|
|||||||
from cartodb_services.mapbox.matrix_client import DEFAULT_PROFILE
|
from cartodb_services.mapbox.matrix_client import DEFAULT_PROFILE
|
||||||
from cartodb_services.tools.exceptions import ServiceException
|
from cartodb_services.tools.exceptions import ServiceException
|
||||||
from cartodb_services.tools import Coordinate
|
from cartodb_services.tools import Coordinate
|
||||||
|
from credentials import mapbox_api_key
|
||||||
|
|
||||||
VALID_TOKEN = 'pk.eyJ1IjoiYWNhcmxvbiIsImEiOiJjamJuZjQ1Zjc0Ymt4Mnh0YmFrMmhtYnY4In0.gt9cw0VeKc3rM2mV5pcEmg'
|
|
||||||
INVALID_TOKEN = 'invalid_token'
|
INVALID_TOKEN = 'invalid_token'
|
||||||
VALID_ORIGIN = Coordinate(-73.989, 40.733)
|
VALID_ORIGIN = Coordinate(-73.989, 40.733)
|
||||||
VALID_TARGET = Coordinate(-74, 40.733)
|
VALID_TARGET = Coordinate(-74, 40.733)
|
||||||
@@ -22,7 +22,7 @@ INVALID_PROFILE = 'invalid_profile'
|
|||||||
|
|
||||||
class MapboxMatrixTestCase(unittest.TestCase):
|
class MapboxMatrixTestCase(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.matrix_client = MapboxMatrixClient(token=VALID_TOKEN,
|
self.matrix_client = MapboxMatrixClient(token=mapbox_api_key(),
|
||||||
logger=Mock())
|
logger=Mock())
|
||||||
|
|
||||||
def test_invalid_profile(self):
|
def test_invalid_profile(self):
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ from cartodb_services.mapbox import MapboxRouting
|
|||||||
from cartodb_services.mapbox.routing import DEFAULT_PROFILE
|
from cartodb_services.mapbox.routing import DEFAULT_PROFILE
|
||||||
from cartodb_services.tools.exceptions import ServiceException
|
from cartodb_services.tools.exceptions import ServiceException
|
||||||
from cartodb_services.tools import Coordinate
|
from cartodb_services.tools import Coordinate
|
||||||
|
from credentials import mapbox_api_key
|
||||||
|
|
||||||
VALID_TOKEN = 'pk.eyJ1IjoiYWNhcmxvbiIsImEiOiJjamJuZjQ1Zjc0Ymt4Mnh0YmFrMmhtYnY4In0.gt9cw0VeKc3rM2mV5pcEmg'
|
|
||||||
INVALID_TOKEN = 'invalid_token'
|
INVALID_TOKEN = 'invalid_token'
|
||||||
VALID_WAYPOINTS = [Coordinate(-73.989, 40.733), Coordinate(-74, 40.733)]
|
VALID_WAYPOINTS = [Coordinate(-73.989, 40.733), Coordinate(-74, 40.733)]
|
||||||
NUM_WAYPOINTS_MAX = 25
|
NUM_WAYPOINTS_MAX = 25
|
||||||
@@ -31,7 +31,7 @@ WELL_KNOWN_LENGTH = 1317.9
|
|||||||
|
|
||||||
class MapboxRoutingTestCase(unittest.TestCase):
|
class MapboxRoutingTestCase(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.routing = MapboxRouting(token=VALID_TOKEN, logger=Mock())
|
self.routing = MapboxRouting(token=mapbox_api_key(), logger=Mock())
|
||||||
|
|
||||||
def test_invalid_profile(self):
|
def test_invalid_profile(self):
|
||||||
with self.assertRaises(ValueError):
|
with self.assertRaises(ValueError):
|
||||||
|
|||||||
Reference in New Issue
Block a user