Compare commits
57 Commits
python-0.2
...
python-0.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dc0b3191f6 | ||
|
|
6a57a85e72 | ||
|
|
08a50c14bb | ||
|
|
ec2fe14ed3 | ||
|
|
305b010225 | ||
|
|
885c7c50fb | ||
|
|
a38c5b275d | ||
|
|
45542b2f28 | ||
|
|
f0a9779a8d | ||
|
|
dd1df8695f | ||
|
|
8507067901 | ||
|
|
00f77cca8a | ||
|
|
dfaf0d5245 | ||
|
|
f63d73b9d7 | ||
|
|
29e636f115 | ||
|
|
f082c918f0 | ||
|
|
246ec135db | ||
|
|
4f5745988f | ||
|
|
f996cb35db | ||
|
|
bbfa03749a | ||
|
|
ab13f3a803 | ||
|
|
ac991a05ab | ||
|
|
0dfd1a9caa | ||
|
|
370272f6c4 | ||
|
|
e2c0a63803 | ||
|
|
84276b4cd3 | ||
|
|
b608830bce | ||
|
|
a8140e53c3 | ||
|
|
c28ca4861a | ||
|
|
b269c46724 | ||
|
|
6b6fbef586 | ||
|
|
eb4638a326 | ||
|
|
a919b87664 | ||
|
|
98a4ed81c5 | ||
|
|
0ec1e051be | ||
|
|
850497ef79 | ||
|
|
8d2d0ececd | ||
|
|
90fd8587e2 | ||
|
|
64a0616c97 | ||
|
|
b1bdf2460e | ||
|
|
04bbb32849 | ||
|
|
3e6c273b48 | ||
|
|
522591dd63 | ||
|
|
75d0959aff | ||
|
|
b2cdb378fb | ||
|
|
100319ed0e | ||
|
|
5e161b55d2 | ||
|
|
7f4b87f513 | ||
|
|
378458c0ae | ||
|
|
4ae4080bba | ||
|
|
2bb67ba17a | ||
|
|
1027d554a5 | ||
|
|
4e1f081952 | ||
|
|
87bb8bea68 | ||
|
|
dc47f6f71b | ||
|
|
2f6d067b4e | ||
|
|
089d3e3f27 |
34
NEWS.md
34
NEWS.md
@@ -1,3 +1,37 @@
|
|||||||
|
Mar 5th, 2019
|
||||||
|
==============
|
||||||
|
* Version `0.21.3` of the python library
|
||||||
|
* Fixed TomTom Qps respondes part 2 (#546)
|
||||||
|
|
||||||
|
Mar 4th, 2019
|
||||||
|
==============
|
||||||
|
* Version `0.21.2` of the python library
|
||||||
|
* Fixed TomTom Qps responses (#546)
|
||||||
|
|
||||||
|
Feb 25th, 2019
|
||||||
|
==============
|
||||||
|
* Version `0.26.2` of the client extension
|
||||||
|
* Fixed bulk geocoding soft limit (#543)
|
||||||
|
|
||||||
|
Dec 31st, 2018
|
||||||
|
==============
|
||||||
|
* Version `0.35.1` of the server extension and `0.26.1` of the client
|
||||||
|
* Now the bulk geocoder returns `Point` geometries instead of MultiPolygons (#538)
|
||||||
|
|
||||||
|
Nov 30th, 2018
|
||||||
|
==============
|
||||||
|
* Version `0.35.0` of the server extension
|
||||||
|
* Now the `mode_type` is working the providers that support it (#536)
|
||||||
|
|
||||||
|
Nov 27th, 2018
|
||||||
|
==============
|
||||||
|
* Version `0.34.2` of the server extension
|
||||||
|
* Fixed bulk geocoding log metrics in order to fix problems in ELK due to the JSON not being standard (#530)
|
||||||
|
|
||||||
|
Nov 22th, 2018
|
||||||
|
==============
|
||||||
|
* Version `0.34.1` of the server extension
|
||||||
|
* Fixed isochrones metrics that increase `success_rows` field for every isochrone generated (#533)
|
||||||
|
|
||||||
Oct 31th, 2018
|
Oct 31th, 2018
|
||||||
==============
|
==============
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
"carto_postgresql_ext": "^0.23.0"
|
"carto_postgresql_ext": "^0.23.0"
|
||||||
},
|
},
|
||||||
"works_with": {
|
"works_with": {
|
||||||
"dataservices-api-server-extension": "^0.32.0"
|
"dataservices-api-server-extension": "^0.35.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
96
client/cdb_dataservices_client--0.26.1--0.26.2.sql
Normal file
96
client/cdb_dataservices_client--0.26.1--0.26.2.sql
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
|
||||||
|
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||||
|
\echo Use "ALTER EXTENSION cdb_dataservices_client UPDATE TO '0.26.2'" to load this file. \quit
|
||||||
|
|
||||||
|
-- Make sure we have a sane search path to create/update the extension
|
||||||
|
SET search_path = "$user",cartodb,public,cdb_dataservices_client;
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_client.cdb_bulk_geocode_street_point (query text,
|
||||||
|
street_column text, city_column text default null, state_column text default null, country_column text default null, batch_size integer DEFAULT NULL)
|
||||||
|
RETURNS SETOF cdb_dataservices_client.geocoding AS $$
|
||||||
|
DECLARE
|
||||||
|
query_row_count integer;
|
||||||
|
enough_quota boolean;
|
||||||
|
remaining_quota integer;
|
||||||
|
max_batch_size integer;
|
||||||
|
|
||||||
|
cartodb_id_batch integer;
|
||||||
|
batches_n integer;
|
||||||
|
DEFAULT_BATCH_SIZE CONSTANT numeric := 100;
|
||||||
|
MAX_SAFE_BATCH_SIZE CONSTANT numeric := 5000;
|
||||||
|
|
||||||
|
temp_table_name text;
|
||||||
|
username text;
|
||||||
|
orgname text;
|
||||||
|
apikey_permissions json;
|
||||||
|
BEGIN
|
||||||
|
SELECT u, o, p INTO username, orgname, apikey_permissions FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text, p json);
|
||||||
|
IF apikey_permissions IS NULL OR NOT apikey_permissions::jsonb ? 'geocoding' THEN
|
||||||
|
RAISE EXCEPTION 'Geocoding permission denied' USING ERRCODE = '01007';
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
-- JSON value stored "" is taken as literal
|
||||||
|
IF username IS NULL OR username = '' OR username = '""' THEN
|
||||||
|
RAISE EXCEPTION 'Username is a mandatory argument, check it out';
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
SELECT csqi.monthly_quota - csqi.used_quota AS remaining_quota, csqi.max_batch_size
|
||||||
|
INTO remaining_quota, max_batch_size
|
||||||
|
FROM cdb_dataservices_client.cdb_service_quota_info_batch() csqi
|
||||||
|
WHERE service = 'hires_geocoder';
|
||||||
|
RAISE DEBUG 'remaining_quota: %; max_batch_size: %', remaining_quota, max_batch_size;
|
||||||
|
|
||||||
|
IF batch_size IS NULL THEN
|
||||||
|
batch_size := max_batch_size;
|
||||||
|
ELSIF batch_size > max_batch_size THEN
|
||||||
|
RAISE EXCEPTION 'batch_size must be lower than %', max_batch_size + 1;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
IF batch_size > MAX_SAFE_BATCH_SIZE THEN
|
||||||
|
batch_size := MAX_SAFE_BATCH_SIZE;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
EXECUTE format('SELECT count(1), ceil(count(1)::float/%s) FROM (%s) _x', batch_size, query)
|
||||||
|
INTO query_row_count, batches_n;
|
||||||
|
|
||||||
|
RAISE DEBUG 'cdb_bulk_geocode_street_point --> query_row_count: %; query: %; country: %; state: %; city: %; street: %',
|
||||||
|
query_row_count, query, country_column, state_column, city_column, street_column;
|
||||||
|
SELECT cdb_dataservices_client.cdb_enough_quota('hires_geocoder', query_row_count) INTO enough_quota;
|
||||||
|
IF enough_quota IS NULL OR NOT enough_quota THEN
|
||||||
|
RAISE EXCEPTION 'Remaining quota: %. Estimated cost: %', remaining_quota, query_row_count;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
RAISE DEBUG 'batches_n: %', batches_n;
|
||||||
|
|
||||||
|
temp_table_name := 'bulk_geocode_street_' || md5(random()::text);
|
||||||
|
|
||||||
|
EXECUTE format('CREATE TEMPORARY TABLE %s ' ||
|
||||||
|
'(cartodb_id integer, the_geom geometry(Point,4326), metadata jsonb)',
|
||||||
|
temp_table_name);
|
||||||
|
|
||||||
|
select
|
||||||
|
coalesce(street_column, ''''''), coalesce(city_column, ''''''),
|
||||||
|
coalesce(state_column, ''''''), coalesce(country_column, '''''')
|
||||||
|
into street_column, city_column, state_column, country_column;
|
||||||
|
|
||||||
|
IF batches_n > 0 THEN
|
||||||
|
FOR cartodb_id_batch in 0..(batches_n - 1)
|
||||||
|
LOOP
|
||||||
|
EXECUTE format(
|
||||||
|
'WITH geocoding_data as (' ||
|
||||||
|
' SELECT ' ||
|
||||||
|
' json_build_object(''id'', cartodb_id, ''address'', %s, ''city'', %s, ''state'', %s, ''country'', %s) as data , ' ||
|
||||||
|
' floor((row_number() over () - 1)::float/$1) as batch' ||
|
||||||
|
' FROM (%s) _x' ||
|
||||||
|
') ' ||
|
||||||
|
'INSERT INTO %s SELECT (cdb_dataservices_client._cdb_bulk_geocode_street_point(jsonb_agg(data))).* ' ||
|
||||||
|
'FROM geocoding_data ' ||
|
||||||
|
'WHERE batch = $2', street_column, city_column, state_column, country_column, query, temp_table_name)
|
||||||
|
USING batch_size, cartodb_id_batch;
|
||||||
|
|
||||||
|
END LOOP;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
RETURN QUERY EXECUTE 'SELECT * FROM ' || quote_ident(temp_table_name);
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE 'plpgsql' SECURITY DEFINER VOLATILE PARALLEL UNSAFE;
|
||||||
96
client/cdb_dataservices_client--0.26.2--0.26.1.sql
Normal file
96
client/cdb_dataservices_client--0.26.2--0.26.1.sql
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
|
||||||
|
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||||
|
\echo Use "ALTER EXTENSION cdb_dataservices_client UPDATE TO '0.26.1'" to load this file. \quit
|
||||||
|
|
||||||
|
-- Make sure we have a sane search path to create/update the extension
|
||||||
|
SET search_path = "$user",cartodb,public,cdb_dataservices_client;
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_client.cdb_bulk_geocode_street_point (query text,
|
||||||
|
street_column text, city_column text default null, state_column text default null, country_column text default null, batch_size integer DEFAULT NULL)
|
||||||
|
RETURNS SETOF cdb_dataservices_client.geocoding AS $$
|
||||||
|
DECLARE
|
||||||
|
query_row_count integer;
|
||||||
|
enough_quota boolean;
|
||||||
|
remaining_quota integer;
|
||||||
|
max_batch_size integer;
|
||||||
|
|
||||||
|
cartodb_id_batch integer;
|
||||||
|
batches_n integer;
|
||||||
|
DEFAULT_BATCH_SIZE CONSTANT numeric := 100;
|
||||||
|
MAX_SAFE_BATCH_SIZE CONSTANT numeric := 5000;
|
||||||
|
|
||||||
|
temp_table_name text;
|
||||||
|
username text;
|
||||||
|
orgname text;
|
||||||
|
apikey_permissions json;
|
||||||
|
BEGIN
|
||||||
|
SELECT u, o, p INTO username, orgname, apikey_permissions FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text, p json);
|
||||||
|
IF apikey_permissions IS NULL OR NOT apikey_permissions::jsonb ? 'geocoding' THEN
|
||||||
|
RAISE EXCEPTION 'Geocoding permission denied' USING ERRCODE = '01007';
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
-- JSON value stored "" is taken as literal
|
||||||
|
IF username IS NULL OR username = '' OR username = '""' THEN
|
||||||
|
RAISE EXCEPTION 'Username is a mandatory argument, check it out';
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
SELECT csqi.monthly_quota - csqi.used_quota AS remaining_quota, csqi.max_batch_size
|
||||||
|
INTO remaining_quota, max_batch_size
|
||||||
|
FROM cdb_dataservices_client.cdb_service_quota_info_batch() csqi
|
||||||
|
WHERE service = 'hires_geocoder';
|
||||||
|
RAISE DEBUG 'remaining_quota: %; max_batch_size: %', remaining_quota, max_batch_size;
|
||||||
|
|
||||||
|
IF batch_size IS NULL THEN
|
||||||
|
batch_size := max_batch_size;
|
||||||
|
ELSIF batch_size > max_batch_size THEN
|
||||||
|
RAISE EXCEPTION 'batch_size must be lower than %', max_batch_size + 1;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
IF batch_size > MAX_SAFE_BATCH_SIZE THEN
|
||||||
|
batch_size := MAX_SAFE_BATCH_SIZE;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
EXECUTE format('SELECT count(1), ceil(count(1)::float/%s) FROM (%s) _x', batch_size, query)
|
||||||
|
INTO query_row_count, batches_n;
|
||||||
|
|
||||||
|
RAISE DEBUG 'cdb_bulk_geocode_street_point --> query_row_count: %; query: %; country: %; state: %; city: %; street: %',
|
||||||
|
query_row_count, query, country_column, state_column, city_column, street_column;
|
||||||
|
SELECT cdb_dataservices_client.cdb_enough_quota('hires_geocoder', query_row_count) INTO enough_quota;
|
||||||
|
IF remaining_quota < query_row_count THEN
|
||||||
|
RAISE EXCEPTION 'Remaining quota: %. Estimated cost: %', remaining_quota, query_row_count;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
RAISE DEBUG 'batches_n: %', batches_n;
|
||||||
|
|
||||||
|
temp_table_name := 'bulk_geocode_street_' || md5(random()::text);
|
||||||
|
|
||||||
|
EXECUTE format('CREATE TEMPORARY TABLE %s ' ||
|
||||||
|
'(cartodb_id integer, the_geom geometry(Point,4326), metadata jsonb)',
|
||||||
|
temp_table_name);
|
||||||
|
|
||||||
|
select
|
||||||
|
coalesce(street_column, ''''''), coalesce(city_column, ''''''),
|
||||||
|
coalesce(state_column, ''''''), coalesce(country_column, '''''')
|
||||||
|
into street_column, city_column, state_column, country_column;
|
||||||
|
|
||||||
|
IF batches_n > 0 THEN
|
||||||
|
FOR cartodb_id_batch in 0..(batches_n - 1)
|
||||||
|
LOOP
|
||||||
|
EXECUTE format(
|
||||||
|
'WITH geocoding_data as (' ||
|
||||||
|
' SELECT ' ||
|
||||||
|
' json_build_object(''id'', cartodb_id, ''address'', %s, ''city'', %s, ''state'', %s, ''country'', %s) as data , ' ||
|
||||||
|
' floor((row_number() over () - 1)::float/$1) as batch' ||
|
||||||
|
' FROM (%s) _x' ||
|
||||||
|
') ' ||
|
||||||
|
'INSERT INTO %s SELECT (cdb_dataservices_client._cdb_bulk_geocode_street_point(jsonb_agg(data))).* ' ||
|
||||||
|
'FROM geocoding_data ' ||
|
||||||
|
'WHERE batch = $2', street_column, city_column, state_column, country_column, query, temp_table_name)
|
||||||
|
USING batch_size, cartodb_id_batch;
|
||||||
|
|
||||||
|
END LOOP;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
RETURN QUERY EXECUTE 'SELECT * FROM ' || quote_ident(temp_table_name);
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE 'plpgsql' SECURITY DEFINER VOLATILE PARALLEL UNSAFE;
|
||||||
5606
client/cdb_dataservices_client--0.26.2.sql
Normal file
5606
client/cdb_dataservices_client--0.26.2.sql
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
|||||||
comment = 'CartoDB dataservices client API extension'
|
comment = 'CartoDB dataservices client API extension'
|
||||||
default_version = '0.26.0'
|
default_version = '0.26.2'
|
||||||
requires = 'plproxy, cartodb'
|
requires = 'plproxy, cartodb'
|
||||||
superuser = true
|
superuser = true
|
||||||
schema = cdb_dataservices_client
|
schema = cdb_dataservices_client
|
||||||
|
|||||||
@@ -0,0 +1,99 @@
|
|||||||
|
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
|
||||||
|
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||||
|
\echo Use "ALTER EXTENSION cdb_dataservices_client UPDATE TO '0.26.1'" to load this file. \quit
|
||||||
|
|
||||||
|
-- Make sure we have a sane search path to create/update the extension
|
||||||
|
SET search_path = "$user",cartodb,public,cdb_dataservices_client;
|
||||||
|
|
||||||
|
-- HERE goes your code to upgrade/downgrade
|
||||||
|
ALTER TYPE cdb_dataservices_client.geocoding ALTER ATTRIBUTE the_geom TYPE geometry(Point,4326);
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_client.cdb_bulk_geocode_street_point (query text,
|
||||||
|
street_column text, city_column text default null, state_column text default null, country_column text default null, batch_size integer DEFAULT NULL)
|
||||||
|
RETURNS SETOF cdb_dataservices_client.geocoding AS $$
|
||||||
|
DECLARE
|
||||||
|
query_row_count integer;
|
||||||
|
enough_quota boolean;
|
||||||
|
remaining_quota integer;
|
||||||
|
max_batch_size integer;
|
||||||
|
|
||||||
|
cartodb_id_batch integer;
|
||||||
|
batches_n integer;
|
||||||
|
DEFAULT_BATCH_SIZE CONSTANT numeric := 100;
|
||||||
|
MAX_SAFE_BATCH_SIZE CONSTANT numeric := 5000;
|
||||||
|
|
||||||
|
temp_table_name text;
|
||||||
|
username text;
|
||||||
|
orgname text;
|
||||||
|
apikey_permissions json;
|
||||||
|
BEGIN
|
||||||
|
SELECT u, o, p INTO username, orgname, apikey_permissions FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text, p json);
|
||||||
|
IF apikey_permissions IS NULL OR NOT apikey_permissions::jsonb ? 'geocoding' THEN
|
||||||
|
RAISE EXCEPTION 'Geocoding permission denied' USING ERRCODE = '01007';
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
-- JSON value stored "" is taken as literal
|
||||||
|
IF username IS NULL OR username = '' OR username = '""' THEN
|
||||||
|
RAISE EXCEPTION 'Username is a mandatory argument, check it out';
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
SELECT csqi.monthly_quota - csqi.used_quota AS remaining_quota, csqi.max_batch_size
|
||||||
|
INTO remaining_quota, max_batch_size
|
||||||
|
FROM cdb_dataservices_client.cdb_service_quota_info_batch() csqi
|
||||||
|
WHERE service = 'hires_geocoder';
|
||||||
|
RAISE DEBUG 'remaining_quota: %; max_batch_size: %', remaining_quota, max_batch_size;
|
||||||
|
|
||||||
|
IF batch_size IS NULL THEN
|
||||||
|
batch_size := max_batch_size;
|
||||||
|
ELSIF batch_size > max_batch_size THEN
|
||||||
|
RAISE EXCEPTION 'batch_size must be lower than %', max_batch_size + 1;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
IF batch_size > MAX_SAFE_BATCH_SIZE THEN
|
||||||
|
batch_size := MAX_SAFE_BATCH_SIZE;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
EXECUTE format('SELECT count(1), ceil(count(1)::float/%s) FROM (%s) _x', batch_size, query)
|
||||||
|
INTO query_row_count, batches_n;
|
||||||
|
|
||||||
|
RAISE DEBUG 'cdb_bulk_geocode_street_point --> query_row_count: %; query: %; country: %; state: %; city: %; street: %',
|
||||||
|
query_row_count, query, country_column, state_column, city_column, street_column;
|
||||||
|
SELECT cdb_dataservices_client.cdb_enough_quota('hires_geocoder', query_row_count) INTO enough_quota;
|
||||||
|
IF remaining_quota < query_row_count THEN
|
||||||
|
RAISE EXCEPTION 'Remaining quota: %. Estimated cost: %', remaining_quota, query_row_count;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
RAISE DEBUG 'batches_n: %', batches_n;
|
||||||
|
|
||||||
|
temp_table_name := 'bulk_geocode_street_' || md5(random()::text);
|
||||||
|
|
||||||
|
EXECUTE format('CREATE TEMPORARY TABLE %s ' ||
|
||||||
|
'(cartodb_id integer, the_geom geometry(Point,4326), metadata jsonb)',
|
||||||
|
temp_table_name);
|
||||||
|
|
||||||
|
select
|
||||||
|
coalesce(street_column, ''''''), coalesce(city_column, ''''''),
|
||||||
|
coalesce(state_column, ''''''), coalesce(country_column, '''''')
|
||||||
|
into street_column, city_column, state_column, country_column;
|
||||||
|
|
||||||
|
IF batches_n > 0 THEN
|
||||||
|
FOR cartodb_id_batch in 0..(batches_n - 1)
|
||||||
|
LOOP
|
||||||
|
EXECUTE format(
|
||||||
|
'WITH geocoding_data as (' ||
|
||||||
|
' SELECT ' ||
|
||||||
|
' json_build_object(''id'', cartodb_id, ''address'', %s, ''city'', %s, ''state'', %s, ''country'', %s) as data , ' ||
|
||||||
|
' floor((row_number() over () - 1)::float/$1) as batch' ||
|
||||||
|
' FROM (%s) _x' ||
|
||||||
|
') ' ||
|
||||||
|
'INSERT INTO %s SELECT (cdb_dataservices_client._cdb_bulk_geocode_street_point(jsonb_agg(data))).* ' ||
|
||||||
|
'FROM geocoding_data ' ||
|
||||||
|
'WHERE batch = $2', street_column, city_column, state_column, country_column, query, temp_table_name)
|
||||||
|
USING batch_size, cartodb_id_batch;
|
||||||
|
|
||||||
|
END LOOP;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
RETURN QUERY EXECUTE 'SELECT * FROM ' || quote_ident(temp_table_name);
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE 'plpgsql' SECURITY DEFINER VOLATILE PARALLEL UNSAFE;
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
|
||||||
|
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||||
|
\echo Use "ALTER EXTENSION cdb_dataservices_client UPDATE TO '0.26.0'" to load this file. \quit
|
||||||
|
|
||||||
|
-- Make sure we have a sane search path to create/update the extension
|
||||||
|
SET search_path = "$user",cartodb,public,cdb_dataservices_client;
|
||||||
|
|
||||||
|
-- HERE goes your code to upgrade/downgrade
|
||||||
|
ALTER TYPE cdb_dataservices_client.geocoding ALTER ATTRIBUTE the_geom TYPE geometry(MultiPolygon,4326);
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_client.cdb_bulk_geocode_street_point (query text,
|
||||||
|
street_column text, city_column text default null, state_column text default null, country_column text default null, batch_size integer DEFAULT NULL)
|
||||||
|
RETURNS SETOF cdb_dataservices_client.geocoding AS $$
|
||||||
|
DECLARE
|
||||||
|
query_row_count integer;
|
||||||
|
enough_quota boolean;
|
||||||
|
remaining_quota integer;
|
||||||
|
max_batch_size integer;
|
||||||
|
|
||||||
|
cartodb_id_batch integer;
|
||||||
|
batches_n integer;
|
||||||
|
DEFAULT_BATCH_SIZE CONSTANT numeric := 100;
|
||||||
|
MAX_SAFE_BATCH_SIZE CONSTANT numeric := 5000;
|
||||||
|
|
||||||
|
temp_table_name text;
|
||||||
|
username text;
|
||||||
|
orgname text;
|
||||||
|
apikey_permissions json;
|
||||||
|
BEGIN
|
||||||
|
SELECT u, o, p INTO username, orgname, apikey_permissions FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text, p json);
|
||||||
|
IF apikey_permissions IS NULL OR NOT apikey_permissions::jsonb ? 'geocoding' THEN
|
||||||
|
RAISE EXCEPTION 'Geocoding permission denied' USING ERRCODE = '01007';
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
-- JSON value stored "" is taken as literal
|
||||||
|
IF username IS NULL OR username = '' OR username = '""' THEN
|
||||||
|
RAISE EXCEPTION 'Username is a mandatory argument, check it out';
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
SELECT csqi.monthly_quota - csqi.used_quota AS remaining_quota, csqi.max_batch_size
|
||||||
|
INTO remaining_quota, max_batch_size
|
||||||
|
FROM cdb_dataservices_client.cdb_service_quota_info_batch() csqi
|
||||||
|
WHERE service = 'hires_geocoder';
|
||||||
|
RAISE DEBUG 'remaining_quota: %; max_batch_size: %', remaining_quota, max_batch_size;
|
||||||
|
|
||||||
|
IF batch_size IS NULL THEN
|
||||||
|
batch_size := max_batch_size;
|
||||||
|
ELSIF batch_size > max_batch_size THEN
|
||||||
|
RAISE EXCEPTION 'batch_size must be lower than %', max_batch_size + 1;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
IF batch_size > MAX_SAFE_BATCH_SIZE THEN
|
||||||
|
batch_size := MAX_SAFE_BATCH_SIZE;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
EXECUTE format('SELECT count(1), ceil(count(1)::float/%s) FROM (%s) _x', batch_size, query)
|
||||||
|
INTO query_row_count, batches_n;
|
||||||
|
|
||||||
|
RAISE DEBUG 'cdb_bulk_geocode_street_point --> query_row_count: %; query: %; country: %; state: %; city: %; street: %',
|
||||||
|
query_row_count, query, country_column, state_column, city_column, street_column;
|
||||||
|
SELECT cdb_dataservices_client.cdb_enough_quota('hires_geocoder', query_row_count) INTO enough_quota;
|
||||||
|
IF remaining_quota < query_row_count THEN
|
||||||
|
RAISE EXCEPTION 'Remaining quota: %. Estimated cost: %', remaining_quota, query_row_count;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
RAISE DEBUG 'batches_n: %', batches_n;
|
||||||
|
|
||||||
|
temp_table_name := 'bulk_geocode_street_' || md5(random()::text);
|
||||||
|
|
||||||
|
EXECUTE format('CREATE TEMPORARY TABLE %s ' ||
|
||||||
|
'(cartodb_id integer, the_geom geometry(Multipolygon,4326), metadata jsonb)',
|
||||||
|
temp_table_name);
|
||||||
|
|
||||||
|
select
|
||||||
|
coalesce(street_column, ''''''), coalesce(city_column, ''''''),
|
||||||
|
coalesce(state_column, ''''''), coalesce(country_column, '''''')
|
||||||
|
into street_column, city_column, state_column, country_column;
|
||||||
|
|
||||||
|
IF batches_n > 0 THEN
|
||||||
|
FOR cartodb_id_batch in 0..(batches_n - 1)
|
||||||
|
LOOP
|
||||||
|
EXECUTE format(
|
||||||
|
'WITH geocoding_data as (' ||
|
||||||
|
' SELECT ' ||
|
||||||
|
' json_build_object(''id'', cartodb_id, ''address'', %s, ''city'', %s, ''state'', %s, ''country'', %s) as data , ' ||
|
||||||
|
' floor((row_number() over () - 1)::float/$1) as batch' ||
|
||||||
|
' FROM (%s) _x' ||
|
||||||
|
') ' ||
|
||||||
|
'INSERT INTO %s SELECT (cdb_dataservices_client._cdb_bulk_geocode_street_point(jsonb_agg(data))).* ' ||
|
||||||
|
'FROM geocoding_data ' ||
|
||||||
|
'WHERE batch = $2', street_column, city_column, state_column, country_column, query, temp_table_name)
|
||||||
|
USING batch_size, cartodb_id_batch;
|
||||||
|
|
||||||
|
END LOOP;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
RETURN QUERY EXECUTE 'SELECT * FROM ' || quote_ident(temp_table_name);
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE 'plpgsql' SECURITY DEFINER VOLATILE PARALLEL UNSAFE;
|
||||||
5606
client/old_versions/cdb_dataservices_client--0.26.1.sql
Normal file
5606
client/old_versions/cdb_dataservices_client--0.26.1.sql
Normal file
File diff suppressed because it is too large
Load Diff
@@ -6,7 +6,7 @@ CREATE TYPE cdb_dataservices_client.isoline AS (
|
|||||||
|
|
||||||
CREATE TYPE cdb_dataservices_client.geocoding AS (
|
CREATE TYPE cdb_dataservices_client.geocoding AS (
|
||||||
cartodb_id integer,
|
cartodb_id integer,
|
||||||
the_geom geometry(Multipolygon,4326),
|
the_geom geometry(Point,4326),
|
||||||
metadata jsonb
|
metadata jsonb
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ BEGIN
|
|||||||
RAISE DEBUG 'cdb_bulk_geocode_street_point --> query_row_count: %; query: %; country: %; state: %; city: %; street: %',
|
RAISE DEBUG 'cdb_bulk_geocode_street_point --> query_row_count: %; query: %; country: %; state: %; city: %; street: %',
|
||||||
query_row_count, query, country_column, state_column, city_column, street_column;
|
query_row_count, query, country_column, state_column, city_column, street_column;
|
||||||
SELECT cdb_dataservices_client.cdb_enough_quota('hires_geocoder', query_row_count) INTO enough_quota;
|
SELECT cdb_dataservices_client.cdb_enough_quota('hires_geocoder', query_row_count) INTO enough_quota;
|
||||||
IF remaining_quota < query_row_count THEN
|
IF enough_quota IS NULL OR NOT enough_quota THEN
|
||||||
RAISE EXCEPTION 'Remaining quota: %. Estimated cost: %', remaining_quota, query_row_count;
|
RAISE EXCEPTION 'Remaining quota: %. Estimated cost: %', remaining_quota, query_row_count;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
@@ -58,7 +58,7 @@ BEGIN
|
|||||||
temp_table_name := 'bulk_geocode_street_' || md5(random()::text);
|
temp_table_name := 'bulk_geocode_street_' || md5(random()::text);
|
||||||
|
|
||||||
EXECUTE format('CREATE TEMPORARY TABLE %s ' ||
|
EXECUTE format('CREATE TEMPORARY TABLE %s ' ||
|
||||||
'(cartodb_id integer, the_geom geometry(Multipolygon,4326), metadata jsonb)',
|
'(cartodb_id integer, the_geom geometry(Point,4326), metadata jsonb)',
|
||||||
temp_table_name);
|
temp_table_name);
|
||||||
|
|
||||||
select
|
select
|
||||||
|
|||||||
@@ -9,6 +9,13 @@ CREATE FUNCTION cdb_dataservices_client.cdb_enough_quota (service TEXT ,input_si
|
|||||||
RETURNS BOOLEAN as $$
|
RETURNS BOOLEAN as $$
|
||||||
SELECT FALSE;
|
SELECT FALSE;
|
||||||
$$ LANGUAGE SQL;
|
$$ LANGUAGE SQL;
|
||||||
|
ALTER FUNCTION cdb_dataservices_client._cdb_bulk_geocode_street_point(searches jsonb) RENAME TO _cdb_bulk_geocode_street_point_mocked;
|
||||||
|
CREATE FUNCTION cdb_dataservices_client._cdb_bulk_geocode_street_point(searches jsonb)
|
||||||
|
RETURNS SETOF cdb_dataservices_client.geocoding AS $$
|
||||||
|
BEGIN
|
||||||
|
RAISE NOTICE 'called with this searches: %', searches;
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE 'plpgsql' SECURITY DEFINER STABLE PARALLEL UNSAFE;
|
||||||
-- No permissions granted
|
-- No permissions granted
|
||||||
-- Test bulk size not mandatory (it will get the optimal)
|
-- Test bulk size not mandatory (it will get the optimal)
|
||||||
SELECT cdb_dataservices_client.cdb_bulk_geocode_street_point('select 1 as cartodb_id', '''Valladolid, Spain''', null, null, null, null);
|
SELECT cdb_dataservices_client.cdb_bulk_geocode_street_point('select 1 as cartodb_id', '''Valladolid, Spain''', null, null, null, null);
|
||||||
@@ -42,6 +49,18 @@ ERROR: Remaining quota: 0. Estimated cost: 1
|
|||||||
-- Test quota check by mocking quota 0
|
-- Test quota check by mocking quota 0
|
||||||
SELECT cdb_dataservices_client.cdb_bulk_geocode_street_point('select 1 as cartodb_id', '''Valladolid, Spain''');
|
SELECT cdb_dataservices_client.cdb_bulk_geocode_street_point('select 1 as cartodb_id', '''Valladolid, Spain''');
|
||||||
ERROR: Remaining quota: 0. Estimated cost: 1
|
ERROR: Remaining quota: 0. Estimated cost: 1
|
||||||
|
-- Check that when cdb_enough_quota returns true (ie. when soft_limit is set to true, even if not enough quota)
|
||||||
|
-- it is able to proceed with the bulk geocode
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_client.cdb_enough_quota (service TEXT ,input_size NUMERIC)
|
||||||
|
RETURNS BOOLEAN as $$
|
||||||
|
SELECT TRUE;
|
||||||
|
$$ LANGUAGE SQL;
|
||||||
|
SELECT cdb_dataservices_client.cdb_bulk_geocode_street_point('select 1 as cartodb_id', '''Valladolid, Spain''');
|
||||||
|
NOTICE: called with this searches: [{"id": 1, "city": "", "state": "", "address": "Valladolid, Spain", "country": ""}]
|
||||||
|
cdb_bulk_geocode_street_point
|
||||||
|
-------------------------------
|
||||||
|
(0 rows)
|
||||||
|
|
||||||
-- Remove permissions
|
-- Remove permissions
|
||||||
SELECT CDB_Conf_RemoveConf('api_keys_postgres');
|
SELECT CDB_Conf_RemoveConf('api_keys_postgres');
|
||||||
cdb_conf_removeconf
|
cdb_conf_removeconf
|
||||||
@@ -51,5 +70,7 @@ SELECT CDB_Conf_RemoveConf('api_keys_postgres');
|
|||||||
|
|
||||||
DROP FUNCTION cdb_dataservices_client.cdb_service_quota_info_batch;
|
DROP FUNCTION cdb_dataservices_client.cdb_service_quota_info_batch;
|
||||||
DROP FUNCTION cdb_dataservices_client.cdb_enough_quota;
|
DROP FUNCTION cdb_dataservices_client.cdb_enough_quota;
|
||||||
|
DROP FUNCTION cdb_dataservices_client._cdb_bulk_geocode_street_point;
|
||||||
ALTER FUNCTION cdb_dataservices_client.cdb_enough_quota_mocked (service TEXT ,input_size NUMERIC) RENAME TO cdb_enough_quota;
|
ALTER FUNCTION cdb_dataservices_client.cdb_enough_quota_mocked (service TEXT ,input_size NUMERIC) RENAME TO cdb_enough_quota;
|
||||||
ALTER FUNCTION cdb_dataservices_client.cdb_service_quota_info_batch_mocked() RENAME TO cdb_service_quota_info_batch;
|
ALTER FUNCTION cdb_dataservices_client.cdb_service_quota_info_batch_mocked() RENAME TO cdb_service_quota_info_batch;
|
||||||
|
ALTER FUNCTION cdb_dataservices_client._cdb_bulk_geocode_street_point_mocked(searches jsonb) RENAME TO _cdb_bulk_geocode_street_point;
|
||||||
|
|||||||
@@ -12,6 +12,14 @@ RETURNS BOOLEAN as $$
|
|||||||
SELECT FALSE;
|
SELECT FALSE;
|
||||||
$$ LANGUAGE SQL;
|
$$ LANGUAGE SQL;
|
||||||
|
|
||||||
|
ALTER FUNCTION cdb_dataservices_client._cdb_bulk_geocode_street_point(searches jsonb) RENAME TO _cdb_bulk_geocode_street_point_mocked;
|
||||||
|
CREATE FUNCTION cdb_dataservices_client._cdb_bulk_geocode_street_point(searches jsonb)
|
||||||
|
RETURNS SETOF cdb_dataservices_client.geocoding AS $$
|
||||||
|
BEGIN
|
||||||
|
RAISE NOTICE 'called with this searches: %', searches;
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE 'plpgsql' SECURITY DEFINER STABLE PARALLEL UNSAFE;
|
||||||
|
|
||||||
-- No permissions granted
|
-- No permissions granted
|
||||||
-- Test bulk size not mandatory (it will get the optimal)
|
-- Test bulk size not mandatory (it will get the optimal)
|
||||||
SELECT cdb_dataservices_client.cdb_bulk_geocode_street_point('select 1 as cartodb_id', '''Valladolid, Spain''', null, null, null, null);
|
SELECT cdb_dataservices_client.cdb_bulk_geocode_street_point('select 1 as cartodb_id', '''Valladolid, Spain''', null, null, null, null);
|
||||||
@@ -32,12 +40,21 @@ SELECT cdb_dataservices_client.cdb_bulk_geocode_street_point('select 1 as cartod
|
|||||||
-- Test quota check by mocking quota 0
|
-- Test quota check by mocking quota 0
|
||||||
SELECT cdb_dataservices_client.cdb_bulk_geocode_street_point('select 1 as cartodb_id', '''Valladolid, Spain''');
|
SELECT cdb_dataservices_client.cdb_bulk_geocode_street_point('select 1 as cartodb_id', '''Valladolid, Spain''');
|
||||||
|
|
||||||
|
-- Check that when cdb_enough_quota returns true (ie. when soft_limit is set to true, even if not enough quota)
|
||||||
|
-- it is able to proceed with the bulk geocode
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_client.cdb_enough_quota (service TEXT ,input_size NUMERIC)
|
||||||
|
RETURNS BOOLEAN as $$
|
||||||
|
SELECT TRUE;
|
||||||
|
$$ LANGUAGE SQL;
|
||||||
|
SELECT cdb_dataservices_client.cdb_bulk_geocode_street_point('select 1 as cartodb_id', '''Valladolid, Spain''');
|
||||||
|
|
||||||
-- Remove permissions
|
-- Remove permissions
|
||||||
SELECT CDB_Conf_RemoveConf('api_keys_postgres');
|
SELECT CDB_Conf_RemoveConf('api_keys_postgres');
|
||||||
|
|
||||||
DROP FUNCTION cdb_dataservices_client.cdb_service_quota_info_batch;
|
DROP FUNCTION cdb_dataservices_client.cdb_service_quota_info_batch;
|
||||||
DROP FUNCTION cdb_dataservices_client.cdb_enough_quota;
|
DROP FUNCTION cdb_dataservices_client.cdb_enough_quota;
|
||||||
|
DROP FUNCTION cdb_dataservices_client._cdb_bulk_geocode_street_point;
|
||||||
|
|
||||||
ALTER FUNCTION cdb_dataservices_client.cdb_enough_quota_mocked (service TEXT ,input_size NUMERIC) RENAME TO cdb_enough_quota;
|
ALTER FUNCTION cdb_dataservices_client.cdb_enough_quota_mocked (service TEXT ,input_size NUMERIC) RENAME TO cdb_enough_quota;
|
||||||
ALTER FUNCTION cdb_dataservices_client.cdb_service_quota_info_batch_mocked() RENAME TO cdb_service_quota_info_batch;
|
ALTER FUNCTION cdb_dataservices_client.cdb_service_quota_info_batch_mocked() RENAME TO cdb_service_quota_info_batch;
|
||||||
|
ALTER FUNCTION cdb_dataservices_client._cdb_bulk_geocode_street_point_mocked(searches jsonb) RENAME TO _cdb_bulk_geocode_street_point;
|
||||||
|
|||||||
@@ -81,4 +81,4 @@ The optional value parameters must be passed using the format: `option=value`. N
|
|||||||
|
|
||||||
Name | Type | Description | Accepted values
|
Name | Type | Description | Accepted values
|
||||||
--- | --- | --- | ---
|
--- | --- | --- | ---
|
||||||
`mode_type` | `text` | Type of route calculation | `shortest` (this option only applies to the car transport mode)
|
`mode_type` | `text` | Type of route calculation | `shortest` or `fastest` (this option only applies to the car transport mode)
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
|
||||||
|
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||||
|
\echo Use "ALTER EXTENSION cdb_dataservices_server UPDATE TO '0.35.1'" to load this file. \quit
|
||||||
|
|
||||||
|
-- HERE goes your code to upgrade/downgrade
|
||||||
|
ALTER TYPE cdb_dataservices_server.geocoding ALTER ATTRIBUTE the_geom TYPE geometry(Point,4326);
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
|
||||||
|
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||||
|
\echo Use "ALTER EXTENSION cdb_dataservices_server UPDATE TO '0.35.0'" to load this file. \quit
|
||||||
|
|
||||||
|
-- HERE goes your code to upgrade/downgrade
|
||||||
|
ALTER TYPE cdb_dataservices_server.geocoding ALTER ATTRIBUTE the_geom TYPE geometry(MultiPolygon,4326);
|
||||||
3808
server/extension/cdb_dataservices_server--0.35.1.sql
Normal file
3808
server/extension/cdb_dataservices_server--0.35.1.sql
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
|||||||
comment = 'CartoDB dataservices server extension'
|
comment = 'CartoDB dataservices server extension'
|
||||||
default_version = '0.34.0'
|
default_version = '0.35.1'
|
||||||
requires = 'plpythonu, plproxy, postgis, cdb_geocoder'
|
requires = 'plpythonu, plproxy, postgis, cdb_geocoder'
|
||||||
superuser = true
|
superuser = true
|
||||||
schema = cdb_dataservices_server
|
schema = cdb_dataservices_server
|
||||||
|
|||||||
@@ -0,0 +1,182 @@
|
|||||||
|
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
|
||||||
|
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||||
|
\echo Use "ALTER EXTENSION cdb_dataservices_server UPDATE TO '0.34.1'" to load this file. \quit
|
||||||
|
|
||||||
|
-- HERE goes your code to upgrade/downgrade
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_mapzen_isochrones(
|
||||||
|
username TEXT,
|
||||||
|
orgname TEXT,
|
||||||
|
source geometry(Geometry, 4326),
|
||||||
|
mode TEXT,
|
||||||
|
data_range integer[],
|
||||||
|
options text[])
|
||||||
|
RETURNS SETOF cdb_dataservices_server.isoline AS $$
|
||||||
|
import json
|
||||||
|
from cartodb_services.mapzen import MatrixClient, MapzenIsochrones
|
||||||
|
from cartodb_services.metrics import QuotaService
|
||||||
|
from cartodb_services.tools import Logger,LoggerConfig
|
||||||
|
from cartodb_services.mapzen.types import coordinates_to_polygon
|
||||||
|
|
||||||
|
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||||
|
user_isolines_routing_config = GD["user_isolines_routing_config_{0}".format(username)]
|
||||||
|
|
||||||
|
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
|
||||||
|
logger_config = GD["logger_config"]
|
||||||
|
logger = Logger(logger_config)
|
||||||
|
# -- Check the quota
|
||||||
|
quota_service = QuotaService(user_isolines_routing_config, redis_conn)
|
||||||
|
if not quota_service.check_user_quota():
|
||||||
|
raise Exception('You have reached the limit of your quota')
|
||||||
|
|
||||||
|
try:
|
||||||
|
mapzen_isochrones = MapzenIsochrones(user_isolines_routing_config.mapzen_matrix_api_key,
|
||||||
|
logger, user_isolines_routing_config.mapzen_isochrones_service_params)
|
||||||
|
|
||||||
|
if source:
|
||||||
|
lat = plpy.execute("SELECT ST_Y('%s') AS lat" % source)[0]['lat']
|
||||||
|
lon = plpy.execute("SELECT ST_X('%s') AS lon" % source)[0]['lon']
|
||||||
|
origin = {'lat': lat, 'lon': lon}
|
||||||
|
else:
|
||||||
|
raise Exception('source is NULL')
|
||||||
|
|
||||||
|
resp = mapzen_isochrones.isochrone(origin, mode, data_range)
|
||||||
|
|
||||||
|
if resp:
|
||||||
|
result = []
|
||||||
|
for isochrone in resp:
|
||||||
|
result_polygon = coordinates_to_polygon(isochrone.coordinates)
|
||||||
|
if result_polygon:
|
||||||
|
result.append([source, isochrone.duration, result_polygon])
|
||||||
|
else:
|
||||||
|
result.append([source, isochrone.duration, None])
|
||||||
|
quota_service.increment_success_service_use()
|
||||||
|
quota_service.increment_isolines_service_use(len(result))
|
||||||
|
return result
|
||||||
|
else:
|
||||||
|
quota_service.increment_empty_service_use()
|
||||||
|
return []
|
||||||
|
except BaseException as e:
|
||||||
|
import sys
|
||||||
|
quota_service.increment_failed_service_use()
|
||||||
|
logger.error('Error trying to get mapzen isochrones', sys.exc_info(), data={"username": username, "orgname": orgname})
|
||||||
|
raise Exception('Error trying to get mapzen isochrones')
|
||||||
|
finally:
|
||||||
|
quota_service.increment_total_service_use()
|
||||||
|
$$ LANGUAGE plpythonu SECURITY DEFINER STABLE PARALLEL RESTRICTED;
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_mapbox_isochrones(
|
||||||
|
username TEXT,
|
||||||
|
orgname TEXT,
|
||||||
|
source geometry(Geometry, 4326),
|
||||||
|
mode TEXT,
|
||||||
|
data_range integer[],
|
||||||
|
options text[])
|
||||||
|
RETURNS SETOF cdb_dataservices_server.isoline AS $$
|
||||||
|
from cartodb_services.tools import ServiceManager
|
||||||
|
from cartodb_services.mapbox import MapboxMatrixClient, MapboxIsolines
|
||||||
|
from cartodb_services.mapbox.types import TRANSPORT_MODE_TO_MAPBOX
|
||||||
|
from cartodb_services.tools import Coordinate
|
||||||
|
from cartodb_services.tools.coordinates import coordinates_to_polygon
|
||||||
|
from cartodb_services.refactor.service.mapbox_isolines_config import MapboxIsolinesConfigBuilder
|
||||||
|
|
||||||
|
import cartodb_services
|
||||||
|
cartodb_services.init(plpy, GD)
|
||||||
|
|
||||||
|
service_manager = ServiceManager('isolines', MapboxIsolinesConfigBuilder, username, orgname, GD)
|
||||||
|
service_manager.assert_within_limits()
|
||||||
|
|
||||||
|
try:
|
||||||
|
client = MapboxMatrixClient(service_manager.config.mapbox_api_key, service_manager.logger, service_manager.config.service_params)
|
||||||
|
mapbox_isolines = MapboxIsolines(client, service_manager.logger)
|
||||||
|
|
||||||
|
if source:
|
||||||
|
lat = plpy.execute("SELECT ST_Y('%s') AS lat" % source)[0]['lat']
|
||||||
|
lon = plpy.execute("SELECT ST_X('%s') AS lon" % source)[0]['lon']
|
||||||
|
origin = Coordinate(lon,lat)
|
||||||
|
else:
|
||||||
|
raise Exception('source is NULL')
|
||||||
|
|
||||||
|
profile = TRANSPORT_MODE_TO_MAPBOX.get(mode)
|
||||||
|
|
||||||
|
resp = mapbox_isolines.calculate_isochrone(origin, data_range, profile)
|
||||||
|
|
||||||
|
if resp:
|
||||||
|
result = []
|
||||||
|
for isochrone in resp:
|
||||||
|
result_polygon = coordinates_to_polygon(isochrone.coordinates)
|
||||||
|
if result_polygon:
|
||||||
|
result.append([source, isochrone.duration, result_polygon])
|
||||||
|
else:
|
||||||
|
result.append([source, isochrone.duration, None])
|
||||||
|
service_manager.quota_service.increment_success_service_use()
|
||||||
|
service_manager.quota_service.increment_isolines_service_use(len(result))
|
||||||
|
return result
|
||||||
|
else:
|
||||||
|
service_manager.quota_service.increment_empty_service_use()
|
||||||
|
return []
|
||||||
|
except BaseException as e:
|
||||||
|
import sys
|
||||||
|
service_manager.quota_service.increment_failed_service_use()
|
||||||
|
service_manager.logger.error('Error trying to get Mapbox isochrones', sys.exc_info(), data={"username": username, "orgname": orgname})
|
||||||
|
raise Exception('Error trying to get Mapbox isochrones')
|
||||||
|
finally:
|
||||||
|
service_manager.quota_service.increment_total_service_use()
|
||||||
|
$$ LANGUAGE plpythonu SECURITY DEFINER STABLE PARALLEL RESTRICTED;
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_tomtom_isochrones(
|
||||||
|
username TEXT,
|
||||||
|
orgname TEXT,
|
||||||
|
source geometry(Geometry, 4326),
|
||||||
|
mode TEXT,
|
||||||
|
data_range integer[],
|
||||||
|
options text[])
|
||||||
|
RETURNS SETOF cdb_dataservices_server.isoline AS $$
|
||||||
|
from cartodb_services.tools import ServiceManager
|
||||||
|
from cartodb_services.tomtom import TomTomIsolines
|
||||||
|
from cartodb_services.tomtom.types import TRANSPORT_MODE_TO_TOMTOM
|
||||||
|
from cartodb_services.tools import Coordinate
|
||||||
|
from cartodb_services.tools.coordinates import coordinates_to_polygon
|
||||||
|
from cartodb_services.refactor.service.tomtom_isolines_config import TomTomIsolinesConfigBuilder
|
||||||
|
|
||||||
|
import cartodb_services
|
||||||
|
cartodb_services.init(plpy, GD)
|
||||||
|
|
||||||
|
service_manager = ServiceManager('isolines', TomTomIsolinesConfigBuilder, username, orgname, GD)
|
||||||
|
service_manager.assert_within_limits()
|
||||||
|
|
||||||
|
try:
|
||||||
|
tomtom_isolines = TomTomIsolines(service_manager.config.tomtom_api_key, service_manager.logger, service_manager.config.service_params)
|
||||||
|
|
||||||
|
if source:
|
||||||
|
lat = plpy.execute("SELECT ST_Y('%s') AS lat" % source)[0]['lat']
|
||||||
|
lon = plpy.execute("SELECT ST_X('%s') AS lon" % source)[0]['lon']
|
||||||
|
origin = Coordinate(lon,lat)
|
||||||
|
else:
|
||||||
|
raise Exception('source is NULL')
|
||||||
|
|
||||||
|
profile = TRANSPORT_MODE_TO_TOMTOM.get(mode)
|
||||||
|
|
||||||
|
resp = tomtom_isolines.calculate_isochrone(origin, data_range, profile)
|
||||||
|
|
||||||
|
if resp:
|
||||||
|
result = []
|
||||||
|
for isochrone in resp:
|
||||||
|
result_polygon = coordinates_to_polygon(isochrone.coordinates)
|
||||||
|
if result_polygon:
|
||||||
|
result.append([source, isochrone.duration, result_polygon])
|
||||||
|
else:
|
||||||
|
result.append([source, isochrone.duration, None])
|
||||||
|
service_manager.quota_service.increment_success_service_use()
|
||||||
|
service_manager.quota_service.increment_isolines_service_use(len(result))
|
||||||
|
return result
|
||||||
|
else:
|
||||||
|
service_manager.quota_service.increment_empty_service_use()
|
||||||
|
return []
|
||||||
|
except BaseException as e:
|
||||||
|
import sys
|
||||||
|
service_manager.quota_service.increment_failed_service_use()
|
||||||
|
service_manager.logger.error('Error trying to get TomTom isochrones', sys.exc_info(), data={"username": username, "orgname": orgname})
|
||||||
|
raise Exception('Error trying to get TomTom isochrones')
|
||||||
|
finally:
|
||||||
|
service_manager.quota_service.increment_total_service_use()
|
||||||
|
$$ LANGUAGE plpythonu SECURITY DEFINER STABLE PARALLEL RESTRICTED;
|
||||||
@@ -0,0 +1,188 @@
|
|||||||
|
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
|
||||||
|
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||||
|
\echo Use "ALTER EXTENSION cdb_dataservices_server UPDATE TO '0.34.0'" to load this file. \quit
|
||||||
|
|
||||||
|
-- HERE goes your code to upgrade/downgrade
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_mapzen_isochrones(
|
||||||
|
username TEXT,
|
||||||
|
orgname TEXT,
|
||||||
|
source geometry(Geometry, 4326),
|
||||||
|
mode TEXT,
|
||||||
|
data_range integer[],
|
||||||
|
options text[])
|
||||||
|
RETURNS SETOF cdb_dataservices_server.isoline AS $$
|
||||||
|
import json
|
||||||
|
from cartodb_services.mapzen import MatrixClient, MapzenIsochrones
|
||||||
|
from cartodb_services.metrics import QuotaService
|
||||||
|
from cartodb_services.tools import Logger,LoggerConfig
|
||||||
|
from cartodb_services.mapzen.types import coordinates_to_polygon
|
||||||
|
|
||||||
|
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||||
|
user_isolines_routing_config = GD["user_isolines_routing_config_{0}".format(username)]
|
||||||
|
|
||||||
|
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
|
||||||
|
logger_config = GD["logger_config"]
|
||||||
|
logger = Logger(logger_config)
|
||||||
|
# -- Check the quota
|
||||||
|
quota_service = QuotaService(user_isolines_routing_config, redis_conn)
|
||||||
|
if not quota_service.check_user_quota():
|
||||||
|
raise Exception('You have reached the limit of your quota')
|
||||||
|
|
||||||
|
try:
|
||||||
|
mapzen_isochrones = MapzenIsochrones(user_isolines_routing_config.mapzen_matrix_api_key,
|
||||||
|
logger, user_isolines_routing_config.mapzen_isochrones_service_params)
|
||||||
|
|
||||||
|
if source:
|
||||||
|
lat = plpy.execute("SELECT ST_Y('%s') AS lat" % source)[0]['lat']
|
||||||
|
lon = plpy.execute("SELECT ST_X('%s') AS lon" % source)[0]['lon']
|
||||||
|
origin = {'lat': lat, 'lon': lon}
|
||||||
|
else:
|
||||||
|
raise Exception('source is NULL')
|
||||||
|
|
||||||
|
resp = mapzen_isochrones.isochrone(origin, mode, data_range)
|
||||||
|
|
||||||
|
if resp:
|
||||||
|
result = []
|
||||||
|
for isochrone in resp:
|
||||||
|
result_polygon = coordinates_to_polygon(isochrone.coordinates)
|
||||||
|
if result_polygon:
|
||||||
|
quota_service.increment_success_service_use()
|
||||||
|
result.append([source, isochrone.duration, result_polygon])
|
||||||
|
else:
|
||||||
|
quota_service.increment_empty_service_use()
|
||||||
|
result.append([source, isochrone.duration, None])
|
||||||
|
quota_service.increment_success_service_use()
|
||||||
|
quota_service.increment_isolines_service_use(len(result))
|
||||||
|
return result
|
||||||
|
else:
|
||||||
|
quota_service.increment_empty_service_use()
|
||||||
|
return []
|
||||||
|
except BaseException as e:
|
||||||
|
import sys
|
||||||
|
quota_service.increment_failed_service_use()
|
||||||
|
logger.error('Error trying to get mapzen isochrones', sys.exc_info(), data={"username": username, "orgname": orgname})
|
||||||
|
raise Exception('Error trying to get mapzen isochrones')
|
||||||
|
finally:
|
||||||
|
quota_service.increment_total_service_use()
|
||||||
|
$$ LANGUAGE plpythonu SECURITY DEFINER STABLE PARALLEL RESTRICTED;
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_mapbox_isochrones(
|
||||||
|
username TEXT,
|
||||||
|
orgname TEXT,
|
||||||
|
source geometry(Geometry, 4326),
|
||||||
|
mode TEXT,
|
||||||
|
data_range integer[],
|
||||||
|
options text[])
|
||||||
|
RETURNS SETOF cdb_dataservices_server.isoline AS $$
|
||||||
|
from cartodb_services.tools import ServiceManager
|
||||||
|
from cartodb_services.mapbox import MapboxMatrixClient, MapboxIsolines
|
||||||
|
from cartodb_services.mapbox.types import TRANSPORT_MODE_TO_MAPBOX
|
||||||
|
from cartodb_services.tools import Coordinate
|
||||||
|
from cartodb_services.tools.coordinates import coordinates_to_polygon
|
||||||
|
from cartodb_services.refactor.service.mapbox_isolines_config import MapboxIsolinesConfigBuilder
|
||||||
|
|
||||||
|
import cartodb_services
|
||||||
|
cartodb_services.init(plpy, GD)
|
||||||
|
|
||||||
|
service_manager = ServiceManager('isolines', MapboxIsolinesConfigBuilder, username, orgname, GD)
|
||||||
|
service_manager.assert_within_limits()
|
||||||
|
|
||||||
|
try:
|
||||||
|
client = MapboxMatrixClient(service_manager.config.mapbox_api_key, service_manager.logger, service_manager.config.service_params)
|
||||||
|
mapbox_isolines = MapboxIsolines(client, service_manager.logger)
|
||||||
|
|
||||||
|
if source:
|
||||||
|
lat = plpy.execute("SELECT ST_Y('%s') AS lat" % source)[0]['lat']
|
||||||
|
lon = plpy.execute("SELECT ST_X('%s') AS lon" % source)[0]['lon']
|
||||||
|
origin = Coordinate(lon,lat)
|
||||||
|
else:
|
||||||
|
raise Exception('source is NULL')
|
||||||
|
|
||||||
|
profile = TRANSPORT_MODE_TO_MAPBOX.get(mode)
|
||||||
|
|
||||||
|
resp = mapbox_isolines.calculate_isochrone(origin, data_range, profile)
|
||||||
|
|
||||||
|
if resp:
|
||||||
|
result = []
|
||||||
|
for isochrone in resp:
|
||||||
|
result_polygon = coordinates_to_polygon(isochrone.coordinates)
|
||||||
|
if result_polygon:
|
||||||
|
service_manager.quota_service.increment_success_service_use()
|
||||||
|
result.append([source, isochrone.duration, result_polygon])
|
||||||
|
else:
|
||||||
|
service_manager.quota_service.increment_empty_service_use()
|
||||||
|
result.append([source, isochrone.duration, None])
|
||||||
|
service_manager.quota_service.increment_success_service_use()
|
||||||
|
service_manager.quota_service.increment_isolines_service_use(len(result))
|
||||||
|
return result
|
||||||
|
else:
|
||||||
|
service_manager.quota_service.increment_empty_service_use()
|
||||||
|
return []
|
||||||
|
except BaseException as e:
|
||||||
|
import sys
|
||||||
|
service_manager.quota_service.increment_failed_service_use()
|
||||||
|
service_manager.logger.error('Error trying to get Mapbox isochrones', sys.exc_info(), data={"username": username, "orgname": orgname})
|
||||||
|
raise Exception('Error trying to get Mapbox isochrones')
|
||||||
|
finally:
|
||||||
|
service_manager.quota_service.increment_total_service_use()
|
||||||
|
$$ LANGUAGE plpythonu SECURITY DEFINER STABLE PARALLEL RESTRICTED;
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_tomtom_isochrones(
|
||||||
|
username TEXT,
|
||||||
|
orgname TEXT,
|
||||||
|
source geometry(Geometry, 4326),
|
||||||
|
mode TEXT,
|
||||||
|
data_range integer[],
|
||||||
|
options text[])
|
||||||
|
RETURNS SETOF cdb_dataservices_server.isoline AS $$
|
||||||
|
from cartodb_services.tools import ServiceManager
|
||||||
|
from cartodb_services.tomtom import TomTomIsolines
|
||||||
|
from cartodb_services.tomtom.types import TRANSPORT_MODE_TO_TOMTOM
|
||||||
|
from cartodb_services.tools import Coordinate
|
||||||
|
from cartodb_services.tools.coordinates import coordinates_to_polygon
|
||||||
|
from cartodb_services.refactor.service.tomtom_isolines_config import TomTomIsolinesConfigBuilder
|
||||||
|
|
||||||
|
import cartodb_services
|
||||||
|
cartodb_services.init(plpy, GD)
|
||||||
|
|
||||||
|
service_manager = ServiceManager('isolines', TomTomIsolinesConfigBuilder, username, orgname, GD)
|
||||||
|
service_manager.assert_within_limits()
|
||||||
|
|
||||||
|
try:
|
||||||
|
tomtom_isolines = TomTomIsolines(service_manager.config.tomtom_api_key, service_manager.logger, service_manager.config.service_params)
|
||||||
|
|
||||||
|
if source:
|
||||||
|
lat = plpy.execute("SELECT ST_Y('%s') AS lat" % source)[0]['lat']
|
||||||
|
lon = plpy.execute("SELECT ST_X('%s') AS lon" % source)[0]['lon']
|
||||||
|
origin = Coordinate(lon,lat)
|
||||||
|
else:
|
||||||
|
raise Exception('source is NULL')
|
||||||
|
|
||||||
|
profile = TRANSPORT_MODE_TO_TOMTOM.get(mode)
|
||||||
|
|
||||||
|
resp = tomtom_isolines.calculate_isochrone(origin, data_range, profile)
|
||||||
|
|
||||||
|
if resp:
|
||||||
|
result = []
|
||||||
|
for isochrone in resp:
|
||||||
|
result_polygon = coordinates_to_polygon(isochrone.coordinates)
|
||||||
|
if result_polygon:
|
||||||
|
service_manager.quota_service.increment_success_service_use()
|
||||||
|
result.append([source, isochrone.duration, result_polygon])
|
||||||
|
else:
|
||||||
|
service_manager.quota_service.increment_empty_service_use()
|
||||||
|
result.append([source, isochrone.duration, None])
|
||||||
|
service_manager.quota_service.increment_success_service_use()
|
||||||
|
service_manager.quota_service.increment_isolines_service_use(len(result))
|
||||||
|
return result
|
||||||
|
else:
|
||||||
|
service_manager.quota_service.increment_empty_service_use()
|
||||||
|
return []
|
||||||
|
except BaseException as e:
|
||||||
|
import sys
|
||||||
|
service_manager.quota_service.increment_failed_service_use()
|
||||||
|
service_manager.logger.error('Error trying to get TomTom isochrones', sys.exc_info(), data={"username": username, "orgname": orgname})
|
||||||
|
raise Exception('Error trying to get TomTom isochrones')
|
||||||
|
finally:
|
||||||
|
service_manager.quota_service.increment_total_service_use()
|
||||||
|
$$ LANGUAGE plpythonu SECURITY DEFINER STABLE PARALLEL RESTRICTED;
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
|
||||||
|
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||||
|
\echo Use "ALTER EXTENSION cdb_dataservices_server UPDATE TO '0.34.1'" to load this file. \quit
|
||||||
|
|
||||||
|
-- HERE goes your code to upgrade/downgrade
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_bulk_geocode_street_point(username TEXT, orgname TEXT, searches jsonb)
|
||||||
|
RETURNS SETOF cdb_dataservices_server.geocoding AS $$
|
||||||
|
from cartodb_services.metrics import metrics
|
||||||
|
from cartodb_services.tools import Logger
|
||||||
|
import json
|
||||||
|
|
||||||
|
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||||
|
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||||
|
|
||||||
|
plpy.execute("SELECT cdb_dataservices_server._get_geocoder_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||||
|
user_geocoder_config = GD["user_geocoder_config_{0}".format(username)]
|
||||||
|
|
||||||
|
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
|
||||||
|
logger_config = GD["logger_config"]
|
||||||
|
logger = Logger(logger_config)
|
||||||
|
|
||||||
|
params = {'username': username, 'orgname': orgname, 'searches': json.loads(searches)}
|
||||||
|
|
||||||
|
with metrics('cdb_bulk_geocode_street_point', user_geocoder_config, logger, params):
|
||||||
|
if user_geocoder_config.google_geocoder:
|
||||||
|
provider_function = "_cdb_bulk_google_geocode_street_point";
|
||||||
|
elif user_geocoder_config.heremaps_geocoder:
|
||||||
|
provider_function = "_cdb_bulk_heremaps_geocode_street_point";
|
||||||
|
elif user_geocoder_config.tomtom_geocoder:
|
||||||
|
provider_function = "_cdb_bulk_tomtom_geocode_street_point";
|
||||||
|
elif user_geocoder_config.mapbox_geocoder:
|
||||||
|
provider_function = "_cdb_bulk_mapbox_geocode_street_point";
|
||||||
|
else:
|
||||||
|
raise Exception('Requested geocoder is not available')
|
||||||
|
|
||||||
|
plan = plpy.prepare("SELECT * FROM cdb_dataservices_server.{}($1, $2, $3); ".format(provider_function), ["text", "text", "jsonb"])
|
||||||
|
return plpy.execute(plan, [username, orgname, searches])
|
||||||
|
|
||||||
|
$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED;
|
||||||
3794
server/extension/old_versions/cdb_dataservices_server--0.34.1.sql
Normal file
3794
server/extension/old_versions/cdb_dataservices_server--0.34.1.sql
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,39 @@
|
|||||||
|
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
|
||||||
|
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||||
|
\echo Use "ALTER EXTENSION cdb_dataservices_server UPDATE TO '0.34.0'" to load this file. \quit
|
||||||
|
|
||||||
|
-- HERE goes your code to upgrade/downgrade
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_bulk_geocode_street_point(username TEXT, orgname TEXT, searches jsonb)
|
||||||
|
RETURNS SETOF cdb_dataservices_server.geocoding AS $$
|
||||||
|
from cartodb_services.metrics import metrics
|
||||||
|
from cartodb_services.tools import Logger
|
||||||
|
import json
|
||||||
|
|
||||||
|
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||||
|
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||||
|
|
||||||
|
plpy.execute("SELECT cdb_dataservices_server._get_geocoder_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||||
|
user_geocoder_config = GD["user_geocoder_config_{0}".format(username)]
|
||||||
|
|
||||||
|
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
|
||||||
|
logger_config = GD["logger_config"]
|
||||||
|
logger = Logger(logger_config)
|
||||||
|
|
||||||
|
params = {'username': username, 'orgname': orgname, 'searches': searches}
|
||||||
|
|
||||||
|
with metrics('cdb_bulk_geocode_street_point', user_geocoder_config, logger, params):
|
||||||
|
if user_geocoder_config.google_geocoder:
|
||||||
|
provider_function = "_cdb_bulk_google_geocode_street_point";
|
||||||
|
elif user_geocoder_config.heremaps_geocoder:
|
||||||
|
provider_function = "_cdb_bulk_heremaps_geocode_street_point";
|
||||||
|
elif user_geocoder_config.tomtom_geocoder:
|
||||||
|
provider_function = "_cdb_bulk_tomtom_geocode_street_point";
|
||||||
|
elif user_geocoder_config.mapbox_geocoder:
|
||||||
|
provider_function = "_cdb_bulk_mapbox_geocode_street_point";
|
||||||
|
else:
|
||||||
|
raise Exception('Requested geocoder is not available')
|
||||||
|
|
||||||
|
plan = plpy.prepare("SELECT * FROM cdb_dataservices_server.{}($1, $2, $3); ".format(provider_function), ["text", "text", "jsonb"])
|
||||||
|
return plpy.execute(plan, [username, orgname, searches])
|
||||||
|
|
||||||
|
$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED;
|
||||||
@@ -0,0 +1,221 @@
|
|||||||
|
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
|
||||||
|
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||||
|
\echo Use "ALTER EXTENSION cdb_dataservices_server UPDATE TO '0.35.0'" to load this file. \quit
|
||||||
|
|
||||||
|
-- HERE goes your code to upgrade/downgrade
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_server._cdb_mapbox_route_with_waypoints(text, text, geometry(Point, 4326)[], text);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_server._cdb_tomtom_route_with_waypoints(text, text, geometry(Point, 4326)[], text);
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_mapbox_route_with_waypoints(
|
||||||
|
username TEXT,
|
||||||
|
orgname TEXT,
|
||||||
|
waypoints geometry(Point, 4326)[],
|
||||||
|
mode TEXT,
|
||||||
|
options text[] DEFAULT ARRAY[]::text[],
|
||||||
|
units text DEFAULT 'kilometers')
|
||||||
|
RETURNS cdb_dataservices_server.simple_route AS $$
|
||||||
|
from cartodb_services.tools import ServiceManager
|
||||||
|
from cartodb_services.mapbox import MapboxRouting
|
||||||
|
from cartodb_services.mapbox.types import TRANSPORT_MODE_TO_MAPBOX
|
||||||
|
from cartodb_services.tools import Coordinate
|
||||||
|
from cartodb_services.tools.polyline import polyline_to_linestring
|
||||||
|
from cartodb_services.tools.normalize import options_to_dict
|
||||||
|
from cartodb_services.refactor.service.mapbox_routing_config import MapboxRoutingConfigBuilder
|
||||||
|
|
||||||
|
import cartodb_services
|
||||||
|
cartodb_services.init(plpy, GD)
|
||||||
|
|
||||||
|
service_manager = ServiceManager('routing', MapboxRoutingConfigBuilder, username, orgname, GD)
|
||||||
|
service_manager.assert_within_limits()
|
||||||
|
|
||||||
|
try:
|
||||||
|
client = MapboxRouting(service_manager.config.mapbox_api_key, service_manager.logger, service_manager.config.service_params)
|
||||||
|
|
||||||
|
if not waypoints or len(waypoints) < 2:
|
||||||
|
service_manager.logger.info("Empty origin or destination")
|
||||||
|
service_manager.quota_service.increment_empty_service_use()
|
||||||
|
return [None, None, None]
|
||||||
|
|
||||||
|
if len(waypoints) > 25:
|
||||||
|
service_manager.logger.info("Too many waypoints (max 25)")
|
||||||
|
service_manager.quota_service.increment_empty_service_use()
|
||||||
|
return [None, None, None]
|
||||||
|
|
||||||
|
waypoint_coords = []
|
||||||
|
for waypoint in waypoints:
|
||||||
|
lat = plpy.execute("SELECT ST_Y('%s') AS lat" % waypoint)[0]['lat']
|
||||||
|
lon = plpy.execute("SELECT ST_X('%s') AS lon" % waypoint)[0]['lon']
|
||||||
|
waypoint_coords.append(Coordinate(lon,lat))
|
||||||
|
|
||||||
|
profile = TRANSPORT_MODE_TO_MAPBOX.get(mode)
|
||||||
|
options_dict = options_to_dict(options)
|
||||||
|
if 'mode_type' in options_dict:
|
||||||
|
plpy.warning('Mapbox provider doesnt support route type parameter')
|
||||||
|
|
||||||
|
resp = client.directions(waypoint_coords, profile)
|
||||||
|
if resp and resp.shape:
|
||||||
|
shape_linestring = polyline_to_linestring(resp.shape)
|
||||||
|
if shape_linestring:
|
||||||
|
service_manager.quota_service.increment_success_service_use()
|
||||||
|
return [shape_linestring, resp.length, int(round(resp.duration))]
|
||||||
|
else:
|
||||||
|
service_manager.quota_service.increment_empty_service_use()
|
||||||
|
return [None, None, None]
|
||||||
|
else:
|
||||||
|
service_manager.quota_service.increment_empty_service_use()
|
||||||
|
return [None, None, None]
|
||||||
|
except BaseException as e:
|
||||||
|
import sys
|
||||||
|
service_manager.quota_service.increment_failed_service_use()
|
||||||
|
service_manager.logger.error('Error trying to calculate Mapbox routing', sys.exc_info(), data={"username": username, "orgname": orgname})
|
||||||
|
raise Exception('Error trying to calculate Mapbox routing')
|
||||||
|
finally:
|
||||||
|
service_manager.quota_service.increment_total_service_use()
|
||||||
|
$$ LANGUAGE plpythonu SECURITY DEFINER STABLE PARALLEL RESTRICTED;
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_tomtom_route_with_waypoints(
|
||||||
|
username TEXT,
|
||||||
|
orgname TEXT,
|
||||||
|
waypoints geometry(Point, 4326)[],
|
||||||
|
mode TEXT,
|
||||||
|
options text[] DEFAULT ARRAY[]::text[],
|
||||||
|
units text DEFAULT 'kilometers')
|
||||||
|
RETURNS cdb_dataservices_server.simple_route AS $$
|
||||||
|
from cartodb_services.tools import ServiceManager
|
||||||
|
from cartodb_services.tomtom import TomTomRouting
|
||||||
|
from cartodb_services.tomtom.types import TRANSPORT_MODE_TO_TOMTOM, DEFAULT_ROUTE_TYPE, MODE_TYPE_TO_TOMTOM
|
||||||
|
from cartodb_services.tools import Coordinate
|
||||||
|
from cartodb_services.tools.polyline import polyline_to_linestring
|
||||||
|
from cartodb_services.tools.normalize import options_to_dict
|
||||||
|
from cartodb_services.refactor.service.tomtom_routing_config import TomTomRoutingConfigBuilder
|
||||||
|
|
||||||
|
import cartodb_services
|
||||||
|
cartodb_services.init(plpy, GD)
|
||||||
|
|
||||||
|
service_manager = ServiceManager('routing', TomTomRoutingConfigBuilder, username, orgname, GD)
|
||||||
|
service_manager.assert_within_limits()
|
||||||
|
|
||||||
|
try:
|
||||||
|
client = TomTomRouting(service_manager.config.tomtom_api_key, service_manager.logger, service_manager.config.service_params)
|
||||||
|
|
||||||
|
if not waypoints or len(waypoints) < 2:
|
||||||
|
service_manager.logger.info("Empty origin or destination")
|
||||||
|
service_manager.quota_service.increment_empty_service_use()
|
||||||
|
return [None, None, None]
|
||||||
|
|
||||||
|
if len(waypoints) > 25:
|
||||||
|
service_manager.logger.info("Too many waypoints (max 25)")
|
||||||
|
service_manager.quota_service.increment_empty_service_use()
|
||||||
|
return [None, None, None]
|
||||||
|
|
||||||
|
waypoint_coords = []
|
||||||
|
for waypoint in waypoints:
|
||||||
|
lat = plpy.execute("SELECT ST_Y('%s') AS lat" % waypoint)[0]['lat']
|
||||||
|
lon = plpy.execute("SELECT ST_X('%s') AS lon" % waypoint)[0]['lon']
|
||||||
|
waypoint_coords.append(Coordinate(lon,lat))
|
||||||
|
|
||||||
|
profile = TRANSPORT_MODE_TO_TOMTOM.get(mode)
|
||||||
|
route_type = DEFAULT_ROUTE_TYPE
|
||||||
|
options_dict = options_to_dict(options)
|
||||||
|
if 'mode_type' in options_dict:
|
||||||
|
route_type = MODE_TYPE_TO_TOMTOM.get(options_dict['mode_type'])
|
||||||
|
|
||||||
|
resp = client.directions(waypoint_coords, profile=profile, route_type=route_type)
|
||||||
|
if resp and resp.shape:
|
||||||
|
shape_linestring = polyline_to_linestring(resp.shape)
|
||||||
|
if shape_linestring:
|
||||||
|
service_manager.quota_service.increment_success_service_use()
|
||||||
|
return [shape_linestring, resp.length, int(round(resp.duration))]
|
||||||
|
else:
|
||||||
|
service_manager.quota_service.increment_empty_service_use()
|
||||||
|
return [None, None, None]
|
||||||
|
else:
|
||||||
|
service_manager.quota_service.increment_empty_service_use()
|
||||||
|
return [None, None, None]
|
||||||
|
except BaseException as e:
|
||||||
|
import sys
|
||||||
|
service_manager.quota_service.increment_failed_service_use()
|
||||||
|
service_manager.logger.error('Error trying to calculate TomTom routing', sys.exc_info(), data={"username": username, "orgname": orgname})
|
||||||
|
raise Exception('Error trying to calculate TomTom routing')
|
||||||
|
finally:
|
||||||
|
service_manager.quota_service.increment_total_service_use()
|
||||||
|
$$ LANGUAGE plpythonu SECURITY DEFINER STABLE PARALLEL RESTRICTED;
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_route_point_to_point(
|
||||||
|
username TEXT,
|
||||||
|
orgname TEXT,
|
||||||
|
origin geometry(Point, 4326),
|
||||||
|
destination geometry(Point, 4326),
|
||||||
|
mode TEXT,
|
||||||
|
options text[] DEFAULT ARRAY[]::text[],
|
||||||
|
units text DEFAULT 'kilometers')
|
||||||
|
RETURNS cdb_dataservices_server.simple_route AS $$
|
||||||
|
from cartodb_services.metrics import metrics
|
||||||
|
from cartodb_services.tools import Logger
|
||||||
|
|
||||||
|
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||||
|
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||||
|
plpy.execute("SELECT cdb_dataservices_server._get_routing_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||||
|
user_routing_config = GD["user_routing_config_{0}".format(username)]
|
||||||
|
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
|
||||||
|
logger_config = GD["logger_config"]
|
||||||
|
logger = Logger(logger_config)
|
||||||
|
|
||||||
|
params = {'username': username, 'orgname': orgname, 'origin': origin, 'destination': destination, 'mode': mode, 'options': options, 'units': units}
|
||||||
|
|
||||||
|
with metrics('cdb_route_with_point', user_routing_config, logger, params):
|
||||||
|
waypoints = [origin, destination]
|
||||||
|
|
||||||
|
if user_routing_config.mapzen_provider:
|
||||||
|
mapzen_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._cdb_mapzen_route_with_waypoints($1, $2, $3, $4, $5, $6) as route;", ["text", "text", "geometry(Point, 4326)[]", "text", "text[]", "text"])
|
||||||
|
result = plpy.execute(mapzen_plan, [username, orgname, waypoints, mode, options, units])
|
||||||
|
return [result[0]['shape'],result[0]['length'], result[0]['duration']]
|
||||||
|
elif user_routing_config.mapbox_provider:
|
||||||
|
mapbox_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._cdb_mapbox_route_with_waypoints($1, $2, $3, $4, $5, $6) as route;", ["text", "text", "geometry(Point, 4326)[]", "text", "text[]", "text"])
|
||||||
|
result = plpy.execute(mapbox_plan, [username, orgname, waypoints, mode, options, units])
|
||||||
|
return [result[0]['shape'],result[0]['length'], result[0]['duration']]
|
||||||
|
elif user_routing_config.tomtom_provider:
|
||||||
|
tomtom_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._cdb_tomtom_route_with_waypoints($1, $2, $3, $4, $5, $6) as route;", ["text", "text", "geometry(Point, 4326)[]", "text", "text[]", "text"])
|
||||||
|
result = plpy.execute(tomtom_plan, [username, orgname, waypoints, mode, options, units])
|
||||||
|
return [result[0]['shape'],result[0]['length'], result[0]['duration']]
|
||||||
|
else:
|
||||||
|
raise Exception('Requested routing method is not available')
|
||||||
|
$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED;
|
||||||
|
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_route_with_waypoints(
|
||||||
|
username TEXT,
|
||||||
|
orgname TEXT,
|
||||||
|
waypoints geometry(Point, 4326)[],
|
||||||
|
mode TEXT,
|
||||||
|
options text[] DEFAULT ARRAY[]::text[],
|
||||||
|
units text DEFAULT 'kilometers')
|
||||||
|
RETURNS cdb_dataservices_server.simple_route AS $$
|
||||||
|
from cartodb_services.metrics import metrics
|
||||||
|
from cartodb_services.tools import Logger
|
||||||
|
|
||||||
|
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||||
|
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||||
|
plpy.execute("SELECT cdb_dataservices_server._get_routing_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||||
|
user_routing_config = GD["user_routing_config_{0}".format(username)]
|
||||||
|
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
|
||||||
|
logger_config = GD["logger_config"]
|
||||||
|
logger = Logger(logger_config)
|
||||||
|
|
||||||
|
params = {'username': username, 'orgname': orgname, 'waypoints': waypoints, 'mode': mode, 'options': options, 'units': units}
|
||||||
|
|
||||||
|
with metrics('cdb_route_with_waypoints', user_routing_config, logger, params):
|
||||||
|
if user_routing_config.mapzen_provider:
|
||||||
|
mapzen_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._cdb_mapzen_route_with_waypoints($1, $2, $3, $4, $5, $6) as route;", ["text", "text", "geometry(Point, 4326)[]", "text", "text[]", "text"])
|
||||||
|
result = plpy.execute(mapzen_plan, [username, orgname, waypoints, mode, options, units])
|
||||||
|
return [result[0]['shape'],result[0]['length'], result[0]['duration']]
|
||||||
|
elif user_routing_config.mapbox_provider:
|
||||||
|
mapbox_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._cdb_mapbox_route_with_waypoints($1, $2, $3, $4, $5, $6) as route;", ["text", "text", "geometry(Point, 4326)[]", "text", "text[]", "text"])
|
||||||
|
result = plpy.execute(mapbox_plan, [username, orgname, waypoints, mode, options, units])
|
||||||
|
return [result[0]['shape'],result[0]['length'], result[0]['duration']]
|
||||||
|
elif user_routing_config.tomtom_provider:
|
||||||
|
tomtom_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._cdb_tomtom_route_with_waypoints($1, $2, $3, $4, $5, $6) as route;", ["text", "text", "geometry(Point, 4326)[]", "text", "text[]", "text"])
|
||||||
|
result = plpy.execute(tomtom_plan, [username, orgname, waypoints, mode, options, units])
|
||||||
|
return [result[0]['shape'],result[0]['length'], result[0]['duration']]
|
||||||
|
else:
|
||||||
|
raise Exception('Requested routing method is not available')
|
||||||
|
$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED;
|
||||||
3795
server/extension/old_versions/cdb_dataservices_server--0.34.2.sql
Normal file
3795
server/extension/old_versions/cdb_dataservices_server--0.34.2.sql
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,209 @@
|
|||||||
|
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
|
||||||
|
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||||
|
\echo Use "ALTER EXTENSION cdb_dataservices_server UPDATE TO '0.34.2'" to load this file. \quit
|
||||||
|
|
||||||
|
-- HERE goes your code to upgrade/downgrade
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_server._cdb_mapbox_route_with_waypoints(text, text, geometry(Point, 4326)[], text, text[], text);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_server._cdb_tomtom_route_with_waypoints(text, text, geometry(Point, 4326)[], text, text[], text);
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_mapbox_route_with_waypoints(
|
||||||
|
username TEXT,
|
||||||
|
orgname TEXT,
|
||||||
|
waypoints geometry(Point, 4326)[],
|
||||||
|
mode TEXT)
|
||||||
|
RETURNS cdb_dataservices_server.simple_route AS $$
|
||||||
|
from cartodb_services.tools import ServiceManager
|
||||||
|
from cartodb_services.mapbox import MapboxRouting
|
||||||
|
from cartodb_services.mapbox.types import TRANSPORT_MODE_TO_MAPBOX
|
||||||
|
from cartodb_services.tools import Coordinate
|
||||||
|
from cartodb_services.tools.polyline import polyline_to_linestring
|
||||||
|
from cartodb_services.refactor.service.mapbox_routing_config import MapboxRoutingConfigBuilder
|
||||||
|
|
||||||
|
import cartodb_services
|
||||||
|
cartodb_services.init(plpy, GD)
|
||||||
|
|
||||||
|
service_manager = ServiceManager('routing', MapboxRoutingConfigBuilder, username, orgname, GD)
|
||||||
|
service_manager.assert_within_limits()
|
||||||
|
|
||||||
|
try:
|
||||||
|
client = MapboxRouting(service_manager.config.mapbox_api_key, service_manager.logger, service_manager.config.service_params)
|
||||||
|
|
||||||
|
if not waypoints or len(waypoints) < 2:
|
||||||
|
service_manager.logger.info("Empty origin or destination")
|
||||||
|
service_manager.quota_service.increment_empty_service_use()
|
||||||
|
return [None, None, None]
|
||||||
|
|
||||||
|
if len(waypoints) > 25:
|
||||||
|
service_manager.logger.info("Too many waypoints (max 25)")
|
||||||
|
service_manager.quota_service.increment_empty_service_use()
|
||||||
|
return [None, None, None]
|
||||||
|
|
||||||
|
waypoint_coords = []
|
||||||
|
for waypoint in waypoints:
|
||||||
|
lat = plpy.execute("SELECT ST_Y('%s') AS lat" % waypoint)[0]['lat']
|
||||||
|
lon = plpy.execute("SELECT ST_X('%s') AS lon" % waypoint)[0]['lon']
|
||||||
|
waypoint_coords.append(Coordinate(lon,lat))
|
||||||
|
|
||||||
|
profile = TRANSPORT_MODE_TO_MAPBOX.get(mode)
|
||||||
|
|
||||||
|
resp = client.directions(waypoint_coords, profile)
|
||||||
|
if resp and resp.shape:
|
||||||
|
shape_linestring = polyline_to_linestring(resp.shape)
|
||||||
|
if shape_linestring:
|
||||||
|
service_manager.quota_service.increment_success_service_use()
|
||||||
|
return [shape_linestring, resp.length, int(round(resp.duration))]
|
||||||
|
else:
|
||||||
|
service_manager.quota_service.increment_empty_service_use()
|
||||||
|
return [None, None, None]
|
||||||
|
else:
|
||||||
|
service_manager.quota_service.increment_empty_service_use()
|
||||||
|
return [None, None, None]
|
||||||
|
except BaseException as e:
|
||||||
|
import sys
|
||||||
|
service_manager.quota_service.increment_failed_service_use()
|
||||||
|
service_manager.logger.error('Error trying to calculate Mapbox routing', sys.exc_info(), data={"username": username, "orgname": orgname})
|
||||||
|
raise Exception('Error trying to calculate Mapbox routing')
|
||||||
|
finally:
|
||||||
|
service_manager.quota_service.increment_total_service_use()
|
||||||
|
$$ LANGUAGE plpythonu SECURITY DEFINER STABLE PARALLEL RESTRICTED;
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_tomtom_route_with_waypoints(
|
||||||
|
username TEXT,
|
||||||
|
orgname TEXT,
|
||||||
|
waypoints geometry(Point, 4326)[],
|
||||||
|
mode TEXT)
|
||||||
|
RETURNS cdb_dataservices_server.simple_route AS $$
|
||||||
|
from cartodb_services.tools import ServiceManager
|
||||||
|
from cartodb_services.tomtom import TomTomRouting
|
||||||
|
from cartodb_services.tomtom.types import TRANSPORT_MODE_TO_TOMTOM
|
||||||
|
from cartodb_services.tools import Coordinate
|
||||||
|
from cartodb_services.tools.polyline import polyline_to_linestring
|
||||||
|
from cartodb_services.refactor.service.tomtom_routing_config import TomTomRoutingConfigBuilder
|
||||||
|
|
||||||
|
import cartodb_services
|
||||||
|
cartodb_services.init(plpy, GD)
|
||||||
|
|
||||||
|
service_manager = ServiceManager('routing', TomTomRoutingConfigBuilder, username, orgname, GD)
|
||||||
|
service_manager.assert_within_limits()
|
||||||
|
|
||||||
|
try:
|
||||||
|
client = TomTomRouting(service_manager.config.tomtom_api_key, service_manager.logger, service_manager.config.service_params)
|
||||||
|
|
||||||
|
if not waypoints or len(waypoints) < 2:
|
||||||
|
service_manager.logger.info("Empty origin or destination")
|
||||||
|
service_manager.quota_service.increment_empty_service_use()
|
||||||
|
return [None, None, None]
|
||||||
|
|
||||||
|
if len(waypoints) > 25:
|
||||||
|
service_manager.logger.info("Too many waypoints (max 25)")
|
||||||
|
service_manager.quota_service.increment_empty_service_use()
|
||||||
|
return [None, None, None]
|
||||||
|
|
||||||
|
waypoint_coords = []
|
||||||
|
for waypoint in waypoints:
|
||||||
|
lat = plpy.execute("SELECT ST_Y('%s') AS lat" % waypoint)[0]['lat']
|
||||||
|
lon = plpy.execute("SELECT ST_X('%s') AS lon" % waypoint)[0]['lon']
|
||||||
|
waypoint_coords.append(Coordinate(lon,lat))
|
||||||
|
|
||||||
|
profile = TRANSPORT_MODE_TO_TOMTOM.get(mode)
|
||||||
|
|
||||||
|
resp = client.directions(waypoint_coords, profile)
|
||||||
|
if resp and resp.shape:
|
||||||
|
shape_linestring = polyline_to_linestring(resp.shape)
|
||||||
|
if shape_linestring:
|
||||||
|
service_manager.quota_service.increment_success_service_use()
|
||||||
|
return [shape_linestring, resp.length, int(round(resp.duration))]
|
||||||
|
else:
|
||||||
|
service_manager.quota_service.increment_empty_service_use()
|
||||||
|
return [None, None, None]
|
||||||
|
else:
|
||||||
|
service_manager.quota_service.increment_empty_service_use()
|
||||||
|
return [None, None, None]
|
||||||
|
except BaseException as e:
|
||||||
|
import sys
|
||||||
|
service_manager.quota_service.increment_failed_service_use()
|
||||||
|
service_manager.logger.error('Error trying to calculate TomTom routing', sys.exc_info(), data={"username": username, "orgname": orgname})
|
||||||
|
raise Exception('Error trying to calculate TomTom routing')
|
||||||
|
finally:
|
||||||
|
service_manager.quota_service.increment_total_service_use()
|
||||||
|
$$ LANGUAGE plpythonu SECURITY DEFINER STABLE PARALLEL RESTRICTED;
|
||||||
|
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_route_point_to_point(
|
||||||
|
username TEXT,
|
||||||
|
orgname TEXT,
|
||||||
|
origin geometry(Point, 4326),
|
||||||
|
destination geometry(Point, 4326),
|
||||||
|
mode TEXT,
|
||||||
|
options text[] DEFAULT ARRAY[]::text[],
|
||||||
|
units text DEFAULT 'kilometers')
|
||||||
|
RETURNS cdb_dataservices_server.simple_route AS $$
|
||||||
|
from cartodb_services.metrics import metrics
|
||||||
|
from cartodb_services.tools import Logger
|
||||||
|
|
||||||
|
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||||
|
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||||
|
plpy.execute("SELECT cdb_dataservices_server._get_routing_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||||
|
user_routing_config = GD["user_routing_config_{0}".format(username)]
|
||||||
|
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
|
||||||
|
logger_config = GD["logger_config"]
|
||||||
|
logger = Logger(logger_config)
|
||||||
|
|
||||||
|
params = {'username': username, 'orgname': orgname, 'origin': origin, 'destination': destination, 'mode': mode, 'options': options, 'units': units}
|
||||||
|
|
||||||
|
with metrics('cdb_route_with_point', user_routing_config, logger, params):
|
||||||
|
waypoints = [origin, destination]
|
||||||
|
|
||||||
|
if user_routing_config.mapzen_provider:
|
||||||
|
mapzen_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._cdb_mapzen_route_with_waypoints($1, $2, $3, $4) as route;", ["text", "text", "geometry(Point, 4326)[]", "text"])
|
||||||
|
result = plpy.execute(mapzen_plan, [username, orgname, waypoints, mode])
|
||||||
|
return [result[0]['shape'],result[0]['length'], result[0]['duration']]
|
||||||
|
elif user_routing_config.mapbox_provider:
|
||||||
|
mapbox_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._cdb_mapbox_route_with_waypoints($1, $2, $3, $4) as route;", ["text", "text", "geometry(Point, 4326)[]", "text"])
|
||||||
|
result = plpy.execute(mapbox_plan, [username, orgname, waypoints, mode])
|
||||||
|
return [result[0]['shape'],result[0]['length'], result[0]['duration']]
|
||||||
|
elif user_routing_config.tomtom_provider:
|
||||||
|
tomtom_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._cdb_tomtom_route_with_waypoints($1, $2, $3, $4) as route;", ["text", "text", "geometry(Point, 4326)[]", "text"])
|
||||||
|
result = plpy.execute(tomtom_plan, [username, orgname, waypoints, mode])
|
||||||
|
return [result[0]['shape'],result[0]['length'], result[0]['duration']]
|
||||||
|
else:
|
||||||
|
raise Exception('Requested routing method is not available')
|
||||||
|
$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED;
|
||||||
|
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_route_with_waypoints(
|
||||||
|
username TEXT,
|
||||||
|
orgname TEXT,
|
||||||
|
waypoints geometry(Point, 4326)[],
|
||||||
|
mode TEXT,
|
||||||
|
options text[] DEFAULT ARRAY[]::text[],
|
||||||
|
units text DEFAULT 'kilometers')
|
||||||
|
RETURNS cdb_dataservices_server.simple_route AS $$
|
||||||
|
from cartodb_services.metrics import metrics
|
||||||
|
from cartodb_services.tools import Logger
|
||||||
|
|
||||||
|
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||||
|
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||||
|
plpy.execute("SELECT cdb_dataservices_server._get_routing_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||||
|
user_routing_config = GD["user_routing_config_{0}".format(username)]
|
||||||
|
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
|
||||||
|
logger_config = GD["logger_config"]
|
||||||
|
logger = Logger(logger_config)
|
||||||
|
|
||||||
|
params = {'username': username, 'orgname': orgname, 'waypoints': waypoints, 'mode': mode, 'options': options, 'units': units}
|
||||||
|
|
||||||
|
with metrics('cdb_route_with_waypoints', user_routing_config, logger, params):
|
||||||
|
if user_routing_config.mapzen_provider:
|
||||||
|
mapzen_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._cdb_mapzen_route_with_waypoints($1, $2, $3, $4) as route;", ["text", "text", "geometry(Point, 4326)[]", "text"])
|
||||||
|
result = plpy.execute(mapzen_plan, [username, orgname, waypoints, mode])
|
||||||
|
return [result[0]['shape'],result[0]['length'], result[0]['duration']]
|
||||||
|
elif user_routing_config.mapbox_provider:
|
||||||
|
mapbox_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._cdb_mapbox_route_with_waypoints($1, $2, $3, $4) as route;", ["text", "text", "geometry(Point, 4326)[]", "text"])
|
||||||
|
result = plpy.execute(mapbox_plan, [username, orgname, waypoints, mode])
|
||||||
|
return [result[0]['shape'],result[0]['length'], result[0]['duration']]
|
||||||
|
elif user_routing_config.tomtom_provider:
|
||||||
|
tomtom_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._cdb_tomtom_route_with_waypoints($1, $2, $3, $4) as route;", ["text", "text", "geometry(Point, 4326)[]", "text"])
|
||||||
|
result = plpy.execute(tomtom_plan, [username, orgname, waypoints, mode])
|
||||||
|
return [result[0]['shape'],result[0]['length'], result[0]['duration']]
|
||||||
|
else:
|
||||||
|
raise Exception('Requested routing method is not available')
|
||||||
|
$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED;
|
||||||
3808
server/extension/old_versions/cdb_dataservices_server--0.35.0.sql
Normal file
3808
server/extension/old_versions/cdb_dataservices_server--0.35.0.sql
Normal file
File diff suppressed because it is too large
Load Diff
@@ -8,13 +8,16 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_mapbox_route_with_waypoi
|
|||||||
username TEXT,
|
username TEXT,
|
||||||
orgname TEXT,
|
orgname TEXT,
|
||||||
waypoints geometry(Point, 4326)[],
|
waypoints geometry(Point, 4326)[],
|
||||||
mode TEXT)
|
mode TEXT,
|
||||||
|
options text[] DEFAULT ARRAY[]::text[],
|
||||||
|
units text DEFAULT 'kilometers')
|
||||||
RETURNS cdb_dataservices_server.simple_route AS $$
|
RETURNS cdb_dataservices_server.simple_route AS $$
|
||||||
from cartodb_services.tools import ServiceManager
|
from cartodb_services.tools import ServiceManager
|
||||||
from cartodb_services.mapbox import MapboxRouting
|
from cartodb_services.mapbox import MapboxRouting
|
||||||
from cartodb_services.mapbox.types import TRANSPORT_MODE_TO_MAPBOX
|
from cartodb_services.mapbox.types import TRANSPORT_MODE_TO_MAPBOX
|
||||||
from cartodb_services.tools import Coordinate
|
from cartodb_services.tools import Coordinate
|
||||||
from cartodb_services.tools.polyline import polyline_to_linestring
|
from cartodb_services.tools.polyline import polyline_to_linestring
|
||||||
|
from cartodb_services.tools.normalize import options_to_dict
|
||||||
from cartodb_services.refactor.service.mapbox_routing_config import MapboxRoutingConfigBuilder
|
from cartodb_services.refactor.service.mapbox_routing_config import MapboxRoutingConfigBuilder
|
||||||
|
|
||||||
import cartodb_services
|
import cartodb_services
|
||||||
@@ -43,6 +46,9 @@ RETURNS cdb_dataservices_server.simple_route AS $$
|
|||||||
waypoint_coords.append(Coordinate(lon,lat))
|
waypoint_coords.append(Coordinate(lon,lat))
|
||||||
|
|
||||||
profile = TRANSPORT_MODE_TO_MAPBOX.get(mode)
|
profile = TRANSPORT_MODE_TO_MAPBOX.get(mode)
|
||||||
|
options_dict = options_to_dict(options)
|
||||||
|
if 'mode_type' in options_dict:
|
||||||
|
plpy.warning('Mapbox provider doesnt support route type parameter')
|
||||||
|
|
||||||
resp = client.directions(waypoint_coords, profile)
|
resp = client.directions(waypoint_coords, profile)
|
||||||
if resp and resp.shape:
|
if resp and resp.shape:
|
||||||
@@ -69,13 +75,16 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_tomtom_route_with_waypoi
|
|||||||
username TEXT,
|
username TEXT,
|
||||||
orgname TEXT,
|
orgname TEXT,
|
||||||
waypoints geometry(Point, 4326)[],
|
waypoints geometry(Point, 4326)[],
|
||||||
mode TEXT)
|
mode TEXT,
|
||||||
|
options text[] DEFAULT ARRAY[]::text[],
|
||||||
|
units text DEFAULT 'kilometers')
|
||||||
RETURNS cdb_dataservices_server.simple_route AS $$
|
RETURNS cdb_dataservices_server.simple_route AS $$
|
||||||
from cartodb_services.tools import ServiceManager
|
from cartodb_services.tools import ServiceManager
|
||||||
from cartodb_services.tomtom import TomTomRouting
|
from cartodb_services.tomtom import TomTomRouting
|
||||||
from cartodb_services.tomtom.types import TRANSPORT_MODE_TO_TOMTOM
|
from cartodb_services.tomtom.types import TRANSPORT_MODE_TO_TOMTOM, DEFAULT_ROUTE_TYPE, MODE_TYPE_TO_TOMTOM
|
||||||
from cartodb_services.tools import Coordinate
|
from cartodb_services.tools import Coordinate
|
||||||
from cartodb_services.tools.polyline import polyline_to_linestring
|
from cartodb_services.tools.polyline import polyline_to_linestring
|
||||||
|
from cartodb_services.tools.normalize import options_to_dict
|
||||||
from cartodb_services.refactor.service.tomtom_routing_config import TomTomRoutingConfigBuilder
|
from cartodb_services.refactor.service.tomtom_routing_config import TomTomRoutingConfigBuilder
|
||||||
|
|
||||||
import cartodb_services
|
import cartodb_services
|
||||||
@@ -104,8 +113,12 @@ RETURNS cdb_dataservices_server.simple_route AS $$
|
|||||||
waypoint_coords.append(Coordinate(lon,lat))
|
waypoint_coords.append(Coordinate(lon,lat))
|
||||||
|
|
||||||
profile = TRANSPORT_MODE_TO_TOMTOM.get(mode)
|
profile = TRANSPORT_MODE_TO_TOMTOM.get(mode)
|
||||||
|
route_type = DEFAULT_ROUTE_TYPE
|
||||||
|
options_dict = options_to_dict(options)
|
||||||
|
if 'mode_type' in options_dict:
|
||||||
|
route_type = MODE_TYPE_TO_TOMTOM.get(options_dict['mode_type'])
|
||||||
|
|
||||||
resp = client.directions(waypoint_coords, profile)
|
resp = client.directions(waypoint_coords, profile=profile, route_type=route_type)
|
||||||
if resp and resp.shape:
|
if resp and resp.shape:
|
||||||
shape_linestring = polyline_to_linestring(resp.shape)
|
shape_linestring = polyline_to_linestring(resp.shape)
|
||||||
if shape_linestring:
|
if shape_linestring:
|
||||||
|
|||||||
@@ -24,16 +24,16 @@ RETURNS cdb_dataservices_server.simple_route AS $$
|
|||||||
waypoints = [origin, destination]
|
waypoints = [origin, destination]
|
||||||
|
|
||||||
if user_routing_config.mapzen_provider:
|
if user_routing_config.mapzen_provider:
|
||||||
mapzen_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._cdb_mapzen_route_with_waypoints($1, $2, $3, $4) as route;", ["text", "text", "geometry(Point, 4326)[]", "text"])
|
mapzen_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._cdb_mapzen_route_with_waypoints($1, $2, $3, $4, $5, $6) as route;", ["text", "text", "geometry(Point, 4326)[]", "text", "text[]", "text"])
|
||||||
result = plpy.execute(mapzen_plan, [username, orgname, waypoints, mode])
|
result = plpy.execute(mapzen_plan, [username, orgname, waypoints, mode, options, units])
|
||||||
return [result[0]['shape'],result[0]['length'], result[0]['duration']]
|
return [result[0]['shape'],result[0]['length'], result[0]['duration']]
|
||||||
elif user_routing_config.mapbox_provider:
|
elif user_routing_config.mapbox_provider:
|
||||||
mapbox_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._cdb_mapbox_route_with_waypoints($1, $2, $3, $4) as route;", ["text", "text", "geometry(Point, 4326)[]", "text"])
|
mapbox_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._cdb_mapbox_route_with_waypoints($1, $2, $3, $4, $5, $6) as route;", ["text", "text", "geometry(Point, 4326)[]", "text", "text[]", "text"])
|
||||||
result = plpy.execute(mapbox_plan, [username, orgname, waypoints, mode])
|
result = plpy.execute(mapbox_plan, [username, orgname, waypoints, mode, options, units])
|
||||||
return [result[0]['shape'],result[0]['length'], result[0]['duration']]
|
return [result[0]['shape'],result[0]['length'], result[0]['duration']]
|
||||||
elif user_routing_config.tomtom_provider:
|
elif user_routing_config.tomtom_provider:
|
||||||
tomtom_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._cdb_tomtom_route_with_waypoints($1, $2, $3, $4) as route;", ["text", "text", "geometry(Point, 4326)[]", "text"])
|
tomtom_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._cdb_tomtom_route_with_waypoints($1, $2, $3, $4, $5, $6) as route;", ["text", "text", "geometry(Point, 4326)[]", "text", "text[]", "text"])
|
||||||
result = plpy.execute(tomtom_plan, [username, orgname, waypoints, mode])
|
result = plpy.execute(tomtom_plan, [username, orgname, waypoints, mode, options, units])
|
||||||
return [result[0]['shape'],result[0]['length'], result[0]['duration']]
|
return [result[0]['shape'],result[0]['length'], result[0]['duration']]
|
||||||
else:
|
else:
|
||||||
raise Exception('Requested routing method is not available')
|
raise Exception('Requested routing method is not available')
|
||||||
@@ -63,16 +63,16 @@ RETURNS cdb_dataservices_server.simple_route AS $$
|
|||||||
|
|
||||||
with metrics('cdb_route_with_waypoints', user_routing_config, logger, params):
|
with metrics('cdb_route_with_waypoints', user_routing_config, logger, params):
|
||||||
if user_routing_config.mapzen_provider:
|
if user_routing_config.mapzen_provider:
|
||||||
mapzen_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._cdb_mapzen_route_with_waypoints($1, $2, $3, $4) as route;", ["text", "text", "geometry(Point, 4326)[]", "text"])
|
mapzen_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._cdb_mapzen_route_with_waypoints($1, $2, $3, $4, $5, $6) as route;", ["text", "text", "geometry(Point, 4326)[]", "text", "text[]", "text"])
|
||||||
result = plpy.execute(mapzen_plan, [username, orgname, waypoints, mode])
|
result = plpy.execute(mapzen_plan, [username, orgname, waypoints, mode, options, units])
|
||||||
return [result[0]['shape'],result[0]['length'], result[0]['duration']]
|
return [result[0]['shape'],result[0]['length'], result[0]['duration']]
|
||||||
elif user_routing_config.mapbox_provider:
|
elif user_routing_config.mapbox_provider:
|
||||||
mapbox_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._cdb_mapbox_route_with_waypoints($1, $2, $3, $4) as route;", ["text", "text", "geometry(Point, 4326)[]", "text"])
|
mapbox_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._cdb_mapbox_route_with_waypoints($1, $2, $3, $4, $5, $6) as route;", ["text", "text", "geometry(Point, 4326)[]", "text", "text[]", "text"])
|
||||||
result = plpy.execute(mapbox_plan, [username, orgname, waypoints, mode])
|
result = plpy.execute(mapbox_plan, [username, orgname, waypoints, mode, options, units])
|
||||||
return [result[0]['shape'],result[0]['length'], result[0]['duration']]
|
return [result[0]['shape'],result[0]['length'], result[0]['duration']]
|
||||||
elif user_routing_config.tomtom_provider:
|
elif user_routing_config.tomtom_provider:
|
||||||
tomtom_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._cdb_tomtom_route_with_waypoints($1, $2, $3, $4) as route;", ["text", "text", "geometry(Point, 4326)[]", "text"])
|
tomtom_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._cdb_tomtom_route_with_waypoints($1, $2, $3, $4, $5, $6) as route;", ["text", "text", "geometry(Point, 4326)[]", "text", "text[]", "text"])
|
||||||
result = plpy.execute(tomtom_plan, [username, orgname, waypoints, mode])
|
result = plpy.execute(tomtom_plan, [username, orgname, waypoints, mode, options, units])
|
||||||
return [result[0]['shape'],result[0]['length'], result[0]['duration']]
|
return [result[0]['shape'],result[0]['length'], result[0]['duration']]
|
||||||
else:
|
else:
|
||||||
raise Exception('Requested routing method is not available')
|
raise Exception('Requested routing method is not available')
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
-- TODO: could cartodb_id be replaced by rowid, maybe needing extra care for offset?
|
-- TODO: could cartodb_id be replaced by rowid, maybe needing extra care for offset?
|
||||||
CREATE TYPE cdb_dataservices_server.geocoding AS (
|
CREATE TYPE cdb_dataservices_server.geocoding AS (
|
||||||
cartodb_id integer,
|
cartodb_id integer,
|
||||||
the_geom geometry(Multipolygon,4326),
|
the_geom geometry(Point,4326),
|
||||||
metadata jsonb
|
metadata jsonb
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -9,6 +9,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_bulk_geocode_street_poin
|
|||||||
RETURNS SETOF cdb_dataservices_server.geocoding AS $$
|
RETURNS SETOF cdb_dataservices_server.geocoding AS $$
|
||||||
from cartodb_services.metrics import metrics
|
from cartodb_services.metrics import metrics
|
||||||
from cartodb_services.tools import Logger
|
from cartodb_services.tools import Logger
|
||||||
|
import json
|
||||||
|
|
||||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||||
@@ -20,7 +21,7 @@ RETURNS SETOF cdb_dataservices_server.geocoding AS $$
|
|||||||
logger_config = GD["logger_config"]
|
logger_config = GD["logger_config"]
|
||||||
logger = Logger(logger_config)
|
logger = Logger(logger_config)
|
||||||
|
|
||||||
params = {'username': username, 'orgname': orgname, 'searches': searches}
|
params = {'username': username, 'orgname': orgname, 'searches': json.loads(searches)}
|
||||||
|
|
||||||
with metrics('cdb_bulk_geocode_street_point', user_geocoder_config, logger, params):
|
with metrics('cdb_bulk_geocode_street_point', user_geocoder_config, logger, params):
|
||||||
if user_geocoder_config.google_geocoder:
|
if user_geocoder_config.google_geocoder:
|
||||||
|
|||||||
@@ -295,10 +295,8 @@ RETURNS SETOF cdb_dataservices_server.isoline AS $$
|
|||||||
for isochrone in resp:
|
for isochrone in resp:
|
||||||
result_polygon = coordinates_to_polygon(isochrone.coordinates)
|
result_polygon = coordinates_to_polygon(isochrone.coordinates)
|
||||||
if result_polygon:
|
if result_polygon:
|
||||||
quota_service.increment_success_service_use()
|
|
||||||
result.append([source, isochrone.duration, result_polygon])
|
result.append([source, isochrone.duration, result_polygon])
|
||||||
else:
|
else:
|
||||||
quota_service.increment_empty_service_use()
|
|
||||||
result.append([source, isochrone.duration, None])
|
result.append([source, isochrone.duration, None])
|
||||||
quota_service.increment_success_service_use()
|
quota_service.increment_success_service_use()
|
||||||
quota_service.increment_isolines_service_use(len(result))
|
quota_service.increment_isolines_service_use(len(result))
|
||||||
@@ -356,10 +354,8 @@ RETURNS SETOF cdb_dataservices_server.isoline AS $$
|
|||||||
for isochrone in resp:
|
for isochrone in resp:
|
||||||
result_polygon = coordinates_to_polygon(isochrone.coordinates)
|
result_polygon = coordinates_to_polygon(isochrone.coordinates)
|
||||||
if result_polygon:
|
if result_polygon:
|
||||||
service_manager.quota_service.increment_success_service_use()
|
|
||||||
result.append([source, isochrone.duration, result_polygon])
|
result.append([source, isochrone.duration, result_polygon])
|
||||||
else:
|
else:
|
||||||
service_manager.quota_service.increment_empty_service_use()
|
|
||||||
result.append([source, isochrone.duration, None])
|
result.append([source, isochrone.duration, None])
|
||||||
service_manager.quota_service.increment_success_service_use()
|
service_manager.quota_service.increment_success_service_use()
|
||||||
service_manager.quota_service.increment_isolines_service_use(len(result))
|
service_manager.quota_service.increment_isolines_service_use(len(result))
|
||||||
@@ -416,10 +412,8 @@ RETURNS SETOF cdb_dataservices_server.isoline AS $$
|
|||||||
for isochrone in resp:
|
for isochrone in resp:
|
||||||
result_polygon = coordinates_to_polygon(isochrone.coordinates)
|
result_polygon = coordinates_to_polygon(isochrone.coordinates)
|
||||||
if result_polygon:
|
if result_polygon:
|
||||||
service_manager.quota_service.increment_success_service_use()
|
|
||||||
result.append([source, isochrone.duration, result_polygon])
|
result.append([source, isochrone.duration, result_polygon])
|
||||||
else:
|
else:
|
||||||
service_manager.quota_service.increment_empty_service_use()
|
|
||||||
result.append([source, isochrone.duration, None])
|
result.append([source, isochrone.duration, None])
|
||||||
service_manager.quota_service.increment_success_service_use()
|
service_manager.quota_service.increment_success_service_use()
|
||||||
service_manager.quota_service.increment_isolines_service_use(len(result))
|
service_manager.quota_service.increment_isolines_service_use(len(result))
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ from collections import namedtuple
|
|||||||
from requests.adapters import HTTPAdapter
|
from requests.adapters import HTTPAdapter
|
||||||
from cartodb_services import StreetPointBulkGeocoder
|
from cartodb_services import StreetPointBulkGeocoder
|
||||||
from cartodb_services.here import HereMapsGeocoder
|
from cartodb_services.here import HereMapsGeocoder
|
||||||
from cartodb_services.geocoder import geocoder_metadata, geocoder_error_response
|
from cartodb_services.geocoder import geocoder_metadata, geocoder_error_response, PRECISION_INTERPOLATED
|
||||||
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
|
||||||
|
|
||||||
@@ -137,8 +137,8 @@ class HereMapsBulkGeocoder(HereMapsGeocoder, StreetPointBulkGeocoder):
|
|||||||
reader = csv.DictReader(root_zip.open(name), delimiter='|')
|
reader = csv.DictReader(root_zip.open(name), delimiter='|')
|
||||||
for row in reader:
|
for row in reader:
|
||||||
if row['SeqNumber'] == '1': # First per requested data
|
if row['SeqNumber'] == '1': # First per requested data
|
||||||
precision = self.PRECISION_BY_MATCH_TYPE[
|
precision = self.PRECISION_BY_MATCH_TYPE.get(
|
||||||
row.get('matchType', 'pointAddress')]
|
row.get('matchType'), PRECISION_INTERPOLATED)
|
||||||
match_type = self.MATCH_TYPE_BY_MATCH_LEVEL.get(row['matchLevel'], None)
|
match_type = self.MATCH_TYPE_BY_MATCH_LEVEL.get(row['matchLevel'], None)
|
||||||
results.append((row['recId'],
|
results.append((row['recId'],
|
||||||
[row['displayLongitude'], row['displayLatitude']],
|
[row['displayLongitude'], row['displayLatitude']],
|
||||||
|
|||||||
@@ -143,8 +143,8 @@ class HereMapsGeocoder(Traceable):
|
|||||||
|
|
||||||
def _extract_metadata_from_result(self, result):
|
def _extract_metadata_from_result(self, result):
|
||||||
# See https://stackoverflow.com/questions/51285622/missing-matchtype-at-here-geocoding-responses
|
# See https://stackoverflow.com/questions/51285622/missing-matchtype-at-here-geocoding-responses
|
||||||
precision = self.PRECISION_BY_MATCH_TYPE[
|
precision = self.PRECISION_BY_MATCH_TYPE.get(
|
||||||
result.get('MatchType', 'pointAddress')]
|
result.get('MatchType'), PRECISION_INTERPOLATED)
|
||||||
match_type = self.MATCH_TYPE_BY_MATCH_LEVEL.get(result['MatchLevel'], None)
|
match_type = self.MATCH_TYPE_BY_MATCH_LEVEL.get(result['MatchLevel'], None)
|
||||||
return geocoder_metadata(
|
return geocoder_metadata(
|
||||||
result['Relevance'],
|
result['Relevance'],
|
||||||
|
|||||||
@@ -73,12 +73,12 @@ class TomTomGeocoder(Traceable):
|
|||||||
@qps_retry(qps=5, provider='tomtom')
|
@qps_retry(qps=5, provider='tomtom')
|
||||||
def geocode(self, searchtext, city=None, state_province=None,
|
def geocode(self, searchtext, city=None, state_province=None,
|
||||||
country=None):
|
country=None):
|
||||||
response = self.geocode_meta(searchtext, city, state_province, country)
|
geocoder_response, http_response = self.geocode_meta(searchtext, city, state_province, country)
|
||||||
error_message = response[1].get('error', None)
|
error_message = geocoder_response[1].get('error', None)
|
||||||
if error_message:
|
if error_message:
|
||||||
raise ServiceException(error_message, None)
|
raise ServiceException(error_message, http_response)
|
||||||
else:
|
else:
|
||||||
return response[0]
|
return geocoder_response[0]
|
||||||
|
|
||||||
@qps_retry(qps=5, provider='tomtom')
|
@qps_retry(qps=5, provider='tomtom')
|
||||||
def geocode_meta(self, searchtext, city=None, state_province=None,
|
def geocode_meta(self, searchtext, city=None, state_province=None,
|
||||||
@@ -93,7 +93,7 @@ class TomTomGeocoder(Traceable):
|
|||||||
country = country.decode('utf-8')
|
country = country.decode('utf-8')
|
||||||
|
|
||||||
if not self._validate_input(searchtext, city, state_province, country):
|
if not self._validate_input(searchtext, city, state_province, country):
|
||||||
return EMPTY_RESPONSE
|
return (EMPTY_RESPONSE, None)
|
||||||
|
|
||||||
address = []
|
address = []
|
||||||
if searchtext and searchtext.strip():
|
if searchtext and searchtext.strip():
|
||||||
@@ -107,18 +107,18 @@ class TomTomGeocoder(Traceable):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
response = requests.get(uri)
|
response = requests.get(uri)
|
||||||
return self._parse_response(response.status_code, response.text)
|
return (self._parse_response(response.status_code, response.text), response)
|
||||||
except requests.Timeout as te:
|
except requests.Timeout as te:
|
||||||
# In case of timeout we want to stop the job because the server
|
# In case of timeout we want to stop the job because the server
|
||||||
# could be down
|
# could be down
|
||||||
msg = 'Timeout connecting to TomTom geocoding server'
|
msg = 'Timeout connecting to TomTom geocoding server'
|
||||||
self._logger.error(msg, te)
|
self._logger.error(msg, te)
|
||||||
return geocoder_error_response(msg)
|
return (geocoder_error_response(msg), None)
|
||||||
except requests.ConnectionError as ce:
|
except requests.ConnectionError as ce:
|
||||||
# Don't raise the exception to continue with the geocoding job
|
# Don't raise the exception to continue with the geocoding job
|
||||||
self._logger.error('Error connecting to TomTom geocoding server',
|
self._logger.error('Error connecting to TomTom geocoding server',
|
||||||
exception=ce)
|
exception=ce)
|
||||||
return EMPTY_RESPONSE
|
return (EMPTY_RESPONSE, None)
|
||||||
|
|
||||||
def _parse_response(self, status_code, text):
|
def _parse_response(self, status_code, text):
|
||||||
if status_code == requests.codes.ok:
|
if status_code == requests.codes.ok:
|
||||||
|
|||||||
@@ -11,13 +11,14 @@ from cartodb_services.tools.coordinates import (validate_coordinates,
|
|||||||
marshall_coordinates)
|
marshall_coordinates)
|
||||||
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 types import (DEFAULT_PROFILE, VALID_PROFILES, DEFAULT_DEPARTAT)
|
from types import (DEFAULT_PROFILE, DEFAULT_ROUTE_TYPE, VALID_PROFILES, VALID_ROUTE_TYPE, DEFAULT_DEPARTAT)
|
||||||
|
|
||||||
BASEURI = ('https://api.tomtom.com/routing/1/calculateRoute/'
|
BASEURI = ('https://api.tomtom.com/routing/1/calculateRoute/'
|
||||||
'{coordinates}'
|
'{coordinates}'
|
||||||
'/json'
|
'/json'
|
||||||
'?key={apikey}'
|
'?key={apikey}'
|
||||||
'&travelMode={travelmode}'
|
'&travelMode={travelmode}'
|
||||||
|
'&routeType={route_type}'
|
||||||
'&departAt={departat}'
|
'&departAt={departat}'
|
||||||
'&computeBestOrder=true')
|
'&computeBestOrder=true')
|
||||||
|
|
||||||
@@ -45,10 +46,11 @@ class TomTomRouting(Traceable):
|
|||||||
self._logger = logger
|
self._logger = logger
|
||||||
|
|
||||||
def _uri(self, coordinates, profile=DEFAULT_PROFILE,
|
def _uri(self, coordinates, profile=DEFAULT_PROFILE,
|
||||||
date_time=DEFAULT_DEPARTAT):
|
date_time=DEFAULT_DEPARTAT, route_type=DEFAULT_ROUTE_TYPE):
|
||||||
uri = URITemplate(BASEURI).expand(apikey=self._apikey,
|
uri = URITemplate(BASEURI).expand(apikey=self._apikey,
|
||||||
coordinates=coordinates,
|
coordinates=coordinates,
|
||||||
travelmode=profile,
|
travelmode=profile,
|
||||||
|
route_type=route_type,
|
||||||
departat=date_time)
|
departat=date_time)
|
||||||
return uri
|
return uri
|
||||||
|
|
||||||
@@ -60,6 +62,14 @@ class TomTomRouting(Traceable):
|
|||||||
valid_profiles=', '.join(
|
valid_profiles=', '.join(
|
||||||
[x for x in VALID_PROFILES])))
|
[x for x in VALID_PROFILES])))
|
||||||
|
|
||||||
|
def _validate_route_type(self, route_type):
|
||||||
|
if route_type not in VALID_ROUTE_TYPE:
|
||||||
|
raise ValueError('{route_type} is not a valid route type. '
|
||||||
|
'Valid route types are: {valid_route_types}'.format(
|
||||||
|
route_type=route_type,
|
||||||
|
valid_route_types=', '.join(
|
||||||
|
[x for x in VALID_ROUTE_TYPE])))
|
||||||
|
|
||||||
def _marshall_coordinates(self, coordinates):
|
def _marshall_coordinates(self, coordinates):
|
||||||
return ':'.join(['{lat},{lon}'.format(lat=coordinate.latitude,
|
return ':'.join(['{lat},{lon}'.format(lat=coordinate.latitude,
|
||||||
lon=coordinate.longitude)
|
lon=coordinate.longitude)
|
||||||
@@ -91,13 +101,14 @@ class TomTomRouting(Traceable):
|
|||||||
|
|
||||||
@qps_retry(qps=5, provider='tomtom')
|
@qps_retry(qps=5, provider='tomtom')
|
||||||
def directions(self, waypoints, profile=DEFAULT_PROFILE,
|
def directions(self, waypoints, profile=DEFAULT_PROFILE,
|
||||||
date_time=DEFAULT_DEPARTAT):
|
date_time=DEFAULT_DEPARTAT, route_type=DEFAULT_ROUTE_TYPE):
|
||||||
self._validate_profile(profile)
|
self._validate_profile(profile)
|
||||||
|
self._validate_route_type(route_type)
|
||||||
validate_coordinates(waypoints, NUM_WAYPOINTS_MIN, NUM_WAYPOINTS_MAX)
|
validate_coordinates(waypoints, NUM_WAYPOINTS_MIN, NUM_WAYPOINTS_MAX)
|
||||||
|
|
||||||
coordinates = self._marshall_coordinates(waypoints)
|
coordinates = self._marshall_coordinates(waypoints)
|
||||||
|
|
||||||
uri = self._uri(coordinates, profile, date_time)
|
uri = self._uri(coordinates, profile, date_time, route_type)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = requests.get(uri)
|
response = requests.get(uri)
|
||||||
|
|||||||
@@ -6,12 +6,16 @@ PROFILE_DRIVING = 'car'
|
|||||||
PROFILE_CYCLING = 'bicycle'
|
PROFILE_CYCLING = 'bicycle'
|
||||||
PROFILE_WALKING = 'pedestrian'
|
PROFILE_WALKING = 'pedestrian'
|
||||||
DEFAULT_PROFILE = PROFILE_DRIVING
|
DEFAULT_PROFILE = PROFILE_DRIVING
|
||||||
|
ROUTE_TYPE_FAST = 'fastest'
|
||||||
|
ROUTE_TYPE_SHORT = 'shortest'
|
||||||
|
|
||||||
DEFAULT_DEPARTAT = 'now'
|
DEFAULT_DEPARTAT = 'now'
|
||||||
|
|
||||||
VALID_PROFILES = [PROFILE_DRIVING,
|
VALID_PROFILES = [PROFILE_DRIVING,
|
||||||
PROFILE_CYCLING,
|
PROFILE_CYCLING,
|
||||||
PROFILE_WALKING]
|
PROFILE_WALKING]
|
||||||
|
VALID_ROUTE_TYPE = [ROUTE_TYPE_SHORT,
|
||||||
|
ROUTE_TYPE_FAST]
|
||||||
|
|
||||||
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
|
||||||
@@ -20,7 +24,13 @@ MAX_SPEEDS = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TRANSPORT_MODE_TO_TOMTOM = {
|
TRANSPORT_MODE_TO_TOMTOM = {
|
||||||
'car': 'car',
|
'car': PROFILE_DRIVING,
|
||||||
'walk': 'pedestrian',
|
'walk': PROFILE_WALKING,
|
||||||
'bicycle': 'bicycle',
|
'bicycle': PROFILE_CYCLING,
|
||||||
|
}
|
||||||
|
|
||||||
|
DEFAULT_ROUTE_TYPE = ROUTE_TYPE_SHORT
|
||||||
|
MODE_TYPE_TO_TOMTOM = {
|
||||||
|
'shortest': ROUTE_TYPE_SHORT,
|
||||||
|
'fastest': ROUTE_TYPE_FAST
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
def normalize(str_input):
|
def normalize(str_input):
|
||||||
return str_input.replace('"', '"') \
|
return str_input.replace('"', '"') \
|
||||||
.replace(';', ',')
|
.replace(';', ',')
|
||||||
|
|
||||||
|
def options_to_dict(options):
|
||||||
|
return dict(option.split("=") for option in options)
|
||||||
|
|||||||
@@ -2,13 +2,17 @@ import time
|
|||||||
import random
|
import random
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from exceptions import TimeoutException
|
from exceptions import TimeoutException
|
||||||
|
import re
|
||||||
|
|
||||||
DEFAULT_RETRY_TIMEOUT = 60
|
DEFAULT_RETRY_TIMEOUT = 60
|
||||||
DEFAULT_QUERIES_PER_SECOND = 10
|
DEFAULT_QUERIES_PER_SECOND = 10
|
||||||
|
|
||||||
TOMTOM_403_RATE_LIMIT_HEADER = 'Account Over Queries Per Second Limit'
|
TOMTOM_403_RATE_LIMIT_HEADERS = [
|
||||||
|
'Account Over Queries Per Second Limit',
|
||||||
|
'Developer Over Qps'
|
||||||
|
]
|
||||||
TOMTOM_DETAIL_HEADER = 'X-Error-Detail-Header'
|
TOMTOM_DETAIL_HEADER = 'X-Error-Detail-Header'
|
||||||
|
TOMTOM_403_RATE_LIMIT_HEADER_PATTERN = re.compile('|'.join(TOMTOM_403_RATE_LIMIT_HEADERS), re.IGNORECASE)
|
||||||
|
|
||||||
def qps_retry(original_function=None, **options):
|
def qps_retry(original_function=None, **options):
|
||||||
""" Query Per Second retry decorator
|
""" Query Per Second retry decorator
|
||||||
@@ -49,9 +53,11 @@ class QPSService:
|
|||||||
response = getattr(e, 'response', None)
|
response = getattr(e, 'response', None)
|
||||||
if response is not None:
|
if response is not None:
|
||||||
if self._provider is not None and self._provider == 'tomtom' and (response.status_code == 403):
|
if self._provider is not None and self._provider == 'tomtom' and (response.status_code == 403):
|
||||||
if response.headers.get(TOMTOM_DETAIL_HEADER) != TOMTOM_403_RATE_LIMIT_HEADER:
|
detail_header = response.headers.get(TOMTOM_DETAIL_HEADER)
|
||||||
|
if detail_header and TOMTOM_403_RATE_LIMIT_HEADER_PATTERN.search(detail_header):
|
||||||
|
self.retry(start_time, attempt_number)
|
||||||
|
else:
|
||||||
raise e
|
raise e
|
||||||
self.retry(start_time, attempt_number)
|
|
||||||
elif response.status_code == 429:
|
elif response.status_code == 429:
|
||||||
self.retry(start_time, attempt_number)
|
self.retry(start_time, attempt_number)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ from setuptools import setup, find_packages
|
|||||||
setup(
|
setup(
|
||||||
name='cartodb_services',
|
name='cartodb_services',
|
||||||
|
|
||||||
version='0.20.2',
|
version='0.21.3',
|
||||||
|
|
||||||
description='CartoDB Services API Python Library',
|
description='CartoDB Services API Python Library',
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,9 @@ INVALID_WAYPOINTS_MIN = [Coordinate(13.42936, 52.50931)]
|
|||||||
INVALID_WAYPOINTS_MAX = [Coordinate(13.42936, 52.50931)
|
INVALID_WAYPOINTS_MAX = [Coordinate(13.42936, 52.50931)
|
||||||
for x in range(0, NUM_WAYPOINTS_MAX + 2)]
|
for x in range(0, NUM_WAYPOINTS_MAX + 2)]
|
||||||
VALID_PROFILE = DEFAULT_PROFILE
|
VALID_PROFILE = DEFAULT_PROFILE
|
||||||
|
VALID_ROUTE_TYPE = 'fastest'
|
||||||
INVALID_PROFILE = 'invalid_profile'
|
INVALID_PROFILE = 'invalid_profile'
|
||||||
|
INVALID_ROUTE_TYPE = 'invalid_route_type'
|
||||||
|
|
||||||
|
|
||||||
class TomTomRoutingTestCase(unittest.TestCase):
|
class TomTomRoutingTestCase(unittest.TestCase):
|
||||||
@@ -43,6 +45,9 @@ class TomTomRoutingTestCase(unittest.TestCase):
|
|||||||
with self.assertRaises(ServiceException):
|
with self.assertRaises(ServiceException):
|
||||||
invalid_routing.directions(VALID_WAYPOINTS,
|
invalid_routing.directions(VALID_WAYPOINTS,
|
||||||
VALID_PROFILE)
|
VALID_PROFILE)
|
||||||
|
def test_invalid_route_type(self):
|
||||||
|
with self.assertRaises(ValueError):
|
||||||
|
self.routing.directions(VALID_WAYPOINTS, VALID_PROFILE, route_type=INVALID_ROUTE_TYPE)
|
||||||
|
|
||||||
def test_valid_request(self):
|
def test_valid_request(self):
|
||||||
route = self.routing.directions(VALID_WAYPOINTS, VALID_PROFILE)
|
route = self.routing.directions(VALID_WAYPOINTS, VALID_PROFILE)
|
||||||
@@ -50,3 +55,9 @@ class TomTomRoutingTestCase(unittest.TestCase):
|
|||||||
assert route.shape
|
assert route.shape
|
||||||
assert route.length
|
assert route.length
|
||||||
assert route.duration
|
assert route.duration
|
||||||
|
|
||||||
|
route = self.routing.directions(VALID_WAYPOINTS, VALID_PROFILE, route_type=VALID_ROUTE_TYPE)
|
||||||
|
|
||||||
|
assert route.shape
|
||||||
|
assert route.length
|
||||||
|
assert route.duration
|
||||||
|
|||||||
Reference in New Issue
Block a user