Modify sql code to user the python virtualenv
This commit is contained in:
@@ -0,0 +1,18 @@
|
|||||||
|
-- Use the crankshaft python module
|
||||||
|
CREATE OR REPLACE FUNCTION _cdb_crankshaft_activate_py()
|
||||||
|
RETURNS VOID
|
||||||
|
AS $$
|
||||||
|
# activate virtualenv
|
||||||
|
# TODO: parameterize with environment variables or something
|
||||||
|
venv_path = '/home/ubuntu/crankshaft/src/py/dev'
|
||||||
|
activate_path = venv_path + '/bin/activate_this.py'
|
||||||
|
exec(open(activate_path).read(),
|
||||||
|
dict(__file__=activate_path))
|
||||||
|
|
||||||
|
# import something from virtualenv
|
||||||
|
# from crankshaft import random_seeds
|
||||||
|
|
||||||
|
# do some stuff
|
||||||
|
# random_seeds.set_random_seeds(123)
|
||||||
|
# plpy.notice('here we are')
|
||||||
|
$$ LANGUAGE plpythonu;
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
CREATE OR REPLACE FUNCTION
|
CREATE OR REPLACE FUNCTION
|
||||||
_cdb_random_seeds (seed_value INTEGER) RETURNS VOID
|
_cdb_random_seeds (seed_value INTEGER) RETURNS VOID
|
||||||
AS $$
|
AS $$
|
||||||
|
plpy.execute('SELECT cdb_crankshaft._cdb_crankshaft_activate_py()')
|
||||||
from crankshaft import random_seeds
|
from crankshaft import random_seeds
|
||||||
random_seeds.set_random_seeds(seed_value)
|
random_seeds.set_random_seeds(seed_value)
|
||||||
$$ LANGUAGE plpythonu;
|
$$ LANGUAGE plpythonu;
|
||||||
@@ -11,6 +11,7 @@ CREATE OR REPLACE FUNCTION
|
|||||||
w_type TEXT DEFAULT 'knn')
|
w_type TEXT DEFAULT 'knn')
|
||||||
RETURNS TABLE (moran FLOAT, quads TEXT, significance FLOAT, ids INT)
|
RETURNS TABLE (moran FLOAT, quads TEXT, significance FLOAT, ids INT)
|
||||||
AS $$
|
AS $$
|
||||||
|
plpy.execute('SELECT cdb_crankshaft._cdb_crankshaft_activate_py()')
|
||||||
from crankshaft.clustering import moran_local
|
from crankshaft.clustering import moran_local
|
||||||
# TODO: use named parameters or a dictionary
|
# TODO: use named parameters or a dictionary
|
||||||
return moran_local(t, attr, significance, num_ngbrs, permutations, geom_column, id_col, w_type)
|
return moran_local(t, attr, significance, num_ngbrs, permutations, geom_column, id_col, w_type)
|
||||||
@@ -29,6 +30,7 @@ CREATE OR REPLACE FUNCTION
|
|||||||
w_type TEXT DEFAULT 'knn')
|
w_type TEXT DEFAULT 'knn')
|
||||||
RETURNS TABLE(moran FLOAT, quads TEXT, significance FLOAT, ids INT, y numeric)
|
RETURNS TABLE(moran FLOAT, quads TEXT, significance FLOAT, ids INT, y numeric)
|
||||||
AS $$
|
AS $$
|
||||||
|
plpy.execute('SELECT cdb_crankshaft._cdb_crankshaft_activate_py()')
|
||||||
from crankshaft.clustering import moran_local_rate
|
from crankshaft.clustering import moran_local_rate
|
||||||
# TODO: use named parameters or a dictionary
|
# TODO: use named parameters or a dictionary
|
||||||
return moran_local_rate(t, numerator, denominator, significance, num_ngbrs, permutations, geom_column, id_col, w_type)
|
return moran_local_rate(t, numerator, denominator, significance, num_ngbrs, permutations, geom_column, id_col, w_type)
|
||||||
Reference in New Issue
Block a user