From a1f339376e70e04dc64472c005565e2b02197dff Mon Sep 17 00:00:00 2001 From: Mario de Frutos Date: Fri, 2 Feb 2018 13:17:56 +0100 Subject: [PATCH 1/8] By default the polyline comes with 6 decimals so we avoid to use 5 by default --- .../cartodb_services/cartodb_services/tools/polyline.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/server/lib/python/cartodb_services/cartodb_services/tools/polyline.py b/server/lib/python/cartodb_services/cartodb_services/tools/polyline.py index eaca5f2..14bba19 100644 --- a/server/lib/python/cartodb_services/cartodb_services/tools/polyline.py +++ b/server/lib/python/cartodb_services/cartodb_services/tools/polyline.py @@ -51,9 +51,7 @@ def polyline_to_linestring(polyline): """Convert a Mapzen polyline shape to a PostGIS linestring""" coordinates = [] for point in polyline: - # Divide by 10 because mapzen uses one more decimal than the - # google standard (https://mapzen.com/documentation/turn-by-turn/decoding/) - coordinates.append("%s %s" % (point[1]/10, point[0]/10)) + coordinates.append("%s %s" % (point[1], point[0])) wkt_coordinates = ','.join(coordinates) try: From c5fed2cc8048d377a43e6a87eb14f5d9840a82b7 Mon Sep 17 00:00:00 2001 From: Mario de Frutos Date: Fri, 2 Feb 2018 13:18:32 +0100 Subject: [PATCH 2/8] Check for empty coordinates when we transform to polygon --- .../cartodb_services/cartodb_services/tools/coordinates.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server/lib/python/cartodb_services/cartodb_services/tools/coordinates.py b/server/lib/python/cartodb_services/cartodb_services/tools/coordinates.py index 935dba0..b02e801 100644 --- a/server/lib/python/cartodb_services/cartodb_services/tools/coordinates.py +++ b/server/lib/python/cartodb_services/cartodb_services/tools/coordinates.py @@ -45,6 +45,8 @@ def marshall_coordinates(coordinates): def coordinates_to_polygon(coordinates): """Convert a Coordinate array coordinates to a PostGIS polygon""" + if not coordinates: + return None coordinates.append(coordinates[0]) # Close the ring result_coordinates = [] for coordinate in coordinates: From e2612645c375df956b476701eafe8cc46740975d Mon Sep 17 00:00:00 2001 From: Mario de Frutos Date: Fri, 2 Feb 2018 13:18:47 +0100 Subject: [PATCH 3/8] Bump to version 0.16.5 --- server/lib/python/cartodb_services/setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/lib/python/cartodb_services/setup.py b/server/lib/python/cartodb_services/setup.py index d38b15b..52144b9 100644 --- a/server/lib/python/cartodb_services/setup.py +++ b/server/lib/python/cartodb_services/setup.py @@ -10,7 +10,7 @@ from setuptools import setup, find_packages setup( name='cartodb_services', - version='0.16.4', + version='0.16.5', description='CartoDB Services API Python Library', From a791d02dccbc8298960aa98a275953ca8c4744de Mon Sep 17 00:00:00 2001 From: Mario de Frutos Date: Fri, 2 Feb 2018 13:26:29 +0100 Subject: [PATCH 4/8] 422 errors from mapbox return empty response --- .../cartodb_services/cartodb_services/mapbox/geocoder.py | 2 ++ .../cartodb_services/cartodb_services/mapbox/isolines.py | 5 +++++ .../cartodb_services/mapbox/matrix_client.py | 2 ++ .../cartodb_services/cartodb_services/mapbox/routing.py | 2 ++ 4 files changed, 11 insertions(+) diff --git a/server/lib/python/cartodb_services/cartodb_services/mapbox/geocoder.py b/server/lib/python/cartodb_services/cartodb_services/mapbox/geocoder.py index ceba105..8d7cacb 100644 --- a/server/lib/python/cartodb_services/cartodb_services/mapbox/geocoder.py +++ b/server/lib/python/cartodb_services/cartodb_services/mapbox/geocoder.py @@ -80,6 +80,8 @@ class MapboxGeocoder(Traceable): return self._parse_geocoder_response(response.text) elif response.status_code == requests.codes.bad_request: return [] + elif response.status_code == requests.codes.unprocessable_entity: + return [] else: raise ServiceException(response.status_code, response) except requests.Timeout as te: 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 10c4209..e7f06c1 100644 --- a/server/lib/python/cartodb_services/cartodb_services/mapbox/isolines.py +++ b/server/lib/python/cartodb_services/cartodb_services/mapbox/isolines.py @@ -49,6 +49,8 @@ class MapboxIsolines(): response = self._matrix_client.matrix([origin] + targets, profile) json_response = json.loads(response) + if not json_response: + return [] costs = [None] * number_of_angles @@ -125,6 +127,9 @@ class MapboxIsolines(): unit_factor=unit_factor, number_of_angles=number_of_angles) + if not costs: + continue + errors = [(cost - isorange) / float(isorange) for cost in costs] max_abs_error = max([abs(e) for e in errors]) if max_abs_error <= tolerance: 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 dfe0bde..8d547b6 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 @@ -72,6 +72,8 @@ class MapboxMatrixClient(Traceable): return response.text elif response.status_code == requests.codes.bad_request: return '{}' + elif response.status_code == requests.codes.unprocessable_entity: + return '{}' else: raise ServiceException(response.status_code, response) except requests.Timeout as te: diff --git a/server/lib/python/cartodb_services/cartodb_services/mapbox/routing.py b/server/lib/python/cartodb_services/cartodb_services/mapbox/routing.py index e0827ca..3f30268 100644 --- a/server/lib/python/cartodb_services/cartodb_services/mapbox/routing.py +++ b/server/lib/python/cartodb_services/cartodb_services/mapbox/routing.py @@ -91,6 +91,8 @@ class MapboxRouting(Traceable): return self._parse_routing_response(response.text) elif response.status_code == requests.codes.bad_request: return MapboxRoutingResponse(None, None, None) + elif response.status_code == requests.codes.unprocessable_entity: + return MapboxRoutingResponse(None, None, None) else: raise ServiceException(response.status_code, response) except requests.Timeout as te: From b2825f46a453679f96e7007bc8da0f77e34ca601 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Ignacio=20S=C3=A1nchez=20Lara?= Date: Wed, 31 May 2017 16:49:54 +0200 Subject: [PATCH 5/8] Missing GRANT USAGE --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 00514f9..127bc9a 100644 --- a/README.md +++ b/README.md @@ -95,8 +95,10 @@ Steps to deploy a new Data Services API version : psql -U postgres -d dataservices_db -c "BEGIN;CREATE EXTENSION IF NOT EXISTS observatory VERSION 'dev'; COMMIT" -e psql -U postgres -d dataservices_db -c "BEGIN;GRANT SELECT ON ALL TABLES IN SCHEMA cdb_observatory TO dataservices_user; COMMIT" -e psql -U postgres -d dataservices_db -c "BEGIN;GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA cdb_observatory TO dataservices_user; COMMIT" -e + psql -U postgres -d dataservices_db -c "BEGIN;GRANT USAGE ON SCHEMA cdb_observatory TO dataservices_user; COMMIT" -e psql -U postgres -d dataservices_db -c "BEGIN;GRANT SELECT ON ALL TABLES IN SCHEMA observatory TO dataservices_user; COMMIT" -e psql -U postgres -d dataservices_db -c "BEGIN;GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA observatory TO dataservices_user; COMMIT" -e + psql -U postgres -d dataservices_db -c "BEGIN;GRANT USAGE ON SCHEMA observatory TO dataservices_user; COMMIT" -e ``` ### Server configuration From 29d5a332b684439a7f41f2f6713901fee0a060d7 Mon Sep 17 00:00:00 2001 From: Mario de Frutos Date: Fri, 2 Feb 2018 18:10:02 +0100 Subject: [PATCH 6/8] Change to reflect the current used user for the DS Check this issue https://github.com/CartoDB/dataservices-api/issues/380 which talks about the renaming for a more proper name --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 127bc9a..1781722 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ Steps to deploy a new Data Services API version : ```sql CREATE DATABASE dataservices_db ENCODING = 'UTF8' LC_COLLATE = 'en_US.UTF-8' LC_CTYPE = 'en_US.UTF-8'; - CREATE USER dataservices_user; + CREATE USER geocoder_api; ``` - Install needed extensions in `dataservices_db` database @@ -90,15 +90,15 @@ Steps to deploy a new Data Services API version : ``` psql -U postgres -d dataservices_db -f src/pg/test/fixtures/load_fixtures.sql ``` - - Give permission to execute and select to the `dataservices_user` user: + - Give permission to execute and select to the `geocoder_api` user: ``` psql -U postgres -d dataservices_db -c "BEGIN;CREATE EXTENSION IF NOT EXISTS observatory VERSION 'dev'; COMMIT" -e - psql -U postgres -d dataservices_db -c "BEGIN;GRANT SELECT ON ALL TABLES IN SCHEMA cdb_observatory TO dataservices_user; COMMIT" -e - psql -U postgres -d dataservices_db -c "BEGIN;GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA cdb_observatory TO dataservices_user; COMMIT" -e - psql -U postgres -d dataservices_db -c "BEGIN;GRANT USAGE ON SCHEMA cdb_observatory TO dataservices_user; COMMIT" -e - psql -U postgres -d dataservices_db -c "BEGIN;GRANT SELECT ON ALL TABLES IN SCHEMA observatory TO dataservices_user; COMMIT" -e - psql -U postgres -d dataservices_db -c "BEGIN;GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA observatory TO dataservices_user; COMMIT" -e - psql -U postgres -d dataservices_db -c "BEGIN;GRANT USAGE ON SCHEMA observatory TO dataservices_user; COMMIT" -e + psql -U postgres -d dataservices_db -c "BEGIN;GRANT SELECT ON ALL TABLES IN SCHEMA cdb_observatory TO geocoder_api; COMMIT" -e + psql -U postgres -d dataservices_db -c "BEGIN;GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA cdb_observatory TO geocoder_api; COMMIT" -e + psql -U postgres -d dataservices_db -c "BEGIN;GRANT USAGE ON SCHEMA cdb_observatory TO geocoder_api; COMMIT" -e + psql -U postgres -d dataservices_db -c "BEGIN;GRANT SELECT ON ALL TABLES IN SCHEMA observatory TO geocoder_api; COMMIT" -e + psql -U postgres -d dataservices_db -c "BEGIN;GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA observatory TO geocoder_api; COMMIT" -e + psql -U postgres -d dataservices_db -c "BEGIN;GRANT USAGE ON SCHEMA observatory TO geocoder_api; COMMIT" -e ``` ### Server configuration From 0b12f26f470975007295864c7683df2d0de90e60 Mon Sep 17 00:00:00 2001 From: Mario de Frutos Date: Fri, 2 Feb 2018 18:15:40 +0100 Subject: [PATCH 7/8] Add info about square brackets in server configuration of the README --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 00514f9..2e8d361 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,8 @@ Steps to deploy a new Data Services API version : Configuration for the different services must be stored in the server database using `CDB_Conf_SetConf()`. +**All the configuration inside brackets [] is optional** + #### Redis configuration If sentinel is used: From fad2f25183a0cbe4efcca074cd86295bf67df780 Mon Sep 17 00:00:00 2001 From: Mario de Frutos Date: Mon, 5 Feb 2018 09:35:40 +0100 Subject: [PATCH 8/8] Updated NEWS.md --- NEWS.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/NEWS.md b/NEWS.md index 8db3f08..643222d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,10 @@ +February 5th, 2018 +================== +* Version `0.16.5` of the python library + * Fix displaced routing shape #443 + * Check for empty coordinates object before converting it to polygon + * 422 errors that come from Mapbox now returns an empty result because is a bad input from the user data + February 2th, 2018 ================== * Version `0.16.4` of the python library