Modify sql code to user the python virtualenv
This commit is contained in:
parent
cdd2d9e722
commit
8e972128eb
18
src/pg/sql/01_py.sql
Normal file
18
src/pg/sql/01_py.sql
Normal file
@ -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
|
||||
_cdb_random_seeds (seed_value INTEGER) RETURNS VOID
|
||||
AS $$
|
||||
plpy.execute('SELECT cdb_crankshaft._cdb_crankshaft_activate_py()')
|
||||
from crankshaft import random_seeds
|
||||
random_seeds.set_random_seeds(seed_value)
|
||||
$$ LANGUAGE plpythonu;
|
@ -11,6 +11,7 @@ CREATE OR REPLACE FUNCTION
|
||||
w_type TEXT DEFAULT 'knn')
|
||||
RETURNS TABLE (moran FLOAT, quads TEXT, significance FLOAT, ids INT)
|
||||
AS $$
|
||||
plpy.execute('SELECT cdb_crankshaft._cdb_crankshaft_activate_py()')
|
||||
from crankshaft.clustering import moran_local
|
||||
# TODO: use named parameters or a dictionary
|
||||
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')
|
||||
RETURNS TABLE(moran FLOAT, quads TEXT, significance FLOAT, ids INT, y numeric)
|
||||
AS $$
|
||||
plpy.execute('SELECT cdb_crankshaft._cdb_crankshaft_activate_py()')
|
||||
from crankshaft.clustering import moran_local_rate
|
||||
# TODO: use named parameters or a dictionary
|
||||
return moran_local_rate(t, numerator, denominator, significance, num_ngbrs, permutations, geom_column, id_col, w_type)
|
Loading…
Reference in New Issue
Block a user