Merge pull request #474 from CartoDB/development
0.17.2 version of Python library
This commit is contained in:
commit
b279fafbc5
5
NEWS.md
5
NEWS.md
@ -1,4 +1,9 @@
|
|||||||
|
|
||||||
|
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):
|
||||||
|
@ -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.2',
|
||||||
|
|
||||||
description='CartoDB Services API Python Library',
|
description='CartoDB Services API Python Library',
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user