updating test for 41

This commit is contained in:
Andy Eschbacher 2016-05-05 16:22:08 -04:00
parent d4b0f72016
commit 67c66358e8
2 changed files with 35 additions and 28 deletions

View File

@ -156,6 +156,7 @@ DECLARE
BEGIN BEGIN
geom_table_name := cdb_observatory._OBS_GeomTable(geom, geometry_level); geom_table_name := cdb_observatory._OBS_GeomTable(geom, geometry_level);
RAISE NOTICE 'geom_table_name: %', geom_table_name;
IF geom_table_name IS NULL IF geom_table_name IS NULL
THEN THEN
@ -170,11 +171,14 @@ BEGIN
INTO data_table_info INTO data_table_info
using geometry_level, column_ids, time_span; using geometry_level, column_ids, time_span;
RAISE NOTICE 'data_table_info: %', data_table_info::text;
IF ST_GeometryType(geom) = 'ST_Point' IF ST_GeometryType(geom) = 'ST_Point'
THEN THEN
results := cdb_observatory._OBS_GetPoints(geom, results := cdb_observatory._OBS_GetPoints(geom,
geom_table_name, geom_table_name,
data_table_info); data_table_info);
RAISE NOTICE 'results: %', results;
ELSIF ST_GeometryType(geom) IN ('ST_Polygon', 'ST_MultiPolygon') ELSIF ST_GeometryType(geom) IN ('ST_Polygon', 'ST_MultiPolygon')
THEN THEN
@ -713,7 +717,7 @@ BEGIN
INTO geoid; INTO geoid;
query := 'SELECT ARRAY['; query := 'SELECT ARRAY[';
FOR i IN 1..array_upper(data_table_info, 1) FOR i IN 1..coalesce(array_upper(data_table_info, 1), 1)
LOOP LOOP
query = query || format('%I ', lower(((data_table_info)[i])->>'colname')); query = query || format('%I ', lower(((data_table_info)[i])->>'colname'));
IF i < array_upper(data_table_info, 1) IF i < array_upper(data_table_info, 1)

View File

@ -1,38 +1,41 @@
\i test/sql/load_fixtures.sql \i test/fixtures/load_fixtures.sql
\pset format unaligned
\set ECHO none
-- --
WITH result as( WITH result as(
Select count(coalesce(OBS_GetDemographicSnapshot->>'value', 'foo')) expected_columns Select count(coalesce(OBS_GetDemographicSnapshot->>'value', 'foo')) expected_columns
FROM cdb_observatory.OBS_GetDemographicSnapshot(cdb_observatory._TestPoint()) FROM cdb_observatory.OBS_GetDemographicSnapshot(cdb_observatory._TestPoint())
) select expected_columns ='58' as OBS_GetDemographicSnapshot_test_no_returns ) select expected_columns ='59' as OBS_GetDemographicSnapshot_test_no_returns
FROM result; FROM result;
-- --
-- names | vals -- names | vals
-- -----------|------- -- --------------|-------
-- gini_index | 0.3494 -- median_income | 45122
WITH result as ( WITH result as (
SELECT _OBS_Get::text as expected FROM SELECT _OBS_Get::text as expected FROM
cdb_observatory._OBS_Get( cdb_observatory._OBS_Get(
cdb_observatory._TestPoint(), cdb_observatory._TestPoint(),
Array['us.census.acs.B19083001']::text[], Array['us.census.acs.B19013001']::text[],
'2009 - 2013', '2010 - 2014',
'us.census.tiger.block_group' 'us.census.tiger.block_group'
) )
) select expected = '{"value":0.3494,"name":"Gini Index","tablename":"obs_3e7cc9cfd403b912c57b42d5f9195af9ce2f3cdb","aggregate":"","type":"Numeric","description":""}' ) SELECT expected = '{"value":79292,"name":"Median Household Income in the past 12 Months","tablename":"obs_1a098da56badf5f32e336002b0a81708c40d29cd","aggregate":"median","type":"Numeric","description":"Within a geographic area, the median income received by every household on a regular basis before payments for personal income taxes, social security, union dues, medicare deductions, etc. It includes income received from wages, salary, commissions, bonuses, and tips; self-employment income from own nonfarm or farm businesses, including proprietorships and partnerships; interest, dividends, net rental income, royalty income, or income from estates and trusts; Social Security or Railroad Retirement income; Supplemental Security Income (SSI); any cash public assistance or welfare payments from the state or local welfare office; retirement, survivor, or disability benefits; and any other sources of income received regularly such as Veterans'' (VA) payments, unemployment and/or worker''s compensation, child support, and alimony."}'
as OBS_Get_gini_index_at_test_point As OBS_Get_median_income_at_test_point
from result; FROM result;
-- gini index at null island -- median income at null island
WITH result as ( WITH result as (
SELECT count(_OBS_Get) as expected FROM SELECT count(_OBS_Get) as expected FROM
cdb_observatory._OBS_Get( cdb_observatory._OBS_Get(
ST_SetSRID(ST_Point(0, 0), 4326), ST_SetSRID(ST_Point(0, 0), 4326),
Array['us.census.acs.B19083001']::text[], Array['us.census.acs.B19013001']::text[],
'2009 - 2013', '2010 - 2014',
'us.census.tiger.block_group' 'us.census.tiger.block_group'
) )
) select expected = 0 as OBS_Get_gini_index_at_null_island ) select expected = 0 as OBS_Get_median_income_at_null_island
from result; from result;
-- OBS_GetPoints -- OBS_GetPoints
@ -43,17 +46,17 @@ WITH result as (
SELECT SELECT
(cdb_observatory._OBS_GetPoints( (cdb_observatory._OBS_GetPoints(
cdb_observatory._TestPoint(), cdb_observatory._TestPoint(),
'obs_a92e1111ad3177676471d66bb8036e6d057f271b'::text, -- see example in obs_geomtable 'obs_1a098da56badf5f32e336002b0a81708c40d29cd'::text, -- see example in obs_geomtable
(Array['{"colname":"total_pop","tablename":"obs_ab038198aaab3f3cb055758638ee4de28ad70146","aggregate":"sum","name":"Total Population","type":"Numeric","description":"The total number of all people living in a given geographic area. This is a very useful catch-all denominator when calculating rates."}'::json]) (Array['{"colname":"total_pop","tablename":"obs_1a098da56badf5f32e336002b0a81708c40d29cd","aggregate":"sum","name":"Total Population","type":"Numeric","description":"The total number of all people living in a given geographic area. This is a very useful catch-all denominator when calculating rates."}'::json])
))[1]::text = '{"value":4809.07989821893,"name":"Total Population","tablename":"obs_ab038198aaab3f3cb055758638ee4de28ad70146","aggregate":"sum","type":"Numeric","description":"The total number of all people living in a given geographic area. This is a very useful catch-all denominator when calculating rates."}' ))[1]::text = '{"value":4809.07989821893,"name":"Total Population","tablename":"obs_1a098da56badf5f32e336002b0a81708c40d29cd","aggregate":"sum","type":"Numeric","description":"The total number of all people living in a given geographic area. This is a very useful catch-all denominator when calculating rates."}'
as OBS_GetPoints_for_test_point; as OBS_GetPoints_for_test_point;
-- what happens at null island -- what happens at null island
SELECT SELECT
(cdb_observatory._OBS_GetPoints( (cdb_observatory._OBS_GetPoints(
ST_SetSRID(ST_Point(0, 0), 4326), ST_SetSRID(ST_Point(0, 0), 4326),
'obs_a92e1111ad3177676471d66bb8036e6d057f271b'::text, -- see example in obs_geomtable 'obs_1a098da56badf5f32e336002b0a81708c40d29cd'::text, -- see example in obs_geomtable
(Array['{"colname":"total_pop","tablename":"obs_ab038198aaab3f3cb055758638ee4de28ad70146","aggregate":"sum","name":"Total Population","type":"Numeric","description":"The total number of all people living in a given geographic area. This is a very useful catch-all denominator when calculating rates."}'::json]) (Array['{"colname":"total_pop","tablename":"obs_1a098da56badf5f32e336002b0a81708c40d29cd","aggregate":"sum","name":"Total Population","type":"Numeric","description":"The total number of all people living in a given geographic area. This is a very useful catch-all denominator when calculating rates."}'::json])
))[1]::text is null ))[1]::text is null
as OBS_GetPoints_for_null_island; as OBS_GetPoints_for_null_island;
@ -65,18 +68,18 @@ SELECT
SELECT SELECT
(cdb_observatory._OBS_GetPolygons( (cdb_observatory._OBS_GetPolygons(
cdb_observatory._TestArea(), cdb_observatory._TestArea(),
'obs_a92e1111ad3177676471d66bb8036e6d057f271b'::text, -- see example in obs_geomtable 'obs_1a098da56badf5f32e336002b0a81708c40d29cd'::text, -- see example in obs_geomtable
Array['{"colname":"total_pop","tablename":"obs_ab038198aaab3f3cb055758638ee4de28ad70146","aggregate":"sum","name":"Total Population","type":"Numeric","description":"The total number of all people living in a given geographic area. This is a very useful catch-all denominator when calculating rates."}'::json] Array['{"colname":"total_pop","tablename":"obs_1a098da56badf5f32e336002b0a81708c40d29cd","aggregate":"sum","name":"Total Population","type":"Numeric","description":"The total number of all people living in a given geographic area. This is a very useful catch-all denominator when calculating rates."}'::json]
))[1]::text = '{"value":1570.78845496678,"name":"Total Population","tablename":"obs_ab038198aaab3f3cb055758638ee4de28ad70146","aggregate":"sum","type":"Numeric","description":"The total number of all people living in a given geographic area. This is a very useful catch-all denominator when calculating rates."}' ))[1]::text = '{"value":1570.78845496678,"name":"Total Population","tablename":"obs_1a098da56badf5f32e336002b0a81708c40d29cd","aggregate":"sum","type":"Numeric","description":"The total number of all people living in a given geographic area. This is a very useful catch-all denominator when calculating rates."}'
as OBS_GetPolygons_for_test_point; as OBS_GetPolygons_for_test_point;
-- see what happens around null island -- see what happens around null island
SELECT SELECT
(cdb_observatory._OBS_GetPolygons( ((cdb_observatory._OBS_GetPolygons(
ST_Buffer(ST_SetSRID(ST_Point(0, 0), 4326)::geography, 500)::geometry, ST_Buffer(ST_SetSRID(ST_Point(0, 0), 4326)::geography, 500)::geometry,
'obs_a92e1111ad3177676471d66bb8036e6d057f271b'::text, -- see example in obs_geomtable 'obs_1a098da56badf5f32e336002b0a81708c40d29cd'::text, -- see example in obs_geomtable
Array['{"colname":"total_pop","tablename":"obs_ab038198aaab3f3cb055758638ee4de28ad70146","aggregate":"sum","name":"Total Population","type":"Numeric","description":"The total number of all people living in a given geographic area. This is a very useful catch-all denominator when calculating rates."}'::json]) Array['{"colname":"total_pop","tablename":"obs_1a098da56badf5f32e336002b0a81708c40d29cd","aggregate":"sum","name":"Total Population","type":"Numeric","description":"The total number of all people living in a given geographic area. This is a very useful catch-all denominator when calculating rates."}'::json])
)[1]->>'value' is null )[1]->>'value') is null
as OBS_GetPolygons_for_null_island; as OBS_GetPolygons_for_null_island;
SELECT cdb_observatory.OBS_GetSegmentSnapshot( SELECT cdb_observatory.OBS_GetSegmentSnapshot(
@ -174,4 +177,4 @@ SELECT cdb_observatory.OBS_GetUSCensusCategory(
cdb_observatory._testarea(), 'SS Segment, 10 clusters'); cdb_observatory._testarea(), 'SS Segment, 10 clusters');
\i test/sql/drop_fixtures.sql \i test/fixtures/drop_fixtures.sql