Refactor and new tests
This commit is contained in:
8
pg/sql/0.0.1/01_random_seeds.sql
Normal file
8
pg/sql/0.0.1/01_random_seeds.sql
Normal file
@@ -0,0 +1,8 @@
|
||||
-- Set the seeds of the RNGs (Random Number Generators)
|
||||
-- used internally.
|
||||
CREATE OR REPLACE FUNCTION
|
||||
cdb_random_seeds (seed_value INTEGER) RETURNS VOID
|
||||
AS $$
|
||||
from crankshaft import random_seeds
|
||||
random_seeds.set_random_seeds(seed_value)
|
||||
$$ LANGUAGE plpythonu;
|
||||
18
pg/sql/0.0.1/02_moran.sql
Normal file
18
pg/sql/0.0.1/02_moran.sql
Normal file
@@ -0,0 +1,18 @@
|
||||
CREATE OR REPLACE FUNCTION
|
||||
cdb_moran_local (
|
||||
t TEXT,
|
||||
attr TEXT,
|
||||
significance float DEFAULT 0.05,
|
||||
num_ngbrs INT DEFAULT 5,
|
||||
permutations INT DEFAULT 99,
|
||||
geom_column TEXT DEFAULT 'the_geom',
|
||||
id_col TEXT DEFAULT 'cartodb_id',
|
||||
w_type TEXT DEFAULT 'knn',
|
||||
random_seed INTEGER DEFAULT NULL
|
||||
)
|
||||
RETURNS TABLE (moran FLOAT, quads TEXT, significance FLOAT, ids INT)
|
||||
AS $$
|
||||
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, random_seed)
|
||||
$$ LANGUAGE plpythonu;
|
||||
20
pg/sql/0.0.1/03_overlap_sum.sql
Normal file
20
pg/sql/0.0.1/03_overlap_sum.sql
Normal file
@@ -0,0 +1,20 @@
|
||||
-- Function by Stuart Lynn for a simple interpolation of a value
|
||||
-- from a polygon table over an arbitrary polygon
|
||||
-- (weighted by the area proportion overlapped)
|
||||
CREATE OR REPLACE
|
||||
FUNCTION cdb_overlap_sum(geom geometry, target_table_name text, target_column text)
|
||||
RETURNS numeric AS
|
||||
$$
|
||||
DECLARE
|
||||
result numeric;
|
||||
BEGIN
|
||||
EXECUTE Format('
|
||||
SELECT sum(%I*ST_Area(St_Intersection($1, a.the_geom))/ST_Area(a.the_geom))
|
||||
FROM %I AS a
|
||||
WHERE $1 && a.the_geom
|
||||
', target_column, target_table_name)
|
||||
USING geom
|
||||
INTO result;
|
||||
RETURN result;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
@@ -1,22 +0,0 @@
|
||||
CREATE OR REPLACE FUNCTION
|
||||
cdb_moran_local (
|
||||
t TEXT,
|
||||
attr TEXT,
|
||||
significance float DEFAULT 0.05,
|
||||
num_ngbrs INT DEFAULT 5,
|
||||
permutations INT DEFAULT 99,
|
||||
geom_column TEXT DEFAULT 'the_geom',
|
||||
id_col TEXT DEFAULT 'cartodb_id',
|
||||
w_type TEXT DEFAULT 'knn'
|
||||
)
|
||||
RETURNS TABLE (
|
||||
moran FLOAT,
|
||||
quads TEXT,
|
||||
significance FLOAT,
|
||||
ids INT
|
||||
)
|
||||
AS $$
|
||||
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)
|
||||
$$ LANGUAGE plpythonu;
|
||||
@@ -1,5 +0,0 @@
|
||||
CREATE OR REPLACE FUNCTION cdb_poc_xyz()
|
||||
RETURNS Text AS $$
|
||||
from crankshaft.poc import xyz
|
||||
return xyz()
|
||||
$$ LANGUAGE plpythonu;
|
||||
Reference in New Issue
Block a user