add full tests
This commit is contained in:
@@ -1,6 +1,18 @@
|
||||
-- Install dependencies
|
||||
CREATE EXTENSION plpythonu;
|
||||
CREATE EXTENSION postgis;
|
||||
CREATE EXTENSION cartodb;
|
||||
CREATE EXTENSION postgis VERSION '2.2.2';
|
||||
-- Create role publicuser if it does not exist
|
||||
DO
|
||||
$$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT *
|
||||
FROM pg_catalog.pg_user
|
||||
WHERE usename = 'publicuser') THEN
|
||||
|
||||
CREATE ROLE publicuser LOGIN;
|
||||
END IF;
|
||||
END
|
||||
$$ LANGUAGE plpgsql;
|
||||
-- Install the extension
|
||||
CREATE EXTENSION crankshaft VERSION 'dev';
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
\pset format unaligned
|
||||
\set ECHO all
|
||||
SELECT count(DISTINCT cluster_no) as clusters from cdb_crankshaft.cdb_kmeans('select * from ppoints', 2);
|
||||
clusters
|
||||
2
|
||||
(1 row)
|
||||
SELECT count(*) clusters from (select cdb_crankshaft.CDB_WeightedMean(the_geom, value::NUMERIC), code from ppoints group by code) p;
|
||||
clusters
|
||||
52
|
||||
(1 row)
|
||||
@@ -0,0 +1,10 @@
|
||||
SET client_min_messages TO WARNING;
|
||||
\set ECHO none
|
||||
_cdb_random_seeds
|
||||
|
||||
(1 row)
|
||||
cartodb_id|trend_test|trend_up_test|trend_down_test|volatility_test
|
||||
1|t|t|t|t
|
||||
2|t|t|t|t
|
||||
3|t|t|t|t
|
||||
(3 rows)
|
||||
@@ -0,0 +1,27 @@
|
||||
\pset format unaligned
|
||||
\set ECHO none
|
||||
_cdb_random_seeds
|
||||
|
||||
(1 row)
|
||||
within_tolerance
|
||||
t
|
||||
t
|
||||
t
|
||||
t
|
||||
t
|
||||
t
|
||||
t
|
||||
t
|
||||
t
|
||||
t
|
||||
t
|
||||
t
|
||||
t
|
||||
t
|
||||
t
|
||||
t
|
||||
t
|
||||
t
|
||||
t
|
||||
t
|
||||
(20 rows)
|
||||
@@ -0,0 +1,14 @@
|
||||
SET client_min_messages TO WARNING;
|
||||
\set ECHO none
|
||||
the_geom | h | hpop | dist
|
||||
--------------------------------------------+-------------------------+--------------------------+----------------
|
||||
01010000001361C3D32B650140DD24068195B34440 | 1.51078258369747945249 | 12.08626066957983561994 | 4964.714459152
|
||||
01010000002497FF907EFB0040713D0AD7A3B04440 | 98.29730954183620807430 | 688.08116679285345652007 | 99.955141922
|
||||
0101000000A167B3EA733501401D5A643BDFAF4440 | 63.70532894711274639196 | 382.23197368267647835174 | 2488.330566505
|
||||
010100000062A1D634EF380140BE9F1A2FDDB44440 | 35.35415870080995954879 | 176.77079350404979774397 | 4359.370460594
|
||||
010100000052B81E85EB510140355EBA490CB24440 | 33.12290506987740864904 | 132.49162027950963459615 | 3703.664449828
|
||||
0101000000C286A757CA320140736891ED7CAF4440 | 65.45251754279248087849 | 196.35755262837744263547 | 2512.092358644
|
||||
01010000007DD0B359F5390140C976BE9F1AAF4440 | 62.83927792471345639225 | 125.67855584942691278449 | 2926.25725244
|
||||
0101000000D237691A140D01407E6FD39FFDB44440 | 53.54905726651871279586 | 53.54905726651871279586 | 3744.515577777
|
||||
(8 rows)
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
SET client_min_messages TO WARNING;
|
||||
\set ECHO none
|
||||
<<<<<<< HEAD
|
||||
nn | nni | idw
|
||||
-----+--------------------------+-----------------
|
||||
200 | 780.79470198683925288365 | 341.46260750526
|
||||
=======
|
||||
cdb_spatialinterpolation
|
||||
t
|
||||
>>>>>>> ebbf68af5700f33737ac18516e2bdc22ea330b24
|
||||
(1 row)
|
||||
|
||||
|
||||
+180
File diff suppressed because one or more lines are too long
Vendored
+2005
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,20 @@
|
||||
-- Install dependencies
|
||||
CREATE EXTENSION plpythonu;
|
||||
CREATE EXTENSION postgis;
|
||||
CREATE EXTENSION cartodb;
|
||||
CREATE EXTENSION postgis VERSION '2.2.2';
|
||||
|
||||
-- Create role publicuser if it does not exist
|
||||
DO
|
||||
$$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT *
|
||||
FROM pg_catalog.pg_user
|
||||
WHERE usename = 'publicuser') THEN
|
||||
|
||||
CREATE ROLE publicuser LOGIN;
|
||||
END IF;
|
||||
END
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
-- Install the extension
|
||||
CREATE EXTENSION crankshaft VERSION 'dev';
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
\pset format unaligned
|
||||
\set ECHO all
|
||||
|
||||
SELECT count(DISTINCT cluster_no) as clusters from cdb_crankshaft.cdb_kmeans('select * from ppoints', 2);
|
||||
|
||||
SELECT count(*) clusters from (select cdb_crankshaft.CDB_WeightedMean(the_geom, value::NUMERIC), code from ppoints group by code) p;
|
||||
@@ -0,0 +1,33 @@
|
||||
SET client_min_messages TO WARNING;
|
||||
\set ECHO none
|
||||
\pset format unaligned
|
||||
\i test/fixtures/markov_usjoin_example.sql
|
||||
|
||||
-- Areas of Interest functions perform some nondeterministic computations
|
||||
-- (to estimate the significance); we will set the seeds for the RNGs
|
||||
-- that affect those results to have repeatable results
|
||||
SELECT cdb_crankshaft._cdb_random_seeds(1234);
|
||||
|
||||
SELECT
|
||||
m1.cartodb_id,
|
||||
CASE WHEN m1.cartodb_id = 1 THEN abs(m2.trend - 0.069767441860465115) / 0.069767441860465115 < 0.05
|
||||
WHEN m1.cartodb_id = 2 THEN abs(m2.trend - 0.15151515151515152) / 0.15151515151515152 < 0.05
|
||||
WHEN m1.cartodb_id = 3 THEN abs(m2.trend - 0.069767441860465115) / 0.069767441860465115 < 0.05
|
||||
ELSE NULL END As trend_test,
|
||||
CASE WHEN m1.cartodb_id = 1 THEN abs(m2.trend_up - 0.065217391304347824) / 0.065217391304347824 < 0.05
|
||||
WHEN m1.cartodb_id = 2 THEN abs(m2.trend_up - 0.13157894736842105) / 0.13157894736842105 < 0.05
|
||||
WHEN m1.cartodb_id = 3 THEN abs(m2.trend_up - 0.065217391304347824) / 0.065217391304347824 < 0.05
|
||||
ELSE NULL END As trend_up_test,
|
||||
CASE WHEN m1.cartodb_id = 1 THEN m2.trend_down = 0.0
|
||||
WHEN m1.cartodb_id = 2 THEN m2.trend_down = 0.0
|
||||
WHEN m1.cartodb_id = 3 THEN m2.trend_down = 0.0
|
||||
ELSE NULL END As trend_down_test,
|
||||
CASE WHEN m1.cartodb_id = 1 THEN abs(m2.volatility - 0.367574633389) / 0.367574633389 < 0.1
|
||||
WHEN m1.cartodb_id = 2 THEN abs(m2.volatility - 0.33807340742635211) / 0.33807340742635211 < 0.1
|
||||
WHEN m1.cartodb_id = 3 THEN abs(m2.volatility - 0.3682585596149513) / 0.3682585596149513 < 0.1
|
||||
ELSE NULL END As volatility_test
|
||||
FROM markov_usjoin_example As m1
|
||||
JOIN cdb_crankshaft.CDB_SpatialMarkovTrend('SELECT * FROM markov_usjoin_example ORDER BY cartodb_id DESC', Array['y1995', 'y1996', 'y1997', 'y1998', 'y1999', 'y2000', 'y2001', 'y2002', 'y2003', 'y2004', 'y2005', 'y2006', 'y2007', 'y2008', 'y2009']::text[], 5::int, 'knn'::text, 5::int, 0::int, 'the_geom'::text, 'cartodb_id'::text) As m2
|
||||
ON m1.cartodb_id = m2.rowid
|
||||
ORDER BY m1.cartodb_id
|
||||
LIMIT 3;
|
||||
@@ -0,0 +1,33 @@
|
||||
\pset format unaligned
|
||||
\set ECHO none
|
||||
\i test/fixtures/ml_values.sql
|
||||
SELECT cdb_crankshaft._cdb_random_seeds(1234);
|
||||
|
||||
WITH expected AS (
|
||||
SELECT generate_series(1000,1020) AS id, unnest(ARRAY[
|
||||
4.5656517130822492,
|
||||
1.7928053473230694,
|
||||
1.0283378773916563,
|
||||
2.6586517814904593,
|
||||
2.9699056242935944,
|
||||
3.9550646059951347,
|
||||
4.1662572444459745,
|
||||
3.8126334839264162,
|
||||
1.8809821053623488,
|
||||
1.6349065129019873,
|
||||
3.0391288591472954,
|
||||
3.3035970359672553,
|
||||
1.5835471589451968,
|
||||
3.7530378537263638,
|
||||
1.0833589653009252,
|
||||
3.8104965452882897,
|
||||
2.665217959294802,
|
||||
1.5850334252802472,
|
||||
3.679401198805563,
|
||||
3.5332033186588636
|
||||
]) AS expected LIMIT 20
|
||||
), prediction AS (
|
||||
SELECT cartodb_id::integer id, prediction
|
||||
FROM cdb_crankshaft.CDB_CreateAndPredictSegment('SELECT target, x1, x2, x3 FROM ml_values WHERE class = $$train$$','target','SELECT cartodb_id, target, x1, x2, x3 FROM ml_values WHERE class = $$test$$')
|
||||
LIMIT 20
|
||||
) SELECT abs(e.expected - p.prediction) <= 1e-9 AS within_tolerance FROM expected e, prediction p WHERE e.id = p.id;
|
||||
@@ -0,0 +1,24 @@
|
||||
SET client_min_messages TO WARNING;
|
||||
\set ECHO none
|
||||
|
||||
WITH t AS (
|
||||
SELECT
|
||||
ARRAY[1,2,3] AS id,
|
||||
ARRAY[7.0,8.0,3.0] AS w,
|
||||
ARRAY[ST_GeomFromText('POINT(2.1744 41.4036)'),ST_GeomFromText('POINT(2.1228 41.3809)'),ST_GeomFromText('POINT(2.1511 41.3742)')] AS g
|
||||
),
|
||||
s AS (
|
||||
SELECT
|
||||
ARRAY[10,20,30,40,50,60,70,80] AS id,
|
||||
ARRAY[800, 700, 600, 500, 400, 300, 200, 100] AS p,
|
||||
ARRAY[ST_GeomFromText('POINT(2.1744 41.403)'),ST_GeomFromText('POINT(2.1228 41.380)'),ST_GeomFromText('POINT(2.1511 41.374)'),ST_GeomFromText('POINT(2.1528 41.413)'),ST_GeomFromText('POINT(2.165 41.391)'),ST_GeomFromText('POINT(2.1498 41.371)'),ST_GeomFromText('POINT(2.1533 41.368)'),ST_GeomFromText('POINT(2.131386 41.41399)')] AS g
|
||||
)
|
||||
SELECT
|
||||
g.the_geom,
|
||||
g.h,
|
||||
g.hpop,
|
||||
g.dist
|
||||
FROM
|
||||
t,
|
||||
s,
|
||||
cdb_crankshaft.CDB_Gravity(t.id, t.g, t.w, s.id, s.g, s.p, 2, 100000, 3) g;
|
||||
@@ -1,12 +1,21 @@
|
||||
SET client_min_messages TO WARNING;
|
||||
\set ECHO none
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
\pset format unaligned
|
||||
|
||||
>>>>>>> ebbf68af5700f33737ac18516e2bdc22ea330b24
|
||||
WITH a AS (
|
||||
SELECT
|
||||
ARRAY[800, 700, 600, 500, 400, 300, 200, 100] AS vals,
|
||||
ARRAY[ST_GeomFromText('POINT(2.1744 41.403)'),ST_GeomFromText('POINT(2.1228 41.380)'),ST_GeomFromText('POINT(2.1511 41.374)'),ST_GeomFromText('POINT(2.1528 41.413)'),ST_GeomFromText('POINT(2.165 41.391)'),ST_GeomFromText('POINT(2.1498 41.371)'),ST_GeomFromText('POINT(2.1533 41.368)'),ST_GeomFromText('POINT(2.131386 41.41399)')] AS g
|
||||
)
|
||||
<<<<<<< HEAD
|
||||
SELECT
|
||||
CDB_SpatialInterpolation(g, vals, ST_GeomFromText('POINT(2.154 41.37)'),0) as NN,
|
||||
CDB_SpatialInterpolation(g, vals, ST_GeomFromText('POINT(2.154 41.37)'),1) as NNI,
|
||||
CDB_SpatialInterpolation(g, vals, ST_GeomFromText('POINT(2.154 41.37)'),2) as IDW
|
||||
FROM a;
|
||||
=======
|
||||
SELECT (cdb_crankshaft.CDB_SpatialInterpolation(g, vals, ST_GeomFromText('POINT(2.154 41.37)'), 1) - 780.79470198683925288365) / 780.79470198683925288365 < 0.001 As cdb_spatialinterpolation FROM a;
|
||||
>>>>>>> ebbf68af5700f33737ac18516e2bdc22ea330b24
|
||||
|
||||
@@ -4,7 +4,7 @@ SELECT cdb_crankshaft._cdb_random_seeds(1234);
|
||||
SET ROLE test_regular_user;
|
||||
|
||||
-- Add to the search path the schema
|
||||
SET search_path TO public,cartodb,cdb_crankshaft;
|
||||
SET search_path TO public,cdb_crankshaft;
|
||||
|
||||
-- Exercise public functions
|
||||
SELECT ppoints.code, m.quads
|
||||
|
||||
Reference in New Issue
Block a user