Compare commits
43 Commits
0.6.0-clie
...
0.8.0-clie
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
45fcfe44e2 | ||
|
|
a4b0725843 | ||
|
|
4075e7349b | ||
|
|
6d35cff9c7 | ||
|
|
594fb99854 | ||
|
|
63ae4a362a | ||
|
|
5ebc2ce2e3 | ||
|
|
e822321306 | ||
|
|
b33730aae3 | ||
|
|
9ed059f4cc | ||
|
|
972970a12d | ||
|
|
37bcaeada3 | ||
|
|
25bf9b6372 | ||
|
|
f76a5cdfcc | ||
|
|
e046ca2c4d | ||
|
|
c9f57259be | ||
|
|
9ba8f92418 | ||
|
|
41b9db4144 | ||
|
|
25d42a75e4 | ||
|
|
f9e9617d6f | ||
|
|
b0bb60736c | ||
|
|
a2863d7135 | ||
|
|
a114f857fd | ||
|
|
47962c9ccb | ||
|
|
901f5d7b8b | ||
|
|
c7bcbddaa9 | ||
|
|
9ad55a4d53 | ||
|
|
f4d8d28d14 | ||
|
|
faab16bb64 | ||
|
|
3e74ac05bb | ||
|
|
2b35c0b375 | ||
|
|
6412d432bf | ||
|
|
a68f6e9705 | ||
|
|
27124e26dd | ||
|
|
175d5e716d | ||
|
|
d57856367a | ||
|
|
770ff0eb95 | ||
|
|
0fc9469430 | ||
|
|
a613ee3039 | ||
|
|
2d67865079 | ||
|
|
6b7e67304a | ||
|
|
6d398a9499 | ||
|
|
ecbcf98670 |
@@ -77,7 +77,7 @@ Steps to deploy a new Data Services API version :
|
||||
SELECT CDB_Conf_SetConf('heremaps_conf', '{"geocoder": {"app_id": "here_geocoder_app_id", "app_code": "here_geocoder_app_code", "geocoder_cost_per_hit": "1"}, "isolines" : {"app_id": "here_isolines_app_id", "app_code": "here_geocoder_app_code"}}');
|
||||
SELECT CDB_Conf_SetConf('user_config', '{"is_organization": false, "entity_name": "<YOUR_USERNAME>"}')
|
||||
SELECT CDB_Conf_SetConf('mapzen_conf', '{"routing": {"api_key": "valhalla_app_key", "monthly_quota": 999999}, "geocoder": {"api_key": "search_app_key", "monthly_quota": 999999}}');
|
||||
SELECT CDB_Conf_SetConf('logger_con', '{"geocoder_log_path": "/tmp/geocodings.log"}')
|
||||
SELECT CDB_Conf_SetConf('logger_conf', '{"geocoder_log_path": "/tmp/geocodings.log"}')
|
||||
SELECT CDB_Conf_SetConf('data_observatory_conf', '{"connection": {"whitelist": [], "production": "host=localhost port=5432 dbname=dataservices_db user=geocoder_api", "staging": "host=localhost port=5432 dbname=dataservices_db user=geocoder_api"}}')
|
||||
```
|
||||
|
||||
|
||||
@@ -13,8 +13,8 @@ OLD_VERSIONS = $(wildcard old_versions/*.sql)
|
||||
# @see http://www.postgresql.org/docs/current/static/extend-pgxs.html
|
||||
DATA = $(NEW_EXTENSION_ARTIFACT) \
|
||||
$(OLD_VERSIONS) \
|
||||
cdb_dataservices_client--0.5.0--0.6.0.sql \
|
||||
cdb_dataservices_client--0.6.0--0.5.0.sql
|
||||
cdb_dataservices_client--0.7.0--0.8.0.sql \
|
||||
cdb_dataservices_client--0.8.0--0.7.0.sql
|
||||
|
||||
|
||||
REGRESS = $(notdir $(basename $(wildcard test/sql/*test.sql)))
|
||||
|
||||
113
client/cdb_dataservices_client--0.7.0--0.8.0.sql
Normal file
113
client/cdb_dataservices_client--0.7.0--0.8.0.sql
Normal file
@@ -0,0 +1,113 @@
|
||||
--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.8.0'" to load this file. \quit
|
||||
|
||||
|
||||
--
|
||||
-- Public dataservices API function
|
||||
--
|
||||
-- These are the only ones with permissions to publicuser role
|
||||
-- and should also be the only ones with SECURITY DEFINER
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client.cdb_here_geocode_street_point (searchtext text, city text DEFAULT NULL, state_province text DEFAULT NULL, country text DEFAULT NULL)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
username text;
|
||||
orgname text;
|
||||
BEGIN
|
||||
IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN
|
||||
RAISE EXCEPTION 'The api_key must be provided';
|
||||
END IF;
|
||||
SELECT u, o INTO username, orgname FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text);
|
||||
-- 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 cdb_dataservices_client._cdb_here_geocode_street_point(username, orgname, searchtext, city, state_province, country) INTO ret;
|
||||
RETURN ret;
|
||||
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||
|
||||
--
|
||||
-- Public dataservices API function
|
||||
--
|
||||
-- These are the only ones with permissions to publicuser role
|
||||
-- and should also be the only ones with SECURITY DEFINER
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client.cdb_google_geocode_street_point (searchtext text, city text DEFAULT NULL, state_province text DEFAULT NULL, country text DEFAULT NULL)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
username text;
|
||||
orgname text;
|
||||
BEGIN
|
||||
IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN
|
||||
RAISE EXCEPTION 'The api_key must be provided';
|
||||
END IF;
|
||||
SELECT u, o INTO username, orgname FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text);
|
||||
-- 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 cdb_dataservices_client._cdb_google_geocode_street_point(username, orgname, searchtext, city, state_province, country) INTO ret;
|
||||
RETURN ret;
|
||||
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||
|
||||
--
|
||||
-- Public dataservices API function
|
||||
--
|
||||
-- These are the only ones with permissions to publicuser role
|
||||
-- and should also be the only ones with SECURITY DEFINER
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client.cdb_mapzen_geocode_street_point (searchtext text, city text DEFAULT NULL, state_province text DEFAULT NULL, country text DEFAULT NULL)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
username text;
|
||||
orgname text;
|
||||
BEGIN
|
||||
IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN
|
||||
RAISE EXCEPTION 'The api_key must be provided';
|
||||
END IF;
|
||||
SELECT u, o INTO username, orgname FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text);
|
||||
-- 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 cdb_dataservices_client._cdb_mapzen_geocode_street_point(username, orgname, searchtext, city, state_province, country) INTO ret;
|
||||
RETURN ret;
|
||||
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_here_geocode_street_point (username text, organization_name text, searchtext text, city text DEFAULT NULL, state_province text DEFAULT NULL, country text DEFAULT NULL)
|
||||
RETURNS Geometry AS $$
|
||||
CONNECT cdb_dataservices_client._server_conn_str();
|
||||
|
||||
SELECT cdb_dataservices_server.cdb_here_geocode_street_point (username, organization_name, searchtext, city, state_province, country);
|
||||
|
||||
$$ LANGUAGE plproxy;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_google_geocode_street_point (username text, organization_name text, searchtext text, city text DEFAULT NULL, state_province text DEFAULT NULL, country text DEFAULT NULL)
|
||||
RETURNS Geometry AS $$
|
||||
CONNECT cdb_dataservices_client._server_conn_str();
|
||||
|
||||
SELECT cdb_dataservices_server.cdb_google_geocode_street_point (username, organization_name, searchtext, city, state_province, country);
|
||||
|
||||
$$ LANGUAGE plproxy;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_mapzen_geocode_street_point (username text, organization_name text, searchtext text, city text DEFAULT NULL, state_province text DEFAULT NULL, country text DEFAULT NULL)
|
||||
RETURNS Geometry AS $$
|
||||
CONNECT cdb_dataservices_client._server_conn_str();
|
||||
|
||||
SELECT cdb_dataservices_server.cdb_mapzen_geocode_street_point (username, organization_name, searchtext, city, state_province, country);
|
||||
|
||||
$$ LANGUAGE plproxy;
|
||||
9
client/cdb_dataservices_client--0.8.0--0.7.0.sql
Normal file
9
client/cdb_dataservices_client--0.8.0--0.7.0.sql
Normal file
@@ -0,0 +1,9 @@
|
||||
--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.7.0'" to load this file. \quit
|
||||
DROP FUNCTION IF EXISTS cdb_dataservices_client.cdb_here_geocode_street_point (text, text, text, text);
|
||||
DROP FUNCTION IF EXISTS cdb_dataservices_client.cdb_google_geocode_street_point (text, text, text, text);
|
||||
DROP FUNCTION IF EXISTS cdb_dataservices_client.cdb_mapzen_geocode_street_point (text, text, text, text);
|
||||
DROP FUNCTION IF EXISTS cdb_dataservices_client._cdb_here_geocode_street_point (text, text, text, text, text, text);
|
||||
DROP FUNCTION IF EXISTS cdb_dataservices_client._cdb_google_geocode_street_point (text, text, text, text, text, text);
|
||||
DROP FUNCTION IF EXISTS cdb_dataservices_client._cdb_mapzen_geocode_street_point (text, text, text, text, text, text);
|
||||
1404
client/cdb_dataservices_client--0.8.0.sql
Normal file
1404
client/cdb_dataservices_client--0.8.0.sql
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
||||
comment = 'CartoDB dataservices client API extension'
|
||||
default_version = '0.6.0'
|
||||
default_version = '0.8.0'
|
||||
requires = 'plproxy, cartodb'
|
||||
superuser = true
|
||||
schema = cdb_dataservices_client
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
--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.7.0'" to load this file. \quit
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client.obs_getmeasurebyid (geom_ref text, measure_id text, boundary_id text, time_span text DEFAULT NULL)
|
||||
RETURNS numeric AS $$
|
||||
DECLARE
|
||||
ret numeric;
|
||||
username text;
|
||||
orgname text;
|
||||
BEGIN
|
||||
IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN
|
||||
RAISE EXCEPTION 'The api_key must be provided';
|
||||
END IF;
|
||||
SELECT u, o INTO username, orgname FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text);
|
||||
-- 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 cdb_dataservices_client._obs_getmeasurebyid(username, orgname, geom_ref, measure_id, boundary_id, time_span) INTO ret;
|
||||
RETURN ret;
|
||||
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client._obs_getmeasurebyid (username text, organization_name text, geom_ref text, measure_id text, boundary_id text, time_span text DEFAULT NULL)
|
||||
RETURNS numeric AS $$
|
||||
CONNECT cdb_dataservices_client._server_conn_str();
|
||||
|
||||
SELECT cdb_dataservices_server.obs_getmeasurebyid (username, organization_name, geom_ref, measure_id, boundary_id, time_span);
|
||||
|
||||
$$ LANGUAGE plproxy;
|
||||
|
||||
GRANT EXECUTE ON FUNCTION cdb_dataservices_client.obs_getmeasurebyid(geom_ref text, measure_id text, boundary_id text, time_span text) TO publicuser;
|
||||
@@ -0,0 +1,5 @@
|
||||
--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.6.0'" to load this file. \quit
|
||||
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getmeasurebyid (text, text, text, text);
|
||||
DROP FUNCTION IF EXISTS cdb_dataservices_client.obs_getmeasurebyid (text, text, text, text);
|
||||
1293
client/old_versions/cdb_dataservices_client--0.7.0.sql
Normal file
1293
client/old_versions/cdb_dataservices_client--0.7.0.sql
Normal file
File diff suppressed because it is too large
Load Diff
@@ -59,6 +59,30 @@
|
||||
- { name: state_province, type: text, default: 'NULL'}
|
||||
- { name: country, type: text, default: 'NULL'}
|
||||
|
||||
- name: cdb_here_geocode_street_point
|
||||
return_type: Geometry
|
||||
params:
|
||||
- { name: searchtext, type: text}
|
||||
- { name: city, type: text, default: 'NULL'}
|
||||
- { name: state_province, type: text, default: 'NULL'}
|
||||
- { name: country, type: text, default: 'NULL'}
|
||||
|
||||
- name: cdb_google_geocode_street_point
|
||||
return_type: Geometry
|
||||
params:
|
||||
- { name: searchtext, type: text}
|
||||
- { name: city, type: text, default: 'NULL'}
|
||||
- { name: state_province, type: text, default: 'NULL'}
|
||||
- { name: country, type: text, default: 'NULL'}
|
||||
|
||||
- name: cdb_mapzen_geocode_street_point
|
||||
return_type: Geometry
|
||||
params:
|
||||
- { name: searchtext, type: text}
|
||||
- { name: city, type: text, default: 'NULL'}
|
||||
- { name: state_province, type: text, default: 'NULL'}
|
||||
- { name: country, type: text, default: 'NULL'}
|
||||
|
||||
- name: cdb_isodistance
|
||||
return_type: SETOF cdb_dataservices_client.isoline
|
||||
multi_row: true
|
||||
@@ -210,6 +234,14 @@
|
||||
- { name: boundary_id, type: text, default: 'NULL' }
|
||||
- { name: time_span, type: text, default: 'NULL'}
|
||||
|
||||
- name: obs_getmeasurebyid
|
||||
return_type: numeric
|
||||
params:
|
||||
- { name: geom_ref, type: text }
|
||||
- { name: measure_id, type: text }
|
||||
- { name: boundary_id, type: text}
|
||||
- { name: time_span, type: text, default: 'NULL'}
|
||||
|
||||
- name: obs_getcategory
|
||||
return_type: text
|
||||
params:
|
||||
|
||||
@@ -102,6 +102,16 @@ BEGIN
|
||||
RETURN ret;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql';
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.obs_getmeasurebyid (username text, orgname text, geom_ref text, measure_id text, boundary_id text, time_span text DEFAULT NULL)
|
||||
RETURNS numeric AS $$
|
||||
DECLARE
|
||||
ret numeric;
|
||||
BEGIN
|
||||
RAISE NOTICE 'cdb_dataservices_server.obs_getmeasurebyid invoked with params (%, %, %, %, %, %)', username, orgname, geom_ref, measure_id, boundary_id, time_span;
|
||||
SELECT 10923.093200390833950::numeric INTO ret;
|
||||
RETURN ret;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql';
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.obs_getcategory (username text, orgname text, geom Geometry, category_id text, boundary_id text DEFAULT NULL, time_span text DEFAULT NULL)
|
||||
RETURNS text AS $$
|
||||
DECLARE
|
||||
@@ -266,6 +276,15 @@ PL/pgSQL function obs_getmeasure(geometry,text,text,text,text) line 16 at SQL st
|
||||
10923.093200390833950
|
||||
(1 row)
|
||||
|
||||
SELECT obs_getmeasurebyid('36047'::text, 'us.census.acs.B01001001'::text, 'us.census.tiger.county'::text);
|
||||
NOTICE: cdb_dataservices_client._obs_getmeasurebyid(6): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.obs_getmeasurebyid invoked with params (test_user, <NULL>, 36047, us.census.acs.B01001001, us.census.tiger.county, <NULL>)
|
||||
CONTEXT: SQL statement "SELECT cdb_dataservices_client._obs_getmeasurebyid(username, orgname, geom_ref, measure_id, boundary_id, time_span)"
|
||||
PL/pgSQL function obs_getmeasurebyid(text,text,text,text) line 16 at SQL statement
|
||||
obs_getmeasurebyid
|
||||
-----------------------
|
||||
10923.093200390833950
|
||||
(1 row)
|
||||
|
||||
SELECT obs_getcategory(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), 'us.census.spielman_singleton_segments.X10'::text);
|
||||
NOTICE: cdb_dataservices_client._obs_getcategory(6): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.obs_getcategory invoked with params (test_user, <NULL>, 0101000020E6100000548B8862F27B52C0DDD1FF722D5A4440, us.census.spielman_singleton_segments.X10, <NULL>, <NULL>)
|
||||
CONTEXT: SQL statement "SELECT cdb_dataservices_client._obs_getcategory(username, orgname, geom, category_id, boundary_id, time_span)"
|
||||
|
||||
@@ -115,6 +115,17 @@ BEGIN
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql';
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.obs_getmeasurebyid (username text, orgname text, geom_ref text, measure_id text, boundary_id text, time_span text DEFAULT NULL)
|
||||
RETURNS numeric AS $$
|
||||
DECLARE
|
||||
ret numeric;
|
||||
BEGIN
|
||||
RAISE NOTICE 'cdb_dataservices_server.obs_getmeasurebyid invoked with params (%, %, %, %, %, %)', username, orgname, geom_ref, measure_id, boundary_id, time_span;
|
||||
SELECT 10923.093200390833950::numeric INTO ret;
|
||||
RETURN ret;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql';
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.obs_getcategory (username text, orgname text, geom Geometry, category_id text, boundary_id text DEFAULT NULL, time_span text DEFAULT NULL)
|
||||
RETURNS text AS $$
|
||||
DECLARE
|
||||
@@ -196,6 +207,7 @@ SELECT obs_getboundariesbypointandradius(ST_SetSRID(ST_Point(-73.936669 , 40.704
|
||||
SELECT obs_getpointsbygeometry(ST_MakeEnvelope(-73.9452409744, 40.6988851644, -73.9280319214, 40.7101254524, 4326), 'us.census.tiger.census_tract'::text);
|
||||
SELECT obs_getpointsbypointandradius(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), 500::numeric, 'us.census.tiger.census_tract'::text);
|
||||
SELECT obs_getmeasure(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), 'us.census.acs.B01001001'::text);
|
||||
SELECT obs_getmeasurebyid('36047'::text, 'us.census.acs.B01001001'::text, 'us.census.tiger.county'::text);
|
||||
SELECT obs_getcategory(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), 'us.census.spielman_singleton_segments.X10'::text);
|
||||
SELECT obs_getuscensusmeasure(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), 'male population'::text);
|
||||
SELECT obs_getuscensuscategory(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), 'Spielman-Singleton Segments: 10 Clusters'::text);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
Routing is the navigation from a defined start location to a defined end location. The calculated results are displayed as turn-by-turn directions on your map, based on the transportation mode that you specified. Routing services through CartoDB are available by using the available functions in the Data Services API.
|
||||
|
||||
### cdb_route_point_to_point(_origin geometry(Point), destination geometry(Point), mode text, [options text[], units text]_)
|
||||
## cdb_route_point_to_point(_origin geometry(Point), destination geometry(Point), mode text, [options text[], units text]_)
|
||||
|
||||
Returns a route from origin to destination.
|
||||
|
||||
@@ -38,7 +38,7 @@ INSERT INTO <TABLE> (duration, length, the_geom) SELECT duration, length, shape
|
||||
UPDATE <TABLE> SET the_geom = (SELECT shape FROM cdb_route_point_to_point('POINT(-3.70237112 40.41706163)'::geometry,'POINT(-3.69909883 40.41236875)'::geometry, 'car', ARRAY['mode_type=shortest']::text[]))
|
||||
```
|
||||
|
||||
### cdb_route_with_waypoints(_waypoints geometry(Point)[], mode text, [options text[], units text]_)
|
||||
## cdb_route_with_waypoints(_waypoints geometry(Point)[], mode text, [options text[], units text]_)
|
||||
|
||||
Returns a route that goes from origin to destination and whose path travels through the defined locations.
|
||||
|
||||
|
||||
@@ -2,39 +2,47 @@
|
||||
# Once a version is released, it is not meant to be changed. E.g: once version 0.0.1 is out, it SHALL NOT be changed.
|
||||
EXTENSION = cdb_dataservices_server
|
||||
EXTVERSION = $(shell grep default_version $(EXTENSION).control | sed -e "s/default_version[[:space:]]*=[[:space:]]*'\([^']*\)'/\1/")
|
||||
|
||||
# The new version to be generated from templates
|
||||
SED = sed
|
||||
ERB = erb
|
||||
REPLACEMENTS = -i 's/$(EXTVERSION)/$(NEW_VERSION)/g'
|
||||
NEW_EXTENSION_ARTIFACT = $(EXTENSION)--$(EXTVERSION).sql
|
||||
OLD_VERSIONS = $(wildcard old_versions/*.sql)
|
||||
|
||||
REGRESS = $(notdir $(basename $(wildcard test/sql/*test.sql)))
|
||||
TEST_DIR = test/
|
||||
REGRESS_OPTS = --inputdir='$(TEST_DIR)' --outputdir='$(TEST_DIR)'
|
||||
|
||||
# DATA is a special variable used by postgres build infrastructure
|
||||
# These are the files to be installed in the server shared dir,
|
||||
# for installation from scratch, upgrades and downgrades.
|
||||
# @see http://www.postgresql.org/docs/current/static/extend-pgxs.html
|
||||
DATA = $(NEW_EXTENSION_ARTIFACT) \
|
||||
$(OLD_VERSIONS) \
|
||||
cdb_dataservices_server--0.8.0--0.9.0.sql \
|
||||
cdb_dataservices_server--0.9.0--0.8.0.sql
|
||||
|
||||
REGRESS = $(notdir $(basename $(wildcard test/sql/*test.sql)))
|
||||
TEST_DIR = test/
|
||||
REGRESS_OPTS = --inputdir='$(TEST_DIR)' --outputdir='$(TEST_DIR)'
|
||||
DATA = $(EXTENSION)--*.sql
|
||||
OLD_VERSIONS = $(wildcard old_versions/*.sql)
|
||||
SOURCES_DATA_DIR = sql/
|
||||
SOURCES_DATA = $(wildcard sql/*.sql)
|
||||
|
||||
# postgres build stuff
|
||||
PG_CONFIG = pg_config
|
||||
PGXS := $(shell $(PG_CONFIG) --pgxs)
|
||||
include $(PGXS)
|
||||
|
||||
SOURCES_DATA_DIR = sql/
|
||||
|
||||
SOURCES_DATA = $(wildcard sql/*.sql)
|
||||
|
||||
$(NEW_EXTENSION_ARTIFACT): $(SOURCES_DATA)
|
||||
rm -f $@
|
||||
cat $(SOURCES_DATA_DIR)/*.sql >> $@
|
||||
|
||||
.PHONY: all
|
||||
all: $(DATA)
|
||||
|
||||
.PHONY: release
|
||||
release: $(EXTENSION).control $(SOURCES_DATA)
|
||||
test -n "$(NEW_VERSION)" # $$NEW_VERSION VARIABLE MISSING. Eg. make release NEW_VERSION=0.x.0
|
||||
mv *.sql old_versions
|
||||
$(SED) $(REPLACEMENTS) $(EXTENSION).control
|
||||
cat $(SOURCES_DATA_DIR)/*.sql > $(EXTENSION)--$(NEW_VERSION).sql
|
||||
$(ERB) version=$(NEW_VERSION) upgrade_downgrade_template.erb > $(EXTENSION)--$(EXTVERSION)--$(NEW_VERSION).sql
|
||||
$(ERB) version=$(EXTVERSION) upgrade_downgrade_template.erb > $(EXTENSION)--$(NEW_VERSION)--$(EXTVERSION).sql
|
||||
|
||||
# Only meant for development time, do not use once a version is released
|
||||
.PHONY: devclean
|
||||
devclean:
|
||||
rm -f $(NEW_EXTENSION_ARTIFACT)
|
||||
|
||||
101
server/extension/cdb_dataservices_server--0.10.0--0.11.0.sql
Normal file
101
server/extension/cdb_dataservices_server--0.10.0--0.11.0.sql
Normal file
@@ -0,0 +1,101 @@
|
||||
--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.11.0'" to load this file. \quit
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_here_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
RETURNS Geometry AS $$
|
||||
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)]
|
||||
|
||||
if user_geocoder_config.heremaps_geocoder:
|
||||
here_plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_here_geocode_street_point($1, $2, $3, $4, $5, $6) as point; ", ["text", "text", "text", "text", "text", "text"])
|
||||
return plpy.execute(here_plan, [username, orgname, searchtext, city, state_province, country], 1)[0]['point']
|
||||
else:
|
||||
plpy.error('Here geocoder is not available for your account.')
|
||||
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_google_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
RETURNS Geometry AS $$
|
||||
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)]
|
||||
|
||||
if user_geocoder_config.google_geocoder:
|
||||
google_plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_google_geocode_street_point($1, $2, $3, $4, $5, $6) as point; ", ["text", "text", "text", "text", "text", "text"])
|
||||
return plpy.execute(google_plan, [username, orgname, searchtext, city, state_province, country], 1)[0]['point']
|
||||
else:
|
||||
plpy.error('Google geocoder is not available for your account.')
|
||||
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_mapzen_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
RETURNS Geometry AS $$
|
||||
# The configuration is retrieved but no checks are performed on it
|
||||
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_mapzen_geocoder_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||
user_geocoder_config = GD["user_mapzen_geocoder_config_{0}".format(username)]
|
||||
|
||||
mapzen_plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_mapzen_geocode_street_point($1, $2, $3, $4, $5, $6) as point; ", ["text", "text", "text", "text", "text", "text"])
|
||||
return plpy.execute(mapzen_plan, [username, orgname, searchtext, city, state_province, country], 1)[0]['point']
|
||||
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_mapzen_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
RETURNS Geometry AS $$
|
||||
from cartodb_services.mapzen import MapzenGeocoder
|
||||
from cartodb_services.mapzen.types import country_to_iso3
|
||||
from cartodb_services.metrics import QuotaService
|
||||
|
||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||
user_mapzen_geocoder_config = GD["user_mapzen_geocoder_config_{0}".format(username)]
|
||||
quota_service = QuotaService(user_mapzen_geocoder_config, redis_conn)
|
||||
if not quota_service.check_user_quota():
|
||||
plpy.error('You have reached the limit of your quota')
|
||||
|
||||
try:
|
||||
geocoder = MapzenGeocoder(user_mapzen_geocoder_config.mapzen_api_key)
|
||||
country_iso3 = None
|
||||
if country:
|
||||
country_iso3 = country_to_iso3(country)
|
||||
coordinates = geocoder.geocode(searchtext=searchtext, city=city,
|
||||
state_province=state_province,
|
||||
country=country_iso3)
|
||||
if coordinates:
|
||||
quota_service.increment_success_service_use()
|
||||
plan = plpy.prepare("SELECT ST_SetSRID(ST_MakePoint($1, $2), 4326); ", ["double precision", "double precision"])
|
||||
point = plpy.execute(plan, [coordinates[0], coordinates[1]], 1)[0]
|
||||
return point['st_setsrid']
|
||||
else:
|
||||
quota_service.increment_empty_service_use()
|
||||
return None
|
||||
except BaseException as e:
|
||||
import sys, traceback
|
||||
type_, value_, traceback_ = sys.exc_info()
|
||||
quota_service.increment_failed_service_use()
|
||||
error_msg = 'There was an error trying to geocode using mapzen geocoder: {0}'.format(e)
|
||||
plpy.notice(traceback.format_tb(traceback_))
|
||||
plpy.error(error_msg)
|
||||
finally:
|
||||
quota_service.increment_total_service_use()
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._get_mapzen_geocoder_config(username text, orgname text)
|
||||
RETURNS boolean AS $$
|
||||
cache_key = "user_mapzen_geocoder_config_{0}".format(username)
|
||||
if cache_key in GD:
|
||||
return False
|
||||
else:
|
||||
from cartodb_services.metrics import MapzenGeocoderConfig
|
||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metadata_connection']
|
||||
mapzen_geocoder_config = MapzenGeocoderConfig(redis_conn, plpy, username, orgname)
|
||||
GD[cache_key] = mapzen_geocoder_config
|
||||
return True
|
||||
$$ LANGUAGE plpythonu SECURITY DEFINER;
|
||||
46
server/extension/cdb_dataservices_server--0.11.0--0.10.0.sql
Normal file
46
server/extension/cdb_dataservices_server--0.11.0--0.10.0.sql
Normal file
@@ -0,0 +1,46 @@
|
||||
--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.10.0'" to load this file. \quit
|
||||
DROP FUNCTION IF EXISTS cdb_dataservices_server.cdb_here_geocode_street_point(TEXT, TEXT, TEXT, TEXT, TEXT, TEXT);
|
||||
DROP FUNCTION IF EXISTS cdb_dataservices_server.cdb_google_geocode_street_point(TEXT, TEXT, TEXT, TEXT, TEXT, TEXT);
|
||||
DROP FUNCTION IF EXISTS cdb_dataservices_server.cdb_mapzen_geocode_street_point(TEXT, TEXT, TEXT, TEXT, TEXT, TEXT);
|
||||
DROP FUNCTION IF EXISTS cdb_dataservices_server._get_mapzen_geocoder_config(text, text);
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_mapzen_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
RETURNS Geometry AS $$
|
||||
from cartodb_services.mapzen import MapzenGeocoder
|
||||
from cartodb_services.mapzen.types import country_to_iso3
|
||||
from cartodb_services.metrics import QuotaService
|
||||
|
||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||
user_geocoder_config = GD["user_geocoder_config_{0}".format(username)]
|
||||
quota_service = QuotaService(user_geocoder_config, redis_conn)
|
||||
if not quota_service.check_user_quota():
|
||||
plpy.error('You have reached the limit of your quota')
|
||||
|
||||
try:
|
||||
geocoder = MapzenGeocoder(user_geocoder_config.mapzen_api_key)
|
||||
country_iso3 = None
|
||||
if country:
|
||||
country_iso3 = country_to_iso3(country)
|
||||
coordinates = geocoder.geocode(searchtext=searchtext, city=city,
|
||||
state_province=state_province,
|
||||
country=country_iso3)
|
||||
if coordinates:
|
||||
quota_service.increment_success_service_use()
|
||||
plan = plpy.prepare("SELECT ST_SetSRID(ST_MakePoint($1, $2), 4326); ", ["double precision", "double precision"])
|
||||
point = plpy.execute(plan, [coordinates[0], coordinates[1]], 1)[0]
|
||||
return point['st_setsrid']
|
||||
else:
|
||||
quota_service.increment_empty_service_use()
|
||||
return None
|
||||
except BaseException as e:
|
||||
import sys, traceback
|
||||
type_, value_, traceback_ = sys.exc_info()
|
||||
quota_service.increment_failed_service_use()
|
||||
error_msg = 'There was an error trying to geocode using mapzen geocoder: {0}'.format(e)
|
||||
plpy.notice(traceback.format_tb(traceback_))
|
||||
plpy.error(error_msg)
|
||||
finally:
|
||||
quota_service.increment_total_service_use()
|
||||
$$ LANGUAGE plpythonu;
|
||||
2134
server/extension/cdb_dataservices_server--0.11.0.sql
Normal file
2134
server/extension/cdb_dataservices_server--0.11.0.sql
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
||||
comment = 'CartoDB dataservices server extension'
|
||||
default_version = '0.9.0'
|
||||
default_version = '0.11.0'
|
||||
requires = 'plpythonu, plproxy, postgis, cdb_geocoder'
|
||||
superuser = true
|
||||
schema = cdb_dataservices_server
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
--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.9.0'" to load this file. \quit
|
||||
DROP FUNCTION IF EXISTS cdb_dataservices_server._OBS_GetMeasureById(text, text, text, text, text, text);
|
||||
DROP FUNCTION IF EXISTS cdb_dataservices_server.OBS_GetMeasureById(text, text, text, text, text, text);
|
||||
2076
server/extension/old_versions/cdb_dataservices_server--0.10.0.sql
Normal file
2076
server/extension/old_versions/cdb_dataservices_server--0.10.0.sql
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,54 @@
|
||||
--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.10.0'" to load this file. \quit
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetMeasureById(
|
||||
username TEXT,
|
||||
orgname TEXT,
|
||||
geom_ref TEXT,
|
||||
measure_id TEXT,
|
||||
boundary_id TEXT,
|
||||
time_span TEXT DEFAULT NULL)
|
||||
RETURNS NUMERIC AS $$
|
||||
CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname);
|
||||
SELECT cdb_observatory.OBS_GetMeasureById(geom_ref, measure_id, boundary_id, time_span);
|
||||
$$ LANGUAGE plproxy;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetMeasureById(
|
||||
username TEXT,
|
||||
orgname TEXT,
|
||||
geom_ref TEXT,
|
||||
measure_id TEXT,
|
||||
boundary_id TEXT,
|
||||
time_span TEXT DEFAULT NULL)
|
||||
RETURNS NUMERIC AS $$
|
||||
from cartodb_services.metrics import QuotaService
|
||||
|
||||
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_obs_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||
user_obs_config = GD["user_obs_config_{0}".format(username)]
|
||||
|
||||
quota_service = QuotaService(user_obs_config, redis_conn)
|
||||
if not quota_service.check_user_quota():
|
||||
plpy.error('You have reached the limit of your quota')
|
||||
|
||||
try:
|
||||
obs_plan = plpy.prepare("SELECT cdb_dataservices_server._OBS_GetMeasureById($1, $2, $3, $4, $5, $6) as measure;", ["text", "text", "text", "text", "text", "text"])
|
||||
result = plpy.execute(obs_plan, [username, orgname, geom_ref, measure_id, boundary_id, time_span])
|
||||
if result:
|
||||
quota_service.increment_success_service_use()
|
||||
return result[0]['measure']
|
||||
else:
|
||||
quota_service.increment_empty_service_use()
|
||||
return None
|
||||
except BaseException as e:
|
||||
import sys, traceback
|
||||
type_, value_, traceback_ = sys.exc_info()
|
||||
quota_service.increment_failed_service_use()
|
||||
error_msg = 'There was an error trying to use OBS_GetMeasureById: {0}'.format(e)
|
||||
plpy.notice(traceback.format_tb(traceback_))
|
||||
plpy.error(error_msg)
|
||||
finally:
|
||||
quota_service.increment_total_service_use()
|
||||
$$ LANGUAGE plpythonu;
|
||||
@@ -476,3 +476,54 @@ RETURNS NUMERIC AS $$
|
||||
finally:
|
||||
quota_service.increment_total_service_use()
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetMeasureById(
|
||||
username TEXT,
|
||||
orgname TEXT,
|
||||
geom_ref TEXT,
|
||||
measure_id TEXT,
|
||||
boundary_id TEXT,
|
||||
time_span TEXT DEFAULT NULL)
|
||||
RETURNS NUMERIC AS $$
|
||||
CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname);
|
||||
SELECT cdb_observatory.OBS_GetMeasureById(geom_ref, measure_id, boundary_id, time_span);
|
||||
$$ LANGUAGE plproxy;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetMeasureById(
|
||||
username TEXT,
|
||||
orgname TEXT,
|
||||
geom_ref TEXT,
|
||||
measure_id TEXT,
|
||||
boundary_id TEXT,
|
||||
time_span TEXT DEFAULT NULL)
|
||||
RETURNS NUMERIC AS $$
|
||||
from cartodb_services.metrics import QuotaService
|
||||
|
||||
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_obs_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||
user_obs_config = GD["user_obs_config_{0}".format(username)]
|
||||
|
||||
quota_service = QuotaService(user_obs_config, redis_conn)
|
||||
if not quota_service.check_user_quota():
|
||||
plpy.error('You have reached the limit of your quota')
|
||||
|
||||
try:
|
||||
obs_plan = plpy.prepare("SELECT cdb_dataservices_server._OBS_GetMeasureById($1, $2, $3, $4, $5, $6) as measure;", ["text", "text", "text", "text", "text", "text"])
|
||||
result = plpy.execute(obs_plan, [username, orgname, geom_ref, measure_id, boundary_id, time_span])
|
||||
if result:
|
||||
quota_service.increment_success_service_use()
|
||||
return result[0]['measure']
|
||||
else:
|
||||
quota_service.increment_empty_service_use()
|
||||
return None
|
||||
except BaseException as e:
|
||||
import sys, traceback
|
||||
type_, value_, traceback_ = sys.exc_info()
|
||||
quota_service.increment_failed_service_use()
|
||||
error_msg = 'There was an error trying to use OBS_GetMeasureById: {0}'.format(e)
|
||||
plpy.notice(traceback.format_tb(traceback_))
|
||||
plpy.error(error_msg)
|
||||
finally:
|
||||
quota_service.increment_total_service_use()
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
@@ -12,6 +12,20 @@ RETURNS boolean AS $$
|
||||
return True
|
||||
$$ LANGUAGE plpythonu SECURITY DEFINER;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._get_mapzen_geocoder_config(username text, orgname text)
|
||||
RETURNS boolean AS $$
|
||||
cache_key = "user_mapzen_geocoder_config_{0}".format(username)
|
||||
if cache_key in GD:
|
||||
return False
|
||||
else:
|
||||
from cartodb_services.metrics import MapzenGeocoderConfig
|
||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metadata_connection']
|
||||
mapzen_geocoder_config = MapzenGeocoderConfig(redis_conn, plpy, username, orgname)
|
||||
GD[cache_key] = mapzen_geocoder_config
|
||||
return True
|
||||
$$ LANGUAGE plpythonu SECURITY DEFINER;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._get_internal_geocoder_config(username text, orgname text)
|
||||
RETURNS boolean AS $$
|
||||
cache_key = "user_internal_geocoder_config_{0}".format(username)
|
||||
|
||||
@@ -20,6 +20,50 @@ RETURNS Geometry AS $$
|
||||
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_here_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
RETURNS Geometry AS $$
|
||||
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)]
|
||||
|
||||
if user_geocoder_config.heremaps_geocoder:
|
||||
here_plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_here_geocode_street_point($1, $2, $3, $4, $5, $6) as point; ", ["text", "text", "text", "text", "text", "text"])
|
||||
return plpy.execute(here_plan, [username, orgname, searchtext, city, state_province, country], 1)[0]['point']
|
||||
else:
|
||||
plpy.error('Here geocoder is not available for your account.')
|
||||
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_google_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
RETURNS Geometry AS $$
|
||||
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)]
|
||||
|
||||
if user_geocoder_config.google_geocoder:
|
||||
google_plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_google_geocode_street_point($1, $2, $3, $4, $5, $6) as point; ", ["text", "text", "text", "text", "text", "text"])
|
||||
return plpy.execute(google_plan, [username, orgname, searchtext, city, state_province, country], 1)[0]['point']
|
||||
else:
|
||||
plpy.error('Google geocoder is not available for your account.')
|
||||
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_mapzen_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
RETURNS Geometry AS $$
|
||||
# The configuration is retrieved but no checks are performed on it
|
||||
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_mapzen_geocoder_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||
user_geocoder_config = GD["user_mapzen_geocoder_config_{0}".format(username)]
|
||||
|
||||
mapzen_plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_mapzen_geocode_street_point($1, $2, $3, $4, $5, $6) as point; ", ["text", "text", "text", "text", "text", "text"])
|
||||
return plpy.execute(mapzen_plan, [username, orgname, searchtext, city, state_province, country], 1)[0]['point']
|
||||
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_here_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
RETURNS Geometry AS $$
|
||||
from cartodb_services.here import HereMapsGeocoder
|
||||
@@ -93,13 +137,13 @@ RETURNS Geometry AS $$
|
||||
from cartodb_services.metrics import QuotaService
|
||||
|
||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||
user_geocoder_config = GD["user_geocoder_config_{0}".format(username)]
|
||||
quota_service = QuotaService(user_geocoder_config, redis_conn)
|
||||
user_mapzen_geocoder_config = GD["user_mapzen_geocoder_config_{0}".format(username)]
|
||||
quota_service = QuotaService(user_mapzen_geocoder_config, redis_conn)
|
||||
if not quota_service.check_user_quota():
|
||||
plpy.error('You have reached the limit of your quota')
|
||||
|
||||
try:
|
||||
geocoder = MapzenGeocoder(user_geocoder_config.mapzen_api_key)
|
||||
geocoder = MapzenGeocoder(user_mapzen_geocoder_config.mapzen_api_key)
|
||||
country_iso3 = None
|
||||
if country:
|
||||
country_iso3 = country_to_iso3(country)
|
||||
|
||||
@@ -31,6 +31,17 @@ SELECT exists(SELECT *
|
||||
t
|
||||
(1 row)
|
||||
|
||||
SELECT exists(SELECT *
|
||||
FROM pg_proc p
|
||||
INNER JOIN pg_namespace ns ON (p.pronamespace = ns.oid)
|
||||
WHERE ns.nspname = 'cdb_dataservices_server'
|
||||
AND proname = 'obs_getmeasurebyid'
|
||||
AND oidvectortypes(p.proargtypes) = 'text, text, text, text, text, text');
|
||||
exists
|
||||
--------
|
||||
t
|
||||
(1 row)
|
||||
|
||||
SELECT exists(SELECT *
|
||||
FROM pg_proc p
|
||||
INNER JOIN pg_namespace ns ON (p.pronamespace = ns.oid)
|
||||
|
||||
@@ -19,6 +19,13 @@ SELECT exists(SELECT *
|
||||
AND proname = 'obs_getmeasure'
|
||||
AND oidvectortypes(p.proargtypes) = 'text, text, geometry, text, text, text, text');
|
||||
|
||||
SELECT exists(SELECT *
|
||||
FROM pg_proc p
|
||||
INNER JOIN pg_namespace ns ON (p.pronamespace = ns.oid)
|
||||
WHERE ns.nspname = 'cdb_dataservices_server'
|
||||
AND proname = 'obs_getmeasurebyid'
|
||||
AND oidvectortypes(p.proargtypes) = 'text, text, text, text, text, text');
|
||||
|
||||
SELECT exists(SELECT *
|
||||
FROM pg_proc p
|
||||
INNER JOIN pg_namespace ns ON (p.pronamespace = ns.oid)
|
||||
|
||||
5
server/extension/upgrade_downgrade_template.erb
Normal file
5
server/extension/upgrade_downgrade_template.erb
Normal file
@@ -0,0 +1,5 @@
|
||||
--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 '<%= version %>'" to load this file. \quit
|
||||
|
||||
-- HERE goes your code to upgrade/downgrade
|
||||
50
server/lib/python/cartodb_services/README.md
Normal file
50
server/lib/python/cartodb_services/README.md
Normal file
@@ -0,0 +1,50 @@
|
||||
# CartoDB dataservices API python module
|
||||
|
||||
This directory contains the python library used by the server side of CartoDB LDS (Location Data Services).
|
||||
|
||||
It is used from pl/python functions contained in the `cdb_dataservices_server` extension. It goes hand in hand with the extension so please consider running the integration tests.
|
||||
|
||||
On the other hand, it is pretty independent from the client, as long as the signatures of the public pl/python functions match.
|
||||
|
||||
## Dependencies
|
||||
See the [[`requirements.txt`]] or better the Basically:
|
||||
- pip
|
||||
- redis and hiredis
|
||||
- dateutil
|
||||
- googlemaps
|
||||
- request
|
||||
|
||||
## Installation
|
||||
Install the requirements:
|
||||
```shell
|
||||
sudo pip install -r requirements.txt
|
||||
```
|
||||
|
||||
Install the library:
|
||||
```shell
|
||||
sudo pip install .
|
||||
```
|
||||
|
||||
NOTE: a system installation is required at present because the library is meant to be used from postgres pl/python, which runs an embedded python interpreter.
|
||||
|
||||
|
||||
## Running the unit tests
|
||||
Just run `nosetests`
|
||||
```shell
|
||||
$ nosetests
|
||||
.................................................
|
||||
----------------------------------------------------------------------
|
||||
Ran 49 tests in 0.131s
|
||||
|
||||
OK
|
||||
```
|
||||
|
||||
## Running the integration tests
|
||||
See the [[../../../../test/README.md]]. Basically, move to the `/test` directory at the top level of this repo and execute the `run_tests.py` script:
|
||||
```sh
|
||||
cd $(git rev-parse --show-toplevel)/test
|
||||
python run_tests.py --host=$YOUR_HOST $YOUR_USERNAME $YOUR_API_KEY
|
||||
```
|
||||
|
||||
## TODO
|
||||
- Move dependencies expressed in `requirements.txt` to `setup.py`
|
||||
@@ -1,3 +1,3 @@
|
||||
from config import GeocoderConfig, IsolinesRoutingConfig, InternalGeocoderConfig, RoutingConfig, ConfigException, ObservatorySnapshotConfig, ObservatoryConfig
|
||||
from config import GeocoderConfig, MapzenGeocoderConfig, IsolinesRoutingConfig, InternalGeocoderConfig, RoutingConfig, ConfigException, ObservatorySnapshotConfig, ObservatoryConfig
|
||||
from quota import QuotaService
|
||||
from user import UserMetricsService
|
||||
|
||||
@@ -128,6 +128,60 @@ class RoutingConfig(ServiceConfig):
|
||||
def period_end_date(self):
|
||||
return self._period_end_date
|
||||
|
||||
# Explicit class for the geocoder configuration for Mapzen
|
||||
# which does not require users to be configured to use the service
|
||||
class MapzenGeocoderConfig(ServiceConfig):
|
||||
|
||||
PERIOD_END_DATE = 'period_end_date'
|
||||
|
||||
def __init__(self, redis_connection, db_conn, username, orgname=None):
|
||||
super(MapzenGeocoderConfig, self).__init__(redis_connection, db_conn,
|
||||
username, orgname)
|
||||
self._log_path = self._db_config.geocoder_log_path
|
||||
try:
|
||||
self._mapzen_api_key = self._db_config.mapzen_geocoder_api_key
|
||||
self._monthly_quota = self._db_config.mapzen_geocoder_monthly_quota
|
||||
self._period_end_date = date_parse(self._redis_config[self.PERIOD_END_DATE])
|
||||
self._cost_per_hit = 0
|
||||
except Exception as e:
|
||||
raise ConfigException("Malformed config for Mapzen geocoder: {1}".format(key, e))
|
||||
|
||||
@property
|
||||
def service_type(self):
|
||||
return 'geocoder_mapzen'
|
||||
|
||||
@property
|
||||
def mapzen_api_key(self):
|
||||
return self._mapzen_api_key
|
||||
|
||||
@property
|
||||
def period_end_date(self):
|
||||
return self._period_end_date
|
||||
|
||||
@property
|
||||
def cost_per_hit(self):
|
||||
return self._cost_per_hit
|
||||
|
||||
@property
|
||||
def google_geocoder(self):
|
||||
return None
|
||||
|
||||
@property
|
||||
def geocoding_quota(self):
|
||||
return self._monthly_quota
|
||||
|
||||
@property
|
||||
def soft_geocoding_limit(self):
|
||||
return False
|
||||
|
||||
@property
|
||||
def is_high_resolution(self):
|
||||
return True
|
||||
|
||||
@property
|
||||
def log_path(self):
|
||||
return self._log_path
|
||||
|
||||
|
||||
class IsolinesRoutingConfig(ServiceConfig):
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ class UserMetricsService:
|
||||
SERVICE_GEOCODER_NOKIA = 'geocoder_here'
|
||||
SERVICE_GEOCODER_CACHE = 'geocoder_cache'
|
||||
SERVICE_HERE_ISOLINES = 'here_isolines'
|
||||
DAY_OF_MONTH_ZERO_PADDED = '%d'
|
||||
|
||||
def __init__(self, user_geocoder_config, redis_connection):
|
||||
self._user_geocoder_config = user_geocoder_config
|
||||
@@ -85,6 +86,11 @@ class UserMetricsService:
|
||||
service, metric, date)
|
||||
score = self._redis_connection.zscore(redis_prefix, date.day)
|
||||
aggregated_metric += score if score else 0
|
||||
zero_padded_day = date.strftime(self.DAY_OF_MONTH_ZERO_PADDED)
|
||||
if str(date.day) != zero_padded_day:
|
||||
score = self._redis_connection.zscore(redis_prefix, zero_padded_day)
|
||||
aggregated_metric += score if score else 0
|
||||
|
||||
return aggregated_metric
|
||||
|
||||
# Private functions
|
||||
@@ -92,12 +98,16 @@ class UserMetricsService:
|
||||
def __increment_user_uses(self, service_type, metric, date, amount):
|
||||
redis_prefix = self.__parse_redis_prefix("user", self._username,
|
||||
service_type, metric, date)
|
||||
self._redis_connection.zincrby(redis_prefix, date.day, amount)
|
||||
self._redis_connection.zincrby(redis_prefix,
|
||||
date.strftime(self.DAY_OF_MONTH_ZERO_PADDED),
|
||||
amount)
|
||||
|
||||
def __increment_organization_uses(self, service_type, metric, date, amount):
|
||||
redis_prefix = self.__parse_redis_prefix("org", self._orgname,
|
||||
service_type, metric, date)
|
||||
self._redis_connection.zincrby(redis_prefix, date.day, amount)
|
||||
self._redis_connection.zincrby(redis_prefix,
|
||||
date.strftime(self.DAY_OF_MONTH_ZERO_PADDED),
|
||||
amount)
|
||||
|
||||
def __parse_redis_prefix(self, prefix, entity_name, service_type, metric,
|
||||
date):
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
redis==2.10.5
|
||||
hiredis==0.1.5
|
||||
# Dependency with incsv in the import
|
||||
python-dateutil==2.2
|
||||
googlemaps==2.4.2
|
||||
# Dependency for googlemaps package
|
||||
@@ -11,3 +10,4 @@ mock==1.3.0
|
||||
mockredispy==2.9.0.11
|
||||
nose==1.3.7
|
||||
requests-mock==0.7.0
|
||||
freezegun==0.3.7
|
||||
|
||||
@@ -10,11 +10,11 @@ from setuptools import setup, find_packages
|
||||
setup(
|
||||
name='cartodb_services',
|
||||
|
||||
version='0.6.2',
|
||||
version='0.6.5',
|
||||
|
||||
description='CartoDB Services API Python Library',
|
||||
|
||||
url='https://github.com/CartoDB/geocoder-api',
|
||||
url='https://github.com/CartoDB/dataservices-api',
|
||||
|
||||
author='Data Services Team - CartoDB',
|
||||
author_email='dataservices@cartodb.com',
|
||||
|
||||
@@ -7,6 +7,7 @@ from unittest import TestCase
|
||||
from mock import Mock
|
||||
from nose.tools import assert_raises
|
||||
from datetime import timedelta
|
||||
from freezegun import freeze_time
|
||||
|
||||
|
||||
class TestUserService(TestCase):
|
||||
@@ -75,9 +76,65 @@ class TestUserService(TestCase):
|
||||
us.increment_service_use(self.NOKIA_GEOCODER, 'fail_responses')
|
||||
assert us.used_quota(self.NOKIA_GEOCODER, date.today()) == 2
|
||||
|
||||
@freeze_time("2015-06-01")
|
||||
def test_should_account_for_zero_paddded_keys(self):
|
||||
us = self.__build_user_service('test_user')
|
||||
self.redis_conn.zincrby('user:test_user:geocoder_here:success_responses:201506', '01', 400)
|
||||
assert us.used_quota(self.NOKIA_GEOCODER, date(2015, 6,1)) == 400
|
||||
|
||||
@freeze_time("2015-06-01")
|
||||
def test_should_account_for_wrongly_stored_non_padded_keys(self):
|
||||
us = self.__build_user_service('test_user')
|
||||
self.redis_conn.zincrby('user:test_user:geocoder_here:success_responses:201506', '1', 400)
|
||||
assert us.used_quota(self.NOKIA_GEOCODER, date(2015, 6,1)) == 400
|
||||
|
||||
@freeze_time("2015-06-01")
|
||||
def test_should_sum_amounts_from_both_key_formats(self):
|
||||
us = self.__build_user_service('test_user')
|
||||
self.redis_conn.zincrby('user:test_user:geocoder_here:success_responses:201506', '1', 400)
|
||||
self.redis_conn.zincrby('user:test_user:geocoder_here:success_responses:201506', '01', 300)
|
||||
assert us.used_quota(self.NOKIA_GEOCODER, date(2015, 6,1)) == 700
|
||||
|
||||
@freeze_time("2015-06-15")
|
||||
def test_should_not_request_redis_twice_when_unneeded(self):
|
||||
class MockRedisWithCounter(MockRedis):
|
||||
def __init__(self):
|
||||
super(MockRedisWithCounter, self).__init__()
|
||||
self._zscore_counter = 0
|
||||
def zscore(self, *args):
|
||||
print args
|
||||
self._zscore_counter += 1
|
||||
return super(MockRedisWithCounter, self).zscore(*args)
|
||||
def zscore_counter(self):
|
||||
return self._zscore_counter
|
||||
self.redis_conn = MockRedisWithCounter()
|
||||
us = self.__build_user_service('test_user', end_date=date.today())
|
||||
us.used_quota(self.NOKIA_GEOCODER, date(2015, 6, 15))
|
||||
|
||||
#('user:test_user:geocoder_here:success_responses:201506', 15)
|
||||
#('user:test_user:geocoder_here:empty_responses:201506', 15)
|
||||
#('user:test_user:geocoder_cache:success_responses:201506', 15)
|
||||
assert self.redis_conn.zscore_counter() == 3
|
||||
|
||||
def test_should_write_zero_padded_dates(self):
|
||||
us = self.__build_user_service('test_user')
|
||||
us.increment_service_use(self.NOKIA_GEOCODER, 'success_responses',
|
||||
date=date(2015,6,1))
|
||||
assert self.redis_conn.zscore('user:test_user:geocoder_here:success_responses:201506', '01') == 1
|
||||
assert self.redis_conn.zscore('user:test_user:geocoder_here:success_responses:201506', '1') == None
|
||||
|
||||
def test_orgs_should_write_zero_padded_dates(self):
|
||||
us = self.__build_user_service('test_user', orgname='test_org')
|
||||
us.increment_service_use(self.NOKIA_GEOCODER, 'success_responses',
|
||||
amount=400,
|
||||
date=date(2015,6,1))
|
||||
assert self.redis_conn.zscore('org:test_org:geocoder_here:success_responses:201506', '01') == 400
|
||||
assert self.redis_conn.zscore('org:test_org:geocoder_here:success_responses:201506', '1') == None
|
||||
|
||||
|
||||
def __build_user_service(self, username, quota=100, service='heremaps',
|
||||
orgname=None, soft_limit=False,
|
||||
end_date=datetime.today()):
|
||||
end_date=date.today()):
|
||||
test_helper.build_redis_user_config(self.redis_conn, username,
|
||||
quota=quota, service=service,
|
||||
soft_limit=soft_limit,
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
This are the automatic integration tests for geocoder api (both client and server)
|
||||
|
||||
### Usage
|
||||
In order to execute the tests you have to execute the `run_tests` python script:
|
||||
In order to execute the tests you have to execute the `run_tests.py` python script:
|
||||
|
||||
``` python run_tests.py [--host=cartodb.com] username api_key```
|
||||
```sh
|
||||
python run_tests.py [--host=cartodb.com] username api_key
|
||||
```
|
||||
|
||||
You can define the host where is going to execute the SQL API queries to test the
|
||||
geocoder API. By default the value is `cartodb.com` but you can put the host you need.
|
||||
@@ -19,3 +21,34 @@ This suite of tests test the following parts of the geocoding API through the SQ
|
||||
- Postal code functions
|
||||
- Ip address functions
|
||||
- Street address functions (This will call Heremaps or Google so it will cost you 2 credits)
|
||||
- Routing functions
|
||||
- Isolines functions
|
||||
- Data Observatory functions
|
||||
|
||||
|
||||
### How to debug the tests
|
||||
You won't be able to plug a debugger when using the `run_test.py` because of the usage of a subprocess and the piping.
|
||||
|
||||
You should be aware that some tests require some extra setup (a test table), that you'll need to do on your own in some cases (check the `ImportHelper.import_test_dataset`)
|
||||
|
||||
In order to do so, you need to use plain `nosetests` which comes prepared to that.
|
||||
|
||||
First, add this to the python test code:
|
||||
|
||||
```python
|
||||
from nose.tools import set_trace; set_trace()
|
||||
```
|
||||
|
||||
Secondly, execute just your test with this:
|
||||
|
||||
```ssh
|
||||
GEOCODER_API_TEST_USERNAME=your_username \
|
||||
GEOCODER_API_TEST_API_KEY=your_api_key \
|
||||
GEOCODER_API_TEST_TABLE_NAME=your_test_table \
|
||||
GEOCODER_API_TEST_HOST=your_target_test_host \
|
||||
nosetests --where=integration/ test_data_observatory_functions.py:TestDataObservatoryFunctions.test_if_obs_search_is_ok
|
||||
```
|
||||
|
||||
(replace the environment variables, test file, class and function according to your needs)
|
||||
|
||||
TODO: we need to refactor the test code a little to avoid these hindrances
|
||||
|
||||
@@ -57,6 +57,19 @@ class TestDataObservatoryFunctions(TestCase):
|
||||
except Exception as e:
|
||||
assert_equal(e.message[0], "The api_key must be provided")
|
||||
|
||||
def test_if_get_measure_by_id_ok(self):
|
||||
query = "SELECT OBS_GetMeasureById('36047048500', 'us.census.acs.B01003001', 'us.census.tiger.census_tract', '2010 - 2014') as measure;&api_key={0}".format(self.env_variables['api_key'])
|
||||
result = IntegrationTestHelper.execute_query(self.sql_api_url, query)
|
||||
assert_not_equal(result['measure'], None)
|
||||
assert_equal(result['measure'], 3241)
|
||||
|
||||
def test_if_get_measure_by_id_without_api_key_raise_error(self):
|
||||
query = "SELECT OBS_GetMeasureById('36047048500', 'us.census.acs.B01003001', 'us.census.tiger.census_tract', '2010 - 2014') as measure"
|
||||
try:
|
||||
IntegrationTestHelper.execute_query(self.sql_api_url, query)
|
||||
except Exception as e:
|
||||
assert_equal(e.message[0], "The api_key must be provided")
|
||||
|
||||
def test_if_get_category_is_ok(self):
|
||||
query = "SELECT OBS_GetCategory(CDB_LatLng(40.704512, -73.936669), 'us.census.spielman_singleton_segments.X10', 'us.census.tiger.census_tract', '2010 - 2014') as category;&api_key={0}".format(self.env_variables['api_key'])
|
||||
result = IntegrationTestHelper.execute_query(self.sql_api_url, query)
|
||||
@@ -116,7 +129,9 @@ class TestDataObservatoryFunctions(TestCase):
|
||||
assert_equal(e.message[0], "The api_key must be provided")
|
||||
|
||||
def test_if_obs_search_is_ok(self):
|
||||
query = "SELECT id FROM OBS_Search('total_pop') LIMIT 1;&api_key={0}".format(self.env_variables['api_key'])
|
||||
sql = "SELECT id FROM OBS_Search('total_pop') WHERE id LIKE 'es.ine%' LIMIT 1;"
|
||||
import urllib
|
||||
query = "{0}&api_key={1}".format(urllib.quote(sql), self.env_variables['api_key'])
|
||||
result = IntegrationTestHelper.execute_query(self.sql_api_url, query)
|
||||
assert_not_equal(result['id'], None)
|
||||
assert_equal(result['id'], 'es.ine.t1_1')
|
||||
|
||||
@@ -35,7 +35,7 @@ class TestRoutingFunctions(TestCase):
|
||||
|
||||
def test_if_select_with_routing_with_waypoints_is_ok(self):
|
||||
query = "SELECT duration, length, shape as the_geom " \
|
||||
"FROM cdb_route_with_waypoints('Array['POINT(-3.7109 40.4234)'::GEOMETRY, "\
|
||||
"FROM cdb_route_with_waypoints(Array['POINT(-3.7109 40.4234)'::GEOMETRY, "\
|
||||
"'POINT(-3.7059 40.4203)'::geometry, 'POINT(-3.7046 40.4180)'::geometry]" \
|
||||
"::geometry[], 'car', " \
|
||||
"ARRAY['mode_type=shortest']::text[])&api_key={0}".format(
|
||||
@@ -45,7 +45,7 @@ class TestRoutingFunctions(TestCase):
|
||||
|
||||
def test_if_select_with_routing_with_waypoints_without_api_key_raise_error(self):
|
||||
query = "SELECT duration, length, shape as the_geom " \
|
||||
"FROM cdb_route_with_waypoints('Array['POINT(-3.7109 40.4234)'::GEOMETRY, "\
|
||||
"FROM cdb_route_with_waypoints(Array['POINT(-3.7109 40.4234)'::GEOMETRY, "\
|
||||
"'POINT(-3.7059 40.4203)'::geometry, 'POINT(-3.7046 40.4180)'::geometry]" \
|
||||
"::geometry[], 'car', " \
|
||||
"ARRAY['mode_type=shortest']::text[])&api_key={0}"
|
||||
|
||||
@@ -22,6 +22,14 @@ class TestStreetFunctions(TestCase):
|
||||
geometry = IntegrationTestHelper.execute_query(self.sql_api_url, query)
|
||||
assert_not_equal(geometry['geometry'], None)
|
||||
|
||||
def test_if_select_with_mapzen_provider_street_point_is_ok(self):
|
||||
query = "SELECT cdb_mapzen_geocode_street_point(street) " \
|
||||
"as geometry FROM {0} LIMIT 1&api_key={1}".format(
|
||||
self.env_variables['table_name'],
|
||||
self.env_variables['api_key'])
|
||||
geometry = IntegrationTestHelper.execute_query(self.sql_api_url, query)
|
||||
assert_not_equal(geometry['geometry'], None)
|
||||
|
||||
def test_if_select_with_street_without_api_key_raise_error(self):
|
||||
query = "SELECT cdb_geocode_street_point(street) " \
|
||||
"as geometry FROM {0} LIMIT 1".format(
|
||||
|
||||
Reference in New Issue
Block a user