2016-05-23 23:26:43 +08:00
|
|
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_route_point_to_point(
|
|
|
|
username TEXT,
|
|
|
|
orgname TEXT,
|
|
|
|
origin geometry(Point, 4326),
|
|
|
|
destination geometry(Point, 4326),
|
|
|
|
mode TEXT,
|
|
|
|
options text[] DEFAULT ARRAY[]::text[],
|
|
|
|
units text DEFAULT 'kilometers')
|
|
|
|
RETURNS cdb_dataservices_server.simple_route AS $$
|
2016-10-29 00:12:04 +08:00
|
|
|
from cartodb_services.metrics import metrics
|
|
|
|
from cartodb_services.tools import Logger
|
2016-05-23 23:26:43 +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_routing_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
|
|
|
user_routing_config = GD["user_routing_config_{0}".format(username)]
|
2016-11-02 16:58:35 +08:00
|
|
|
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
|
|
|
|
logger_config = GD["logger_config"]
|
|
|
|
logger = Logger(logger_config)
|
2016-05-23 23:26:43 +08:00
|
|
|
|
2016-11-02 16:58:35 +08:00
|
|
|
with metrics('cdb_route_with_point', user_routing_config, logger):
|
2016-10-29 00:12:04 +08:00
|
|
|
waypoints = [origin, destination]
|
|
|
|
mapzen_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._cdb_mapzen_route_with_waypoints($1, $2, $3, $4, $5, $6) as route;", ["text", "text", "geometry(Point, 4326)[]", "text", "text[]", "text"])
|
|
|
|
result = plpy.execute(mapzen_plan, [username, orgname, waypoints, mode, options, units])
|
|
|
|
return [result[0]['shape'],result[0]['length'], result[0]['duration']]
|
2016-05-23 23:26:43 +08:00
|
|
|
$$ LANGUAGE plpythonu;
|
|
|
|
|
|
|
|
|
|
|
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_route_with_waypoints(
|
|
|
|
username TEXT,
|
|
|
|
orgname TEXT,
|
|
|
|
waypoints geometry(Point, 4326)[],
|
|
|
|
mode TEXT,
|
|
|
|
options text[] DEFAULT ARRAY[]::text[],
|
|
|
|
units text DEFAULT 'kilometers')
|
|
|
|
RETURNS cdb_dataservices_server.simple_route AS $$
|
2016-10-29 00:12:04 +08:00
|
|
|
from cartodb_services.metrics import metrics
|
|
|
|
from cartodb_services.tools import Logger
|
2016-05-23 23:26:43 +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_routing_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
|
|
|
user_routing_config = GD["user_routing_config_{0}".format(username)]
|
2016-11-02 16:58:35 +08:00
|
|
|
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
|
|
|
|
logger_config = GD["logger_config"]
|
|
|
|
logger = Logger(logger_config)
|
2016-05-23 23:26:43 +08:00
|
|
|
|
2016-11-02 16:58:35 +08:00
|
|
|
with metrics('cdb_route_with_waypoints', user_routing_config, logger):
|
2016-10-29 00:12:04 +08:00
|
|
|
mapzen_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._cdb_mapzen_route_with_waypoints($1, $2, $3, $4, $5, $6) as route;", ["text", "text", "geometry(Point, 4326)[]", "text", "text[]", "text"])
|
|
|
|
result = plpy.execute(mapzen_plan, [username, orgname, waypoints, mode, options, units])
|
|
|
|
return [result[0]['shape'],result[0]['length'], result[0]['duration']]
|
2016-05-23 23:26:43 +08:00
|
|
|
$$ LANGUAGE plpythonu;
|