Maintain old snapshot functions to avoid break compatibility
This commit is contained in:
parent
8680c9cbd0
commit
5d6c3d7b11
@ -93,14 +93,14 @@
|
||||
return_type: json
|
||||
params:
|
||||
- { name: geom, type: "geometry(Geometry, 4326)" }
|
||||
- { name: time_span, type: "text", default: 'NULL' }
|
||||
- { name: geometry_level, type: text, default: 'NULL' }
|
||||
- { name: time_span, type: "text", default: "'2009 - 2013'::text" }
|
||||
- { name: geometry_level, type: text, default: "'\"us.census.tiger\".block_group'::text" }
|
||||
|
||||
- name: obs_get_segment_snapshot
|
||||
return_type: json
|
||||
params:
|
||||
- { name: geom, type: "geometry(Geometry, 4326)" }
|
||||
- { name: geometry_level, type: text, default: 'NULL' }
|
||||
- { name: geometry_level, type: text, default: "'\"us.census.tiger\".census_tract'::text" }
|
||||
|
||||
- name: obs_getdemographicsnapshot
|
||||
return_type: SETOF JSON
|
||||
|
@ -18,6 +18,56 @@ RETURNS boolean AS $$
|
||||
return True
|
||||
$$ LANGUAGE plpythonu SECURITY DEFINER;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetDemographicSnapshotJSON(
|
||||
username TEXT,
|
||||
orgname TEXT,
|
||||
geom geometry(Geometry, 4326),
|
||||
time_span TEXT DEFAULT NULL,
|
||||
geometry_level TEXT DEFAULT NULL)
|
||||
RETURNS json AS $$
|
||||
CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname);
|
||||
SELECT cdb_observatory.OBS_GetDemographicSnapshot(geom, time_span, geometry_level);
|
||||
$$ LANGUAGE plproxy;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.obs_get_demographic_snapshot(
|
||||
username TEXT,
|
||||
orgname TEXT,
|
||||
geom geometry(Geometry, 4326),
|
||||
time_span TEXT DEFAULT NULL,
|
||||
geometry_level TEXT DEFAULT NULL)
|
||||
RETURNS json AS $$
|
||||
from cartodb_services.metrics import QuotaService
|
||||
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_obs_snapshot_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||
user_obs_snapshot_config = GD["user_obs_snapshot_config_{0}".format(username)]
|
||||
|
||||
quota_service = QuotaService(user_obs_snapshot_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_GetDemographicSnapshotJSON($1, $2, $3, $4, $5) as snapshot;", ["text", "text", "geometry(Geometry, 4326)", "text", "text"])
|
||||
result = plpy.execute(obs_plan, [username, orgname, geom, time_span, geometry_level])
|
||||
if result:
|
||||
quota_service.increment_success_service_use()
|
||||
return result[0]['snapshot']
|
||||
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 get_geographic_snapshot: {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._OBS_GetDemographicSnapshot(
|
||||
username TEXT,
|
||||
orgname TEXT,
|
||||
@ -71,6 +121,54 @@ RETURNS SETOF JSON AS $$
|
||||
quota_service.increment_total_service_use()
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetSegmentSnapshotJSON(
|
||||
username TEXT,
|
||||
orgname TEXT,
|
||||
geom geometry(Geometry, 4326),
|
||||
geometry_level TEXT DEFAULT NULL)
|
||||
RETURNS json AS $$
|
||||
CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname);
|
||||
SELECT cdb_observatory.OBS_GetSegmentSnapshot(geom, geometry_level);
|
||||
$$ LANGUAGE plproxy;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.obs_get_segment_snapshot(
|
||||
username TEXT,
|
||||
orgname TEXT,
|
||||
geom geometry(Geometry, 4326),
|
||||
geometry_level TEXT DEFAULT NULL)
|
||||
RETURNS json AS $$
|
||||
from cartodb_services.metrics import QuotaService
|
||||
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_obs_snapshot_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||
user_obs_snapshot_config = GD["user_obs_snapshot_config_{0}".format(username)]
|
||||
|
||||
quota_service = QuotaService(user_obs_snapshot_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_GetSegmentSnapshotJSON($1, $2, $3, $4) as snapshot;", ["text", "text", "geometry(Geometry, 4326)", "text"])
|
||||
result = plpy.execute(obs_plan, [username, orgname, geom, geometry_level])
|
||||
if result:
|
||||
quota_service.increment_success_service_use()
|
||||
return result[0]['snapshot']
|
||||
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 get_segment_snapshot: {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._OBS_GetSegmentSnapshot(
|
||||
username TEXT,
|
||||
orgname TEXT,
|
||||
|
@ -4,8 +4,10 @@
|
||||
|
||||
DROP FUNCTION IF EXISTS cdb_dataservices_server._get_obs_config(text, text);
|
||||
DROP FUNCTION IF EXISTS cdb_dataservices_server._OBS_GetDemographicSnapshot(text, text, geometry(Geometry, 4326), text, text);
|
||||
DROP FUNCTION IF EXISTS cdb_dataservices_server._OBS_GetDemographicSnapshotJSON(text, text, geometry(Geometry, 4326), text, text);
|
||||
DROP FUNCTION IF EXISTS cdb_dataservices_server.OBS_GetDemographicSnapshot(TEXT, TEXT, geometry(Geometry, 4326), TEXT, TEXT);
|
||||
DROP FUNCTION IF EXISTS cdb_dataservices_server._OBS_GetSegmentSnapshot(text, text, geometry(Geometry, 4326), text);
|
||||
DROP FUNCTION IF EXISTS cdb_dataservices_server._OBS_GetSegmentSnapshotJSON(text, text, geometry(Geometry, 4326), text);
|
||||
DROP FUNCTION IF EXISTS cdb_dataservices_server.OBS_GetSegmentSnapshot(TEXT, TEXT, geometry(Geometry, 4326), TEXT);
|
||||
DROP FUNCTION IF EXISTS cdb_dataservices_server.OBS_GetMeasure(TEXT, TEXT, geometry(Geometry, 4326), TEXT, TEXT, TEXT, TEXT);
|
||||
DROP FUNCTION IF EXISTS cdb_dataservices_server._OBS_GetMeasure(TEXT, TEXT, geometry(Geometry, 4326), TEXT, TEXT, TEXT, TEXT);
|
||||
@ -56,4 +58,81 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetSegmentSnapshot(
|
||||
RETURNS json AS $$
|
||||
CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname);
|
||||
SELECT cdb_observatory.OBS_GetSegmentSnapshot(geom, geometry_level);
|
||||
$$ LANGUAGE plproxy;
|
||||
$$ LANGUAGE plproxy;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.obs_get_demographic_snapshot(
|
||||
username TEXT,
|
||||
orgname TEXT,
|
||||
geom geometry(Geometry, 4326),
|
||||
time_span TEXT DEFAULT '2009 - 2013',
|
||||
geometry_level TEXT DEFAULT '"us.census.tiger".block_group')
|
||||
RETURNS json AS $$
|
||||
from cartodb_services.metrics import QuotaService
|
||||
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_obs_snapshot_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||
user_obs_snapshot_config = GD["user_obs_snapshot_config_{0}".format(username)]
|
||||
|
||||
quota_service = QuotaService(user_obs_snapshot_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_GetDemographicSnapshot($1, $2, $3, $4, $5) as snapshot;", ["text", "text", "geometry(Geometry, 4326)", "text", "text"])
|
||||
result = plpy.execute(obs_plan, [username, orgname, geom, time_span, geometry_level])
|
||||
if result:
|
||||
quota_service.increment_success_service_use()
|
||||
return result[0]['snapshot']
|
||||
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 get_geographic_snapshot: {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.obs_get_segment_snapshot(
|
||||
username TEXT,
|
||||
orgname TEXT,
|
||||
geom geometry(Geometry, 4326),
|
||||
geometry_level TEXT DEFAULT '"us.census.tiger".block_group')
|
||||
RETURNS json AS $$
|
||||
from cartodb_services.metrics import QuotaService
|
||||
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_obs_snapshot_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||
user_obs_snapshot_config = GD["user_obs_snapshot_config_{0}".format(username)]
|
||||
|
||||
quota_service = QuotaService(user_obs_snapshot_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_GetSegmentSnapshot($1, $2, $3, $4) as snapshot;", ["text", "text", "geometry(Geometry, 4326)", "text"])
|
||||
result = plpy.execute(obs_plan, [username, orgname, geom, geometry_level])
|
||||
if result:
|
||||
quota_service.increment_success_service_use()
|
||||
return result[0]['snapshot']
|
||||
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 get_segment_snapshot: {0}'.format(e)
|
||||
plpy.notice(traceback.format_tb(traceback_))
|
||||
plpy.error(error_msg)
|
||||
finally:
|
||||
quota_service.increment_total_service_use()
|
||||
$$ LANGUAGE plpythonu;
|
@ -16,6 +16,56 @@ RETURNS text AS $$
|
||||
return user_obs_snapshot_config.connection_str
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetDemographicSnapshotJSON(
|
||||
username TEXT,
|
||||
orgname TEXT,
|
||||
geom geometry(Geometry, 4326),
|
||||
time_span TEXT DEFAULT NULL,
|
||||
geometry_level TEXT DEFAULT NULL)
|
||||
RETURNS json AS $$
|
||||
CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname);
|
||||
SELECT cdb_observatory.OBS_GetDemographicSnapshot(geom, time_span, geometry_level);
|
||||
$$ LANGUAGE plproxy;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.obs_get_demographic_snapshot(
|
||||
username TEXT,
|
||||
orgname TEXT,
|
||||
geom geometry(Geometry, 4326),
|
||||
time_span TEXT DEFAULT NULL,
|
||||
geometry_level TEXT DEFAULT NULL)
|
||||
RETURNS json AS $$
|
||||
from cartodb_services.metrics import QuotaService
|
||||
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_obs_snapshot_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||
user_obs_snapshot_config = GD["user_obs_snapshot_config_{0}".format(username)]
|
||||
|
||||
quota_service = QuotaService(user_obs_snapshot_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_GetDemographicSnapshotJSON($1, $2, $3, $4, $5) as snapshot;", ["text", "text", "geometry(Geometry, 4326)", "text", "text"])
|
||||
result = plpy.execute(obs_plan, [username, orgname, geom, time_span, geometry_level])
|
||||
if result:
|
||||
quota_service.increment_success_service_use()
|
||||
return result[0]['snapshot']
|
||||
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 get_geographic_snapshot: {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._OBS_GetDemographicSnapshot(
|
||||
username TEXT,
|
||||
orgname TEXT,
|
||||
@ -69,6 +119,54 @@ RETURNS SETOF JSON AS $$
|
||||
quota_service.increment_total_service_use()
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetSegmentSnapshotJSON(
|
||||
username TEXT,
|
||||
orgname TEXT,
|
||||
geom geometry(Geometry, 4326),
|
||||
geometry_level TEXT DEFAULT NULL)
|
||||
RETURNS json AS $$
|
||||
CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname);
|
||||
SELECT cdb_observatory.OBS_GetSegmentSnapshot(geom, geometry_level);
|
||||
$$ LANGUAGE plproxy;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.obs_get_segment_snapshot(
|
||||
username TEXT,
|
||||
orgname TEXT,
|
||||
geom geometry(Geometry, 4326),
|
||||
geometry_level TEXT DEFAULT NULL)
|
||||
RETURNS json AS $$
|
||||
from cartodb_services.metrics import QuotaService
|
||||
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_obs_snapshot_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||
user_obs_snapshot_config = GD["user_obs_snapshot_config_{0}".format(username)]
|
||||
|
||||
quota_service = QuotaService(user_obs_snapshot_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_GetSegmentSnapshotJSON($1, $2, $3, $4) as snapshot;", ["text", "text", "geometry(Geometry, 4326)", "text"])
|
||||
result = plpy.execute(obs_plan, [username, orgname, geom, geometry_level])
|
||||
if result:
|
||||
quota_service.increment_success_service_use()
|
||||
return result[0]['snapshot']
|
||||
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 get_segment_snapshot: {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._OBS_GetSegmentSnapshot(
|
||||
username TEXT,
|
||||
orgname TEXT,
|
||||
|
Loading…
Reference in New Issue
Block a user