2016-05-11 17:50:21 +08:00
|
|
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetBoundary(
|
|
|
|
username TEXT,
|
|
|
|
orgname TEXT,
|
|
|
|
geom geometry(Point, 4326),
|
|
|
|
boundary_id TEXT,
|
|
|
|
time_span TEXT DEFAULT NULL)
|
|
|
|
RETURNS geometry(Geometry, 4326) AS $$
|
|
|
|
CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname);
|
|
|
|
SELECT cdb_observatory.OBS_GetBoundary(geom, boundary_id, time_span);
|
2017-11-07 22:32:07 +08:00
|
|
|
$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE;
|
2016-05-11 17:50:21 +08:00
|
|
|
|
|
|
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetBoundary(
|
|
|
|
username TEXT,
|
|
|
|
orgname TEXT,
|
|
|
|
geom geometry(Point, 4326),
|
|
|
|
boundary_id TEXT,
|
|
|
|
time_span TEXT DEFAULT NULL)
|
|
|
|
RETURNS geometry(Geometry, 4326) AS $$
|
2016-10-29 00:12:04 +08:00
|
|
|
from cartodb_services.metrics import metrics
|
2016-05-11 17:50:21 +08:00
|
|
|
from cartodb_services.metrics import QuotaService
|
2016-08-02 23:28:48 +08:00
|
|
|
from cartodb_services.tools import Logger,LoggerConfig
|
2016-05-11 17:50:21 +08:00
|
|
|
|
|
|
|
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)]
|
|
|
|
|
2016-08-03 23:37:40 +08:00
|
|
|
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
|
|
|
|
logger_config = GD["logger_config"]
|
2016-08-02 23:28:48 +08:00
|
|
|
logger = Logger(logger_config)
|
2016-05-11 17:50:21 +08:00
|
|
|
quota_service = QuotaService(user_obs_config, redis_conn)
|
|
|
|
if not quota_service.check_user_quota():
|
2016-08-02 01:04:56 +08:00
|
|
|
raise Exception('You have reached the limit of your quota')
|
2016-05-11 17:50:21 +08:00
|
|
|
|
2016-11-11 18:03:00 +08:00
|
|
|
with metrics('obs_getboundary', user_obs_config, logger):
|
2016-10-29 00:12:04 +08:00
|
|
|
try:
|
|
|
|
obs_plan = plpy.prepare("SELECT cdb_dataservices_server._OBS_GetBoundary($1, $2, $3, $4) as boundary;", ["text", "text", "geometry(Point, 4326)", "text", "text"])
|
|
|
|
result = plpy.execute(obs_plan, [username, orgname, geom, boundary_id, time_span])
|
|
|
|
if result:
|
|
|
|
quota_service.increment_success_service_use()
|
|
|
|
return result[0]['boundary']
|
|
|
|
else:
|
|
|
|
quota_service.increment_empty_service_use()
|
|
|
|
return None
|
|
|
|
except BaseException as e:
|
|
|
|
import sys
|
|
|
|
quota_service.increment_failed_service_use()
|
|
|
|
logger.error('Error trying to OBS_GetBoundary', sys.exc_info(), data={"username": username, "orgname": orgname})
|
|
|
|
raise Exception('Error trying to OBS_GetBoundary')
|
|
|
|
finally:
|
|
|
|
quota_service.increment_total_service_use()
|
2020-02-24 23:12:27 +08:00
|
|
|
$$ LANGUAGE @@plpythonu@@ STABLE PARALLEL RESTRICTED;
|
2016-05-11 17:50:21 +08:00
|
|
|
|
|
|
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetBoundaryId(
|
|
|
|
username TEXT,
|
|
|
|
orgname TEXT,
|
|
|
|
geom geometry(Point, 4326),
|
|
|
|
boundary_id TEXT,
|
|
|
|
time_span TEXT DEFAULT NULL)
|
|
|
|
RETURNS TEXT AS $$
|
|
|
|
CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname);
|
2016-05-12 17:32:59 +08:00
|
|
|
SELECT cdb_observatory.OBS_GetBoundaryId(geom, boundary_id, time_span);
|
2017-11-07 22:32:07 +08:00
|
|
|
$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE;
|
2016-05-11 17:50:21 +08:00
|
|
|
|
|
|
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetBoundaryId(
|
|
|
|
username TEXT,
|
|
|
|
orgname TEXT,
|
|
|
|
geom geometry(Point, 4326),
|
|
|
|
boundary_id TEXT,
|
|
|
|
time_span TEXT DEFAULT NULL)
|
|
|
|
RETURNS TEXT AS $$
|
2016-10-29 00:12:04 +08:00
|
|
|
from cartodb_services.metrics import metrics
|
2016-05-11 17:50:21 +08:00
|
|
|
from cartodb_services.metrics import QuotaService
|
2016-08-02 23:28:48 +08:00
|
|
|
from cartodb_services.tools import Logger,LoggerConfig
|
2016-05-11 17:50:21 +08:00
|
|
|
|
|
|
|
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)]
|
|
|
|
|
2016-08-03 23:37:40 +08:00
|
|
|
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
|
|
|
|
logger_config = GD["logger_config"]
|
2016-08-02 23:28:48 +08:00
|
|
|
logger = Logger(logger_config)
|
2016-05-11 17:50:21 +08:00
|
|
|
quota_service = QuotaService(user_obs_config, redis_conn)
|
|
|
|
if not quota_service.check_user_quota():
|
2016-08-02 01:04:56 +08:00
|
|
|
raise Exception('You have reached the limit of your quota')
|
2016-05-11 17:50:21 +08:00
|
|
|
|
2016-11-11 18:03:00 +08:00
|
|
|
with metrics('obs_getboundaryid', user_obs_config, logger):
|
2016-10-29 00:12:04 +08:00
|
|
|
try:
|
|
|
|
obs_plan = plpy.prepare("SELECT cdb_dataservices_server._OBS_GetBoundaryId($1, $2, $3, $4, $5) as boundary;", ["text", "text", "geometry(Point, 4326)", "text", "text"])
|
|
|
|
result = plpy.execute(obs_plan, [username, orgname, geom, boundary_id, time_span])
|
|
|
|
if result:
|
|
|
|
quota_service.increment_success_service_use()
|
|
|
|
return result[0]['boundary']
|
|
|
|
else:
|
|
|
|
quota_service.increment_empty_service_use()
|
|
|
|
return None
|
|
|
|
except BaseException as e:
|
|
|
|
import sys
|
|
|
|
quota_service.increment_failed_service_use()
|
|
|
|
logger.error('Error trying to OBS_GetBoundaryId', sys.exc_info(), data={"username": username, "orgname": orgname})
|
|
|
|
raise Exception('Error trying to OBS_GetBoundaryId')
|
|
|
|
finally:
|
|
|
|
quota_service.increment_total_service_use()
|
2020-02-24 23:12:27 +08:00
|
|
|
$$ LANGUAGE @@plpythonu@@ STABLE PARALLEL RESTRICTED;
|
2016-05-11 17:50:21 +08:00
|
|
|
|
|
|
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetBoundaryById(
|
|
|
|
username TEXT,
|
|
|
|
orgname TEXT,
|
|
|
|
geometry_id TEXT,
|
|
|
|
boundary_id TEXT,
|
|
|
|
time_span TEXT DEFAULT NULL)
|
|
|
|
RETURNS geometry(Geometry, 4326) AS $$
|
|
|
|
CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname);
|
|
|
|
SELECT cdb_observatory.OBS_GetBoundaryById(geometry_id, boundary_id, time_span);
|
2017-11-07 22:32:07 +08:00
|
|
|
$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE;
|
2016-05-11 17:50:21 +08:00
|
|
|
|
|
|
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetBoundaryById(
|
|
|
|
username TEXT,
|
|
|
|
orgname TEXT,
|
|
|
|
geometry_id TEXT,
|
|
|
|
boundary_id TEXT,
|
|
|
|
time_span TEXT DEFAULT NULL)
|
|
|
|
RETURNS geometry(Geometry, 4326) AS $$
|
2016-10-29 00:12:04 +08:00
|
|
|
from cartodb_services.metrics import metrics
|
2016-05-11 17:50:21 +08:00
|
|
|
from cartodb_services.metrics import QuotaService
|
2016-08-02 23:28:48 +08:00
|
|
|
from cartodb_services.tools import Logger,LoggerConfig
|
2016-05-11 17:50:21 +08:00
|
|
|
|
|
|
|
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)]
|
|
|
|
|
2016-08-03 23:37:40 +08:00
|
|
|
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
|
|
|
|
logger_config = GD["logger_config"]
|
2016-08-02 23:28:48 +08:00
|
|
|
logger = Logger(logger_config)
|
2016-05-11 17:50:21 +08:00
|
|
|
quota_service = QuotaService(user_obs_config, redis_conn)
|
|
|
|
if not quota_service.check_user_quota():
|
2016-08-02 01:04:56 +08:00
|
|
|
raise Exception('You have reached the limit of your quota')
|
2016-05-11 17:50:21 +08:00
|
|
|
|
2016-11-11 18:03:00 +08:00
|
|
|
with metrics('obs_getboundarybyid', user_obs_config, logger):
|
2016-10-29 00:12:04 +08:00
|
|
|
try:
|
|
|
|
obs_plan = plpy.prepare("SELECT cdb_dataservices_server._OBS_GetBoundaryById($1, $2, $3, $4, $5) as boundary;", ["text", "text", "text", "text", "text"])
|
|
|
|
result = plpy.execute(obs_plan, [username, orgname, geometry_id, boundary_id, time_span])
|
|
|
|
if result:
|
|
|
|
quota_service.increment_success_service_use()
|
|
|
|
return result[0]['boundary']
|
|
|
|
else:
|
|
|
|
quota_service.increment_empty_service_use()
|
|
|
|
return None
|
|
|
|
except BaseException as e:
|
|
|
|
import sys
|
|
|
|
quota_service.increment_failed_service_use()
|
|
|
|
logger.error('Error trying to OBS_GetBoundaryById', sys.exc_info(), data={"username": username, "orgname": orgname})
|
|
|
|
raise Exception('Error trying to OBS_GetBoundaryById')
|
|
|
|
finally:
|
|
|
|
quota_service.increment_total_service_use()
|
2020-02-24 23:12:27 +08:00
|
|
|
$$ LANGUAGE @@plpythonu@@ STABLE PARALLEL RESTRICTED;
|
2016-05-11 17:50:21 +08:00
|
|
|
|
|
|
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetBoundariesByGeometry(
|
|
|
|
username TEXT,
|
|
|
|
orgname TEXT,
|
|
|
|
geom geometry(Point, 4326),
|
|
|
|
boundary_id TEXT,
|
|
|
|
time_span TEXT DEFAULT NULL,
|
2016-07-26 17:42:00 +08:00
|
|
|
overlap_type text DEFAULT NULL)
|
2016-05-11 17:50:21 +08:00
|
|
|
RETURNS TABLE(the_geom geometry, geom_refs text) AS $$
|
|
|
|
CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname);
|
|
|
|
SELECT * FROM cdb_observatory.OBS_GetBoundariesByGeometry(geom, boundary_id, time_span, overlap_type);
|
2017-11-07 22:32:07 +08:00
|
|
|
$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE;
|
2016-05-11 17:50:21 +08:00
|
|
|
|
|
|
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetBoundariesByGeometry(
|
|
|
|
username TEXT,
|
|
|
|
orgname TEXT,
|
|
|
|
geom geometry(Point, 4326),
|
|
|
|
boundary_id TEXT,
|
|
|
|
time_span TEXT DEFAULT NULL,
|
2016-07-26 17:42:00 +08:00
|
|
|
overlap_type TEXT DEFAULT NULL)
|
2016-05-11 17:50:21 +08:00
|
|
|
RETURNS TABLE(the_geom geometry, geom_refs text) AS $$
|
2016-10-29 00:12:04 +08:00
|
|
|
from cartodb_services.metrics import metrics
|
2016-05-11 17:50:21 +08:00
|
|
|
from cartodb_services.metrics import QuotaService
|
2016-08-02 23:28:48 +08:00
|
|
|
from cartodb_services.tools import Logger,LoggerConfig
|
2016-05-11 17:50:21 +08:00
|
|
|
|
|
|
|
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)]
|
|
|
|
|
2016-08-03 23:37:40 +08:00
|
|
|
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
|
|
|
|
logger_config = GD["logger_config"]
|
2016-08-02 23:28:48 +08:00
|
|
|
logger = Logger(logger_config)
|
2016-05-11 17:50:21 +08:00
|
|
|
quota_service = QuotaService(user_obs_config, redis_conn)
|
|
|
|
if not quota_service.check_user_quota():
|
2016-08-02 01:04:56 +08:00
|
|
|
raise Exception('You have reached the limit of your quota')
|
2016-05-11 17:50:21 +08:00
|
|
|
|
2016-11-11 18:03:00 +08:00
|
|
|
with metrics('obs_getboundariesbygeometry', user_obs_config, logger):
|
2016-10-29 00:12:04 +08:00
|
|
|
try:
|
|
|
|
obs_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._OBS_GetBoundariesByGeometry($1, $2, $3, $4, $5, $6) as boundary;", ["text", "text", "geometry(Point, 4326)", "text", "text", "text"])
|
|
|
|
result = plpy.execute(obs_plan, [username, orgname, geom, boundary_id, time_span, overlap_type])
|
|
|
|
if result:
|
|
|
|
resp = []
|
|
|
|
for element in result:
|
|
|
|
the_geom = element['the_geom']
|
|
|
|
geom_refs = element['geom_refs']
|
|
|
|
resp.append([the_geom, geom_refs])
|
|
|
|
quota_service.increment_success_service_use()
|
|
|
|
return resp
|
|
|
|
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 OBS_GetBoundariesByGeometry', sys.exc_info(), data={"username": username, "orgname": orgname})
|
|
|
|
raise Exception('Error trying to OBS_GetBoundariesByGeometry')
|
|
|
|
finally:
|
|
|
|
quota_service.increment_total_service_use()
|
2020-02-24 23:12:27 +08:00
|
|
|
$$ LANGUAGE @@plpythonu@@ STABLE PARALLEL RESTRICTED;
|
2016-05-11 17:50:21 +08:00
|
|
|
|
|
|
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetBoundariesByPointAndRadius(
|
|
|
|
username TEXT,
|
|
|
|
orgname TEXT,
|
|
|
|
geom geometry(Point, 4326),
|
|
|
|
radius NUMERIC,
|
|
|
|
boundary_id TEXT,
|
|
|
|
time_span TEXT DEFAULT NULL,
|
2016-07-26 17:42:00 +08:00
|
|
|
overlap_type TEXT DEFAULT NULL)
|
2016-05-11 17:50:21 +08:00
|
|
|
RETURNS TABLE(the_geom geometry, geom_refs text) AS $$
|
|
|
|
CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname);
|
|
|
|
SELECT * FROM cdb_observatory.OBS_GetBoundariesByPointAndRadius(geom, radius, boundary_id, time_span, overlap_type);
|
2017-11-07 22:32:07 +08:00
|
|
|
$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE;
|
2016-05-11 17:50:21 +08:00
|
|
|
|
|
|
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetBoundariesByPointAndRadius(
|
|
|
|
username TEXT,
|
|
|
|
orgname TEXT,
|
|
|
|
geom geometry(Point, 4326),
|
|
|
|
radius NUMERIC,
|
|
|
|
boundary_id TEXT,
|
|
|
|
time_span TEXT DEFAULT NULL,
|
2016-07-26 17:42:00 +08:00
|
|
|
overlap_type TEXT DEFAULT NULL)
|
2016-05-11 17:50:21 +08:00
|
|
|
RETURNS TABLE(the_geom geometry, geom_refs text) AS $$
|
2016-10-29 00:12:04 +08:00
|
|
|
from cartodb_services.metrics import metrics
|
2016-05-11 17:50:21 +08:00
|
|
|
from cartodb_services.metrics import QuotaService
|
2016-08-02 23:28:48 +08:00
|
|
|
from cartodb_services.tools import Logger,LoggerConfig
|
2016-05-11 17:50:21 +08:00
|
|
|
|
|
|
|
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)]
|
|
|
|
|
2016-08-03 23:37:40 +08:00
|
|
|
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
|
|
|
|
logger_config = GD["logger_config"]
|
2016-08-02 23:28:48 +08:00
|
|
|
logger = Logger(logger_config)
|
2016-05-11 17:50:21 +08:00
|
|
|
quota_service = QuotaService(user_obs_config, redis_conn)
|
|
|
|
if not quota_service.check_user_quota():
|
2016-08-02 01:04:56 +08:00
|
|
|
raise Exception('You have reached the limit of your quota')
|
2016-05-11 17:50:21 +08:00
|
|
|
|
2016-11-11 18:03:00 +08:00
|
|
|
with metrics('obs_getboundariesbypointandradius', user_obs_config, logger):
|
2016-10-29 00:12:04 +08:00
|
|
|
try:
|
|
|
|
obs_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._OBS_GetBoundariesByPointAndRadius($1, $2, $3, $4, $5, $6, $7) as boundary;", ["text", "text", "geometry(Point, 4326)", "numeric", "text", "text", "text"])
|
|
|
|
result = plpy.execute(obs_plan, [username, orgname, geom, radius, boundary_id, time_span, overlap_type])
|
|
|
|
if result:
|
|
|
|
resp = []
|
|
|
|
for element in result:
|
|
|
|
the_geom = element['the_geom']
|
|
|
|
geom_refs = element['geom_refs']
|
|
|
|
resp.append([the_geom, geom_refs])
|
|
|
|
quota_service.increment_success_service_use()
|
|
|
|
return resp
|
|
|
|
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 OBS_GetBoundariesByPointAndRadius', sys.exc_info(), data={"username": username, "orgname": orgname})
|
|
|
|
raise Exception('Error trying to OBS_GetBoundariesByPointAndRadius')
|
|
|
|
finally:
|
|
|
|
quota_service.increment_total_service_use()
|
2020-02-24 23:12:27 +08:00
|
|
|
$$ LANGUAGE @@plpythonu@@ STABLE PARALLEL RESTRICTED;
|
2016-05-11 17:50:21 +08:00
|
|
|
|
|
|
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetPointsByGeometry(
|
|
|
|
username TEXT,
|
|
|
|
orgname TEXT,
|
|
|
|
geom geometry(Point, 4326),
|
|
|
|
boundary_id TEXT,
|
|
|
|
time_span TEXT DEFAULT NULL,
|
2016-07-26 17:42:00 +08:00
|
|
|
overlap_type TEXT DEFAULT NULL)
|
2016-05-11 17:50:21 +08:00
|
|
|
RETURNS TABLE(the_geom geometry, geom_refs text) AS $$
|
|
|
|
CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname);
|
|
|
|
SELECT * FROM cdb_observatory.OBS_GetPointsByGeometry(geom, boundary_id, time_span, overlap_type);
|
2017-11-07 22:32:07 +08:00
|
|
|
$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE;
|
2016-05-11 17:50:21 +08:00
|
|
|
|
|
|
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetPointsByGeometry(
|
|
|
|
username TEXT,
|
|
|
|
orgname TEXT,
|
|
|
|
geom geometry(Point, 4326),
|
|
|
|
boundary_id TEXT,
|
|
|
|
time_span TEXT DEFAULT NULL,
|
2016-07-26 17:42:00 +08:00
|
|
|
overlap_type TEXT DEFAULT NULL)
|
2016-05-11 17:50:21 +08:00
|
|
|
RETURNS TABLE(the_geom geometry, geom_refs text) AS $$
|
2016-10-29 00:12:04 +08:00
|
|
|
from cartodb_services.metrics import metrics
|
2016-05-11 17:50:21 +08:00
|
|
|
from cartodb_services.metrics import QuotaService
|
2016-08-02 23:28:48 +08:00
|
|
|
from cartodb_services.tools import Logger,LoggerConfig
|
2016-05-11 17:50:21 +08:00
|
|
|
|
|
|
|
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)]
|
|
|
|
|
2016-08-03 23:37:40 +08:00
|
|
|
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
|
|
|
|
logger_config = GD["logger_config"]
|
2016-08-02 23:28:48 +08:00
|
|
|
logger = Logger(logger_config)
|
2016-05-11 17:50:21 +08:00
|
|
|
quota_service = QuotaService(user_obs_config, redis_conn)
|
|
|
|
if not quota_service.check_user_quota():
|
2016-08-02 01:04:56 +08:00
|
|
|
raise Exception('You have reached the limit of your quota')
|
2016-05-11 17:50:21 +08:00
|
|
|
|
2016-11-11 18:03:00 +08:00
|
|
|
with metrics('obs_getpointsbygeometry', user_obs_config, logger):
|
2016-10-29 00:12:04 +08:00
|
|
|
try:
|
|
|
|
obs_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._OBS_GetPointsByGeometry($1, $2, $3, $4, $5, $6) as boundary;", ["text", "text", "geometry(Point, 4326)", "text", "text", "text"])
|
|
|
|
result = plpy.execute(obs_plan, [username, orgname, geom, boundary_id, time_span, overlap_type])
|
|
|
|
if result:
|
|
|
|
resp = []
|
|
|
|
for element in result:
|
|
|
|
the_geom = element['the_geom']
|
|
|
|
geom_refs = element['geom_refs']
|
|
|
|
resp.append([the_geom, geom_refs])
|
|
|
|
quota_service.increment_success_service_use()
|
|
|
|
return resp
|
|
|
|
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 OBS_GetPointsByGeometry', sys.exc_info(), data={"username": username, "orgname": orgname})
|
|
|
|
raise Exception('Error trying to OBS_GetPointsByGeometry')
|
|
|
|
finally:
|
|
|
|
quota_service.increment_total_service_use()
|
2020-02-24 23:12:27 +08:00
|
|
|
$$ LANGUAGE @@plpythonu@@ STABLE PARALLEL RESTRICTED;
|
2016-05-11 17:50:21 +08:00
|
|
|
|
|
|
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetPointsByPointAndRadius(
|
|
|
|
username TEXT,
|
|
|
|
orgname TEXT,
|
|
|
|
geom geometry(Point, 4326),
|
|
|
|
radius NUMERIC,
|
|
|
|
boundary_id TEXT,
|
|
|
|
time_span TEXT DEFAULT NULL,
|
2016-07-26 17:42:00 +08:00
|
|
|
overlap_type TEXT DEFAULT NULL)
|
2016-05-11 17:50:21 +08:00
|
|
|
RETURNS TABLE(the_geom geometry, geom_refs text) AS $$
|
|
|
|
CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname);
|
|
|
|
SELECT * FROM cdb_observatory.OBS_GetPointsByPointAndRadius(geom, radius, boundary_id, time_span, overlap_type);
|
2017-11-07 22:32:07 +08:00
|
|
|
$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE;
|
2016-05-11 17:50:21 +08:00
|
|
|
|
|
|
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetPointsByPointAndRadius(
|
|
|
|
username TEXT,
|
|
|
|
orgname TEXT,
|
|
|
|
geom geometry(Point, 4326),
|
|
|
|
radius NUMERIC,
|
|
|
|
boundary_id TEXT,
|
|
|
|
time_span TEXT DEFAULT NULL,
|
2016-07-26 17:42:00 +08:00
|
|
|
overlap_type TEXT DEFAULT NULL)
|
2016-05-11 17:50:21 +08:00
|
|
|
RETURNS TABLE(the_geom geometry, geom_refs text) AS $$
|
2016-10-29 00:12:04 +08:00
|
|
|
from cartodb_services.metrics import metrics
|
2016-05-11 17:50:21 +08:00
|
|
|
from cartodb_services.metrics import QuotaService
|
2016-08-02 23:28:48 +08:00
|
|
|
from cartodb_services.tools import Logger,LoggerConfig
|
2016-05-11 17:50:21 +08:00
|
|
|
|
|
|
|
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)]
|
|
|
|
|
2016-08-03 23:37:40 +08:00
|
|
|
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
|
|
|
|
logger_config = GD["logger_config"]
|
2016-08-02 23:28:48 +08:00
|
|
|
logger = Logger(logger_config)
|
2016-05-11 17:50:21 +08:00
|
|
|
quota_service = QuotaService(user_obs_config, redis_conn)
|
|
|
|
if not quota_service.check_user_quota():
|
2016-08-02 01:04:56 +08:00
|
|
|
raise Exception('You have reached the limit of your quota')
|
2016-05-11 17:50:21 +08:00
|
|
|
|
2016-11-11 18:03:00 +08:00
|
|
|
with metrics('obs_getpointsbypointandradius', user_obs_config, logger):
|
2016-10-29 00:12:04 +08:00
|
|
|
try:
|
|
|
|
obs_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._OBS_GetPointsByPointAndRadius($1, $2, $3, $4, $5, $6, $7) as boundary;", ["text", "text", "geometry(Point, 4326)", "numeric", "text", "text", "text"])
|
|
|
|
result = plpy.execute(obs_plan, [username, orgname, geom, radius, boundary_id, time_span, overlap_type])
|
|
|
|
if result:
|
|
|
|
resp = []
|
|
|
|
for element in result:
|
|
|
|
the_geom = element['the_geom']
|
|
|
|
geom_refs = element['geom_refs']
|
|
|
|
resp.append([the_geom, geom_refs])
|
|
|
|
quota_service.increment_success_service_use()
|
|
|
|
return resp
|
|
|
|
else:
|
|
|
|
quota_service.increment_empty_service_use()
|
|
|
|
return None
|
|
|
|
except BaseException as e:
|
|
|
|
import sys
|
|
|
|
quota_service.increment_failed_service_use()
|
|
|
|
logger.error('Error trying to OBS_GetPointsByPointAndRadius', sys.exc_info(), data={"username": username, "orgname": orgname})
|
|
|
|
raise Exception('Error trying to OBS_GetPointsByPointAndRadius')
|
|
|
|
finally:
|
|
|
|
quota_service.increment_total_service_use()
|
2020-02-24 23:12:27 +08:00
|
|
|
$$ LANGUAGE @@plpythonu@@ STABLE PARALLEL RESTRICTED;
|