Compare commits
16 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 | ||
|
|
bc4c9fea33 |
12
NEWS.md
12
NEWS.md
@@ -1,4 +1,16 @@
|
|||||||
|
|
||||||
|
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
|
February 27th, 2018
|
||||||
==================
|
==================
|
||||||
* Version `0.17.1` of the python library
|
* Version `0.17.1` of the python library
|
||||||
|
|||||||
@@ -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):
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ class RoutingConfig(ServiceConfig):
|
|||||||
elif self._routing_provider == self.MAPBOX_PROVIDER:
|
elif self._routing_provider == self.MAPBOX_PROVIDER:
|
||||||
self._mapbox_api_keys = self._db_config.mapbox_routing_api_keys
|
self._mapbox_api_keys = self._db_config.mapbox_routing_api_keys
|
||||||
self._mapbox_service_params = self._db_config.mapbox_routing_service_params
|
self._mapbox_service_params = self._db_config.mapbox_routing_service_params
|
||||||
self._set_monthly_quota()
|
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])
|
||||||
|
|
||||||
@@ -192,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):
|
||||||
@@ -204,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
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ from setuptools import setup, find_packages
|
|||||||
setup(
|
setup(
|
||||||
name='cartodb_services',
|
name='cartodb_services',
|
||||||
|
|
||||||
version='0.17.1',
|
version='0.17.4',
|
||||||
|
|
||||||
description='CartoDB Services API Python Library',
|
description='CartoDB Services API Python Library',
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user