Merge remote-tracking branch 'origin/QLIK' into qlik-alfa-plproxy

Conflicts:
	src/pg/test/expected/40_observatory_utility_test.out
	src/pg/test/sql/40_observatory_utility_test.sql
This commit is contained in:
Rafa de la Torre 2016-04-19 14:26:41 +02:00
commit 7a215db14f
14 changed files with 682 additions and 39 deletions

View File

@ -301,7 +301,7 @@ BEGIN
IF results IS NULL
THEN
results := Array[];
results := Array[]::numeric[];
END IF;
RETURN QUERY SELECT names, results;
@ -315,7 +315,6 @@ CREATE OR REPLACE FUNCTION OBS_GetPoints(
geom geometry,
geom_table_name text,
data_table_info OBS_ColumnData[]
)
RETURNS NUMERIC[]
AS $$
@ -346,15 +345,25 @@ BEGIN
geoid)
INTO area;
IF area IS NULL
THEN
RAISE NOTICE 'No geometry at %', ST_AsText(geom);
END IF;
query := 'SELECT ARRAY[';
query := 'SELECT Array[';
FOR i IN 1..array_upper(data_table_info, 1)
LOOP
IF ((data_table_info)[i]).aggregate != 'sum'
IF area is NULL OR area = 0
THEN
query = query || format('%I ', ((data_table_info)[i]).colname);
-- give back null values
query := query || format('NULL::numeric ');
ELSIF ((data_table_info)[i]).aggregate != 'sum'
THEN
-- give back full variable
query := query || format('%I ', ((data_table_info)[i]).colname);
ELSE
query = query || format('%I/%s ',
-- give back variable normalized by area of geography
query := query || format('%I/%s ',
((data_table_info)[i]).colname,
area);
END IF;
@ -365,7 +374,7 @@ BEGIN
END IF;
END LOOP;
query := query || format(' ]
query := query || format(' ]::numeric[]
FROM observatory.%I
WHERE %I.geoid = %L
',
@ -398,8 +407,8 @@ DECLARE
i NUMERIC;
BEGIN
q_select := 'select geoid, ';
q_sum := 'select Array[';
q_select := 'SELECT geoid, ';
q_sum := 'SELECT Array[';
FOR i IN 1..array_upper(data_table_info, 1)
LOOP
@ -409,7 +418,7 @@ BEGIN
THEN
q_sum := q_sum || format('sum(overlap_fraction * COALESCE(%I, 0)) ',((data_table_info)[i]).colname,((data_table_info)[i]).colname);
ELSE
q_sum := q_sum || ' null ';
q_sum := q_sum || ' NULL::numeric ';
END IF;
IF i < array_upper(data_table_info,1)
@ -433,7 +442,7 @@ BEGIN
q := q || q_select || format('FROM observatory.%I ', ((data_table_info)[1].tablename));
q := q || ' ) ' || q_sum || ' ] FROM _overlaps, values
q := q || ' ) ' || q_sum || ' ]::numeric[] FROM _overlaps, values
WHERE values.geoid = _overlaps.geoid';
EXECUTE
@ -495,8 +504,8 @@ RETURNS TABLE(
percent_income_spent_on_rent_quantile NUMERIC,
owner_occupied_housing_units_quantile NUMERIC,
million_dollar_housing_units_quantile NUMERIC
) AS $$
)
AS $$
DECLARE
target_cols text[];
seg_name Text;
@ -553,17 +562,17 @@ target_cols := Array[
EXECUTE
$query$
SELECT (categories)[1]
FROM OBS_GetCategories($1,
Array['"us.census.spielman_singleton_segments".X10'],
$2
)
LIMIT 1
FROM OBS_GetCategories(
$1,
Array['"us.census.spielman_singleton_segments".X10'],
$2)
LIMIT 1
$query$
INTO segment_name
USING geom, geometry_level;
q :=
format( $query$
format($query$
WITH a As (
SELECT
names As names,
@ -641,7 +650,7 @@ BEGIN
END IF;
END LOOP;
query := query || format(' ]
query := query || format(' ]::text[]
FROM observatory.%I
WHERE %I.geoid = %L
',

View File

@ -13,14 +13,24 @@ Loading obs_85328201013baa14e8e8a4a57a01e6f6fbc5f9b1.sql fixture file...
Done.
Loading obs_3e7cc9cfd403b912c57b42d5f9195af9ce2f3cdb.sql fixture file...
Done.
-- OBS_GeomTable
-- get table with known geometry_id
-- should give back a table like obs_{hex hash}
SELECT
cdb_observatory.OBS_GeomTable(
CDB_LatLng(40.7128,-74.0059),
'"us.census.tiger".census_tract'
);
Loading obs_column.sql fixture file...
Done.
Loading obs_column_table.sql fixture file...
Done.
Loading obs_column_to_column.sql fixture file...
Done.
Loading obs_85328201013baa14e8e8a4a57a01e6f6fbc5f9b1.sql fixture file...
Done.
Loading obs_3e7cc9cfd403b912c57b42d5f9195af9ce2f3cdb.sql fixture file...
Done.
Loading obs_ab038198aaab3f3cb055758638ee4de28ad70146.sql fixture file...
Done.
Loading obs_a92e1111ad3177676471d66bb8036e6d057f271b.sql fixture file...
Done.
Loading obs_11ee8b82c877c073438bc935a91d3dfccef875d1.sql fixture file...
Done.
Loading obs_d34555209878e8c4b37cf0b2b3d072ff129ec470.sql fixture file...
Done.
obs_geomtable
----------------------------------------------
obs_a92e1111ad3177676471d66bb8036e6d057f271b
@ -69,6 +79,11 @@ SELECT
obs_lookupcensushuman
---------------------------------
{"\"us.census.acs\".B19083001"}
(1 row)
obs_lookupcensushuman
-----------------------
(1 row)
-- OBS_BuildSnapshotQuery
@ -82,6 +97,12 @@ SELECT
SELECT vals[1] As total_pop, vals[2] As male_pop, vals[3] As female_pop, vals[4] As median_age
(1 row)
obs_buildsnapshotquery
------------------------------------
SELECT vals[1] As mandarin_orange
(1 row)
Dropping obs_table.sql fixture table...
\i test/sql/drop_fixtures.sql
SET client_min_messages TO NOTICE;
\set ECHO none
@ -97,3 +118,11 @@ Dropping obs_85328201013baa14e8e8a4a57a01e6f6fbc5f9b1 fixture table...
Done.
Dropping obs_3e7cc9cfd403b912c57b42d5f9195af9ce2f3cdb fixture table...
Done.
Dropping obs_ab038198aaab3f3cb055758638ee4de28ad70146 fixture table...
Done.
Dropping obs_a92e1111ad3177676471d66bb8036e6d057f271b fixture table...
Done.
Dropping obs_11ee8b82c877c073438bc935a91d3dfccef875d1 fixture table...
Done.
Dropping obs_d34555209878e8c4b37cf0b2b3d072ff129ec470 fixture table...
Done.

View File

@ -0,0 +1,123 @@
SELECT set_config(
'search_path',
current_setting('search_path') || ',cdb_observatory,observatory',
false
) WHERE current_setting('search_path') !~ '(^|,)(cdb_observatory|observatory)(,|$)';
set_config
------------------------------------------------------
"$user", public, cartodb,cdb_observatory,observatory
(1 row)
\i test/sql/load_fixtures.sql
SET client_min_messages TO WARNING;
\set ECHO none
Loading obs_table.sql fixture file...
Done.
Loading obs_column.sql fixture file...
Done.
Loading obs_column_table.sql fixture file...
Done.
Loading obs_column_to_column.sql fixture file...
Done.
Loading obs_85328201013baa14e8e8a4a57a01e6f6fbc5f9b1.sql fixture file...
Done.
Loading obs_3e7cc9cfd403b912c57b42d5f9195af9ce2f3cdb.sql fixture file...
Done.
Loading obs_ab038198aaab3f3cb055758638ee4de28ad70146.sql fixture file...
Done.
Loading obs_a92e1111ad3177676471d66bb8036e6d057f271b.sql fixture file...
Done.
Loading obs_11ee8b82c877c073438bc935a91d3dfccef875d1.sql fixture file...
Done.
Loading obs_d34555209878e8c4b37cf0b2b3d072ff129ec470.sql fixture file...
Done.
total_pop | male_pop | female_pop | median_age | white_pop | black_pop | asian_pop | hispanic_pop | amerindian_pop | other_race_pop | two_or_more_races_pop | not_hispanic_pop | households | pop_25_years_over | high_school_diploma | less_one_year_college | one_year_more_college | associates_degree | bachelors_degree | masters_degree | median_income | gini_index | income_per_capita | housing_units | vacant_housing_units | vacant_housing_units_for_rent | vacant_housing_units_for_sale | median_rent | percent_income_spent_on_rent | owner_occupied_housing_units | million_dollar_housing_units | mortgaged_housing_units | commuters_16_over | commute_less_10_mins | commute_10_14_mins | commute_15_19_mins | commute_20_24_mins | commute_25_29_mins | commute_30_34_mins | commute_35_44_mins | commute_45_59_mins | commute_60_more_mins | aggregate_travel_time_to_work | income_less_10000 | income_10000_14999 | income_15000_19999 | income_20000_24999 | income_25000_29999 | income_30000_34999 | income_35000_39999 | income_40000_44999 | income_45000_49999 | income_50000_59999 | income_60000_74999 | income_75000_99999 | income_100000_124999 | income_125000_149999 | income_150000_199999 | income_200000_or_more | land_area
------------------+------------------+------------------+------------+------------------+------------------+------------------+------------------+----------------+----------------+-----------------------+------------------+------------------+-------------------+---------------------+-----------------------+-----------------------+-------------------+------------------+------------------+---------------+------------+-------------------+------------------+----------------------+-------------------------------+-------------------------------+-------------+------------------------------+------------------------------+------------------------------+-------------------------+-------------------+----------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+----------------------+-------------------------------+-------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+----------------------+----------------------+----------------------+-----------------------+-----------
9516.27603138953 | 6152.51682996181 | 3363.75920142772 | 28.8 | 5301.51450207924 | 149.500408952343 | 230.000629157451 | 3835.26049120049 | 0 | 0 | 0 | 5681.01554018904 | 3323.50909132517 | 7107.01944096523 | 1040.75284693747 | 69.0001887472353 | 793.502170593206 | 327.750896549367 | 2742.7575027026 | 931.502548087676 | 66304 | 0.3494 | 28291 | 3662.76001933241 | 339.25092800724 | 120.750330307662 | 0 | 1764 | 35.3 | 339.25092800724 | 0 | 224.250613428515 | 6549.26791525841 | 327.750896549367 | 28.7500786446814 | 201.25055051277 | 621.001698725117 | 373.751022380858 | 1851.50506471748 | 1414.50386931832 | 1115.50305141364 | 615.251682996181 | | 57.5001572893627 | 0 | 212.750581970642 | 408.251116754475 | 0 | 155.250424681279 | 109.250298849789 | 92.0002516629803 | 63.250173018299 | 184.000503325961 | 621.001698725117 | 552.001509977882 | 327.750896549367 | 333.500912278304 | 126.500346036598 | |
(1 row)
dimension | dimension_value
----------------------+-------------------------------------
{total_pop,male_pop} | {9516.27603138953,6152.51682996181}
(1 row)
dimension | dimension_value
-----------------------+-----------------
{female_pop,male_pop} | {NULL,NULL}
(1 row)
dimension | dimension_value
-----------------------+-----------------
{female_pop,male_pop} | {}
(1 row)
names | vals
--------------+----------
{gini_index} | {0.3494}
(1 row)
names | vals
--------------+------
{gini_index} | {}
(1 row)
obs_getpoints
--------------------
{4809.33380072727}
(1 row)
obs_getpoints
---------------
(1 row)
obs_getpolygons
--------------------
{1570.72353789469}
(1 row)
obs_getpolygons
-----------------
{NULL}
(1 row)
segment_name | total_pop_quantile | male_pop_quantile | female_pop_quantile | median_age_quantile | white_pop_quantile | black_pop_quantile | asian_pop_quantile | hispanic_pop_quantile | not_us_citizen_pop_quantile | workers_16_and_over_quantile | commuters_by_car_truck_van_quantile | commuters_by_public_transportation_quantile | commuters_by_bus_quantile | commuters_by_subway_or_elevated_quantile | walked_to_work_quantile | worked_at_home_quantile | children_quantile | households_quantile | population_3_years_over_quantile | in_school_quantile | in_grades_1_to_4_quantile | in_grades_5_to_8_quantile | in_grades_9_to_12_quantile | in_undergrad_college_quantile | pop_25_years_over_quantile | high_school_diploma_quantile | bachelors_degree_quantile | masters_degree_quantile | pop_5_years_over_quantile | speak_only_english_at_home_quantile | speak_spanish_at_home_quantile | pop_determined_poverty_status_quantile | poverty_quantile | median_income_quantile | gini_index_quantile | income_per_capita_quantile | housing_units_quantile | vacant_housing_units_quantile | vacant_housing_units_for_rent_quantile | vacant_housing_units_for_sale_quantile | median_rent_quantile | percent_income_spent_on_rent_quantile | owner_occupied_housing_units_quantile | million_dollar_housing_units_quantile
-----------------------------+--------------------+-------------------+---------------------+---------------------+--------------------+--------------------+--------------------+-----------------------+-----------------------------+------------------------------+-------------------------------------+---------------------------------------------+---------------------------+------------------------------------------+-------------------------+-------------------------+--------------------+---------------------+----------------------------------+--------------------+---------------------------+---------------------------+----------------------------+-------------------------------+----------------------------+------------------------------+---------------------------+-------------------------+---------------------------+-------------------------------------+--------------------------------+----------------------------------------+-------------------+------------------------+---------------------+----------------------------+------------------------+-------------------------------+----------------------------------------+----------------------------------------+----------------------+---------------------------------------+---------------------------------------+---------------------------------------
Wealthy, urban without Kids | 0.234783783783784 | 0.422405405405405 | 0.0987567567567568 | 0.0715 | 0.295310810810811 | 0.407189189189189 | 0.625608108108108 | 0.795202702702703 | 0.703797297297297 | 0.59227027027027 | 0.0180540540540541 | 0.993756756756757 | 0.728162162162162 | 0.995972972972973 | 0.929135135135135 | 0.625432432432432 | 0.0386081081081081 | 0.157121621621622 | 0.241878378378378 | 0.173783783783784 | 0.0380675675675676 | 0.0308108108108108 | 0.0486216216216216 | 0.479743243243243 | 0.297675675675676 | 0.190351351351351 | 0.802513513513514 | 0.757148648648649 | 0.255405405405405 | 0.196094594594595 | 0.816851351351351 | 0.252513513513514 | 0.560054054054054 | 0.777472972972973 | 0.336932432432432 | 0.655378378378378 | 0.141810810810811 | 0.362824324324324 | 0.463837837837838 | 0 | 0.939040540540541 | 0.419445945945946 | 0.0387972972972973 | 0
(1 row)
segment_name | total_pop_quantile | male_pop_quantile | female_pop_quantile | median_age_quantile | white_pop_quantile | black_pop_quantile | asian_pop_quantile | hispanic_pop_quantile | not_us_citizen_pop_quantile | workers_16_and_over_quantile | commuters_by_car_truck_van_quantile | commuters_by_public_transportation_quantile | commuters_by_bus_quantile | commuters_by_subway_or_elevated_quantile | walked_to_work_quantile | worked_at_home_quantile | children_quantile | households_quantile | population_3_years_over_quantile | in_school_quantile | in_grades_1_to_4_quantile | in_grades_5_to_8_quantile | in_grades_9_to_12_quantile | in_undergrad_college_quantile | pop_25_years_over_quantile | high_school_diploma_quantile | bachelors_degree_quantile | masters_degree_quantile | pop_5_years_over_quantile | speak_only_english_at_home_quantile | speak_spanish_at_home_quantile | pop_determined_poverty_status_quantile | poverty_quantile | median_income_quantile | gini_index_quantile | income_per_capita_quantile | housing_units_quantile | vacant_housing_units_quantile | vacant_housing_units_for_rent_quantile | vacant_housing_units_for_sale_quantile | median_rent_quantile | percent_income_spent_on_rent_quantile | owner_occupied_housing_units_quantile | million_dollar_housing_units_quantile
--------------+--------------------+-------------------+---------------------+---------------------+--------------------+--------------------+--------------------+-----------------------+-----------------------------+------------------------------+-------------------------------------+---------------------------------------------+---------------------------+------------------------------------------+-------------------------+-------------------------+-------------------+---------------------+----------------------------------+--------------------+---------------------------+---------------------------+----------------------------+-------------------------------+----------------------------+------------------------------+---------------------------+-------------------------+---------------------------+-------------------------------------+--------------------------------+----------------------------------------+------------------+------------------------+---------------------+----------------------------+------------------------+-------------------------------+----------------------------------------+----------------------------------------+----------------------+---------------------------------------+---------------------------------------+---------------------------------------
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
(1 row)
names | categories
-----------+---------------------------------------------------------------
{X10,x10} | {"Wealthy, urban without Kids","Wealthy, urban without Kids"}
(1 row)
names | categories
-----------+------------
{X10,x10} |
(1 row)
Dropping obs_table.sql fixture table...
Done.
Dropping obs_column.sql fixture table...
Done.
Dropping obs_column_table.sql fixture table...
Done.
Dropping obs_column_to_column.sql fixture table...
Done.
Dropping obs_85328201013baa14e8e8a4a57a01e6f6fbc5f9b1 fixture table...
Done.
Dropping obs_3e7cc9cfd403b912c57b42d5f9195af9ce2f3cdb fixture table...
Done.
Dropping obs_ab038198aaab3f3cb055758638ee4de28ad70146 fixture table...
Done.
Dropping obs_a92e1111ad3177676471d66bb8036e6d057f271b fixture table...
Done.
Dropping obs_11ee8b82c877c073438bc935a91d3dfccef875d1 fixture table...
Done.
Dropping obs_d34555209878e8c4b37cf0b2b3d072ff129ec470 fixture table...
Done.

View File

@ -0,0 +1,17 @@
CREATE TABLE IF NOT EXISTS obs_11ee8b82c877c073438bc935a91d3dfccef875d1 (
cartodb_id integer,
the_geom geometry(Geometry,4326),
the_geom_webmercator geometry(Geometry,3857),
geoid text,
x10 text,
x2 text,
x31 text,
x55 text
);
INSERT INTO obs_11ee8b82c877c073438bc935a91d3dfccef875d1 (cartodb_id, the_geom, the_geom_webmercator, geoid, x10, x2, x31, x55) VALUES (2150, NULL, NULL, '36047048500', 'Wealthy, urban without Kids', '8', '15', '1');
CREATE SCHEMA IF NOT EXISTS observatory;
ALTER TABLE obs_11ee8b82c877c073438bc935a91d3dfccef875d1 SET SCHEMA observatory;

View File

@ -1,5 +1,5 @@
CREATE TABLE obs_3e7cc9cfd403b912c57b42d5f9195af9ce2f3cdb (
CREATE TABLE IF NOT EXISTS obs_3e7cc9cfd403b912c57b42d5f9195af9ce2f3cdb (
cartodb_id integer,
the_geom geometry(Geometry,4326),
the_geom_webmercator geometry(Geometry,3857),
@ -126,4 +126,4 @@ CREATE TABLE obs_3e7cc9cfd403b912c57b42d5f9195af9ce2f3cdb (
INSERT INTO obs_3e7cc9cfd403b912c57b42d5f9195af9ce2f3cdb (cartodb_id, the_geom, the_geom_webmercator, geoid, total_pop, male_pop, female_pop, median_age, white_pop, black_pop, asian_pop, hispanic_pop, amerindian_pop, other_race_pop, two_or_more_races_pop, not_hispanic_pop, not_us_citizen_pop, workers_16_and_over, commuters_by_car_truck_van, commuters_drove_alone, commuters_by_carpool, commuters_by_public_transportation, commuters_by_bus, commuters_by_subway_or_elevated, walked_to_work, worked_at_home, children, households, population_3_years_over, in_school, in_grades_1_to_4, in_grades_5_to_8, in_grades_9_to_12, in_undergrad_college, pop_25_years_over, high_school_diploma, less_one_year_college, one_year_more_college, associates_degree, bachelors_degree, masters_degree, pop_5_years_over, speak_only_english_at_home, speak_spanish_at_home, pop_determined_poverty_status, poverty, median_income, gini_index, income_per_capita, housing_units, vacant_housing_units, vacant_housing_units_for_rent, vacant_housing_units_for_sale, median_rent, percent_income_spent_on_rent, owner_occupied_housing_units, million_dollar_housing_units, mortgaged_housing_units, families_with_young_children, two_parent_families_with_young_children, two_parents_in_labor_force_families_with_young_children, two_parents_father_in_labor_force_families_with_young_children, two_parents_mother_in_labor_force_families_with_young_children, two_parents_not_in_labor_force_families_with_young_children, one_parent_families_with_young_children, father_one_parent_families_with_young_children, men_45_to_64, men_45_to_49, men_50_to_54, men_55_to_59, men_60_61, men_62_64, black_men_45_54, black_men_55_64, hispanic_men_45_54, hispanic_men_55_64, white_men_45_54, white_men_55_64, asian_men_45_54, asian_men_55_64, men_45_64_less_than_9_grade, men_45_64_grade_9_12, men_45_64_high_school, men_45_64_some_college, men_45_64_associates_degree, men_45_64_bachelors_degree, men_45_64_graduate_degree, father_in_labor_force_one_parent_families_with_young_children, pop_15_and_over, pop_never_married, pop_now_married, pop_separated, pop_widowed, pop_divorced, commuters_16_over, commute_less_10_mins, commute_10_14_mins, commute_15_19_mins, commute_20_24_mins, commute_25_29_mins, commute_30_34_mins, commute_35_44_mins, commute_45_59_mins, commute_60_more_mins, aggregate_travel_time_to_work, income_less_10000, income_10000_14999, income_15000_19999, income_20000_24999, income_25000_29999, income_30000_34999, income_35000_39999, income_40000_44999, income_45000_49999, income_50000_59999, income_60000_74999, income_75000_99999, income_100000_124999, income_125000_149999, income_150000_199999, income_200000_or_more) VALUES (132625, NULL, NULL, '360470485002', 1655, 1070, 585, 28.8000000000000007, 922, 26, 40, 667, 0, 0, 0, 988, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 578, NULL, NULL, NULL, NULL, NULL, NULL, 1236, 181, 12, 138, 57, 477, 162, NULL, NULL, NULL, NULL, NULL, 66304, 0.349399999999999988, 28291, 637, 59, 21, 0, 1764, 35.2999999999999972, 59, 0, 39, 60, 47, 22, 25, 0, 0, 13, 0, NULL, 12, 64, 6, 15, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, 1139, 57, 5, 35, 108, 65, 322, 246, 194, 107, NULL, 10, 0, 37, 71, 0, 27, 19, 16, 11, 32, 108, 96, 57, 58, 22, 14);
CREATE SCHEMA IF NOT EXISTS observatory;
ALTER TABLE obs_3e7cc9cfd403b912c57b42d5f9195af9ce2f3cdb SET SCHEMA observatory;
ALTER TABLE obs_3e7cc9cfd403b912c57b42d5f9195af9ce2f3cdb SET SCHEMA observatory;

View File

@ -1,5 +1,5 @@
CREATE TABLE obs_85328201013baa14e8e8a4a57a01e6f6fbc5f9b1 (
CREATE TABLE IF NOT EXISTS obs_85328201013baa14e8e8a4a57a01e6f6fbc5f9b1 (
cartodb_id integer,
the_geom geometry(Geometry,4326),
the_geom_webmercator geometry(Geometry,3857),
@ -10,4 +10,3 @@ INSERT INTO obs_85328201013baa14e8e8a4a57a01e6f6fbc5f9b1(cartodb_id, the_geom, t
CREATE SCHEMA IF NOT EXISTS observatory;
ALTER TABLE obs_85328201013baa14e8e8a4a57a01e6f6fbc5f9b1 SET SCHEMA observatory;

View File

@ -0,0 +1,12 @@
CREATE TABLE IF NOT EXISTS obs_a92e1111ad3177676471d66bb8036e6d057f271b (
cartodb_id integer,
the_geom geometry(Geometry,4326),
the_geom_webmercator geometry(Geometry,3857),
geoid text
);
INSERT INTO obs_a92e1111ad3177676471d66bb8036e6d057f271b (cartodb_id, the_geom, the_geom_webmercator, geoid) VALUES (42130, '0106000020E6100000010000000103000000010000003500000056EF703B347C52C054FF2092215B44401B9AB2D30F7C52C03FE1ECD6325B4440B14B546F0D7C52C0BBCE86FC335B4440730F09DFFB7B52C0B796C9703C5B4440108FC4CBD37B52C0B96C74CE4F5B444001C0B167CF7B52C0ED0BE8853B5B4440C843DFDDCA7B52C05DDDB1D8265B4440A73D25E7C47B52C0D53BDC0E0D5B4440BB5E9A22C07B52C0F8A3A833F75A4440355F251FBB7B52C0B64604E3E05A444008910C39B67B52C098BF42E6CA5A44405227A089B07B52C0F204C24EB15A444024F1F274AE7B52C069E4F38AA75A44402B4A09C1AA7B52C06B63EC84975A4440E199D024B17B52C0546F0D6C955A44403C873254C57B52C02EAC1BEF8E5A44402593533BC37B52C0588AE42B815A4440973AC8EBC17B52C087890629785A44407A6F0C01C07B52C0E1EB6B5D6A5A44401B9B1DA9BE7B52C03F6F2A52615A444088855AD3BC7B52C088669E5C535A4440E1EA0088BB7B52C0E6E95C514A5A44400CE6AF90B97B52C070D05E7D3C5A44401E85EB51B87B52C0B03A72A4335A4440BAF3C473B67B52C09929ADBF255A4440CD920035B57B52C0454AB3791C5A4440F78DAF3DB37B52C0E09BA6CF0E5A4440DBC2F352B17B52C0703FE081015A444015C440D7BE7B52C05E83BEF4F659444041446ADAC57B52C0EFDFBC38F15944405FB1868BDC7B52C0C03E3A75E559444034BC5983F77B52C0205ED72FD8594440EFFCA204FD7B52C07E384888F25944403ACAC16C027C52C00876FC17085A444056478E74067C52C00FECF82F105A44400FECF82F107C52C0876D8B321B5A4440BB438A01127C52C0DE1CAED51E5A4440B9C15087157C52C034643C4A255A444099F221A81A7C52C0D0EFFB372F5A44404AED45B41D7C52C0785DBF60375A4440373465A71F7C52C065A71FD4455A4440C558A65F227C52C0D80DDB16655A4440F92EA52E197C52C09BA73AE4665A4440DEE522BE137C52C00664AF777F5A44405698BED7107C52C04759BF99985A444012D90759167C52C09430D3F6AF5A444044679945287C52C01F680586AC5A444049F086342A7C52C09CC3B5DAC35A44401FF5D72B2C7C52C0CB811E6ADB5A4440247EC51A2E7C52C0548B8862F25A4440FF59F3E32F7C52C0CB290131095B4440F96871C6307C52C09605137F145B444056EF703B347C52C054FF2092215B4440', '0106000020110F00000100000001030000000100000035000000CB0F2CEF1F665FC19DEDA02077F552416364A618E2655FC1D8D8EF798AF55241B40B7B08DE655FC199D7E7C28BF55241A3B11233C0655FC1B566E13B95F5524144B6AC207C655FC159D4CCEEAAF55241C19F52AB74655FC12A57B43494F552412CCFD9F56C655FC16DCEDF097DF552413D4D8DD462655FC12019DD2460F55241A97756BB5A655FC11519CDA747F552414BC1413752655FC1D30B38A72EF552416D0D0CE549655FC1694FB00416F55241DA23DD3C40655FC142906158F9F45241181B0FB43C655FC1A4E09E67EEF452419013EF6936655FC1B2DBC473DCF45241EBE7774441655FC1B4F8441ADAF45241AB9FC98D63655FC1594262D5D2F452411FBBDBFD5F655FC1E9AD116AC3F45241470CE7C35D655FC185FD8751B9F45241619957825A655FC1AB01DCDCA9F45241F732233A58655FC1E64AF3BA9FF45241FD0A331C55655FC1BF49541790F45241EE375EE952655FC1CF9272F585F45241AA316F924F655FC1D4F7757776F45241F8F1F9744D655FC1408CFE8D6CF452416B12CA484A655FC156BE40FD5CF45241B8D2542B48655FC149DCA39952F4524175CC65D444655FC106D3B94A43F452418E59D69241655FC1C23D366334F452419AA4818858655FC16C90219128F45241CD18C57164655FC1A533872422F45241BD2B21FD8A655FC1F390C1F614F45241B152F8CBB8655FC14A47B61806F452419ECAC825C2655FC16FDF6F9C23F45241D71BDA54CB655FC11F9B2BC43BF45241144F772DD2655FC116806FD544F45241AB4763B5E2655FC1CE331F2B51F45241DD9333CCE5655FC196244A3E55F45241BF29F5C7EB655FC1FB82AE795CF452419DE2E87DF4655FC145D3439967F45241B8920EABF9655FC1DB285EBD70F4524132BDDDFAFC655FC153A8E8ED80F452419841869901665FC1C596BEF3A3F45241EB9DB5FCF1655FC1418DA5F8A5F45241219564BFE8655FC1990A5B81C1F45241169F5DD2E3655FC18BDBEAA9DDF4524105172E2CED655FC108740AD7F7F452415F54539E0B665FC10CE331FCF3F452410FA302E70E665FC1D518FB1F0EF5524154A9F13D12665FC18624A18528F5524104F8A08615665FC1C8112C4242F55241A38C318F18665FC1E920CACF5BF552410EE9E90F1A665FC1834F6D7A68F55241CB0F2CEF1F665FC19DEDA02077F55241', '36047048500');
CREATE SCHEMA IF NOT EXISTS observatory;
ALTER TABLE obs_a92e1111ad3177676471d66bb8036e6d057f271b SET SCHEMA observatory;

View File

@ -0,0 +1,129 @@
CREATE TABLE IF NOT EXISTS obs_ab038198aaab3f3cb055758638ee4de28ad70146 (
cartodb_id integer,
the_geom geometry(Geometry,4326),
the_geom_webmercator geometry(Geometry,3857),
geoid text,
total_pop double precision,
male_pop double precision,
female_pop double precision,
median_age double precision,
white_pop double precision,
black_pop double precision,
asian_pop double precision,
hispanic_pop double precision,
amerindian_pop double precision,
other_race_pop double precision,
two_or_more_races_pop double precision,
not_hispanic_pop double precision,
not_us_citizen_pop double precision,
workers_16_and_over double precision,
commuters_by_car_truck_van double precision,
commuters_drove_alone double precision,
commuters_by_carpool double precision,
commuters_by_public_transportation double precision,
commuters_by_bus double precision,
commuters_by_subway_or_elevated double precision,
walked_to_work double precision,
worked_at_home double precision,
children double precision,
households double precision,
population_3_years_over double precision,
in_school double precision,
in_grades_1_to_4 double precision,
in_grades_5_to_8 double precision,
in_grades_9_to_12 double precision,
in_undergrad_college double precision,
pop_25_years_over double precision,
high_school_diploma double precision,
less_one_year_college double precision,
one_year_more_college double precision,
associates_degree double precision,
bachelors_degree double precision,
masters_degree double precision,
pop_5_years_over double precision,
speak_only_english_at_home double precision,
speak_spanish_at_home double precision,
pop_determined_poverty_status double precision,
poverty double precision,
median_income double precision,
gini_index double precision,
income_per_capita double precision,
housing_units double precision,
vacant_housing_units double precision,
vacant_housing_units_for_rent double precision,
vacant_housing_units_for_sale double precision,
median_rent double precision,
percent_income_spent_on_rent double precision,
owner_occupied_housing_units double precision,
million_dollar_housing_units double precision,
mortgaged_housing_units double precision,
families_with_young_children double precision,
two_parent_families_with_young_children double precision,
two_parents_in_labor_force_families_with_young_children double precision,
two_parents_father_in_labor_force_families_with_young_children double precision,
two_parents_mother_in_labor_force_families_with_young_children double precision,
two_parents_not_in_labor_force_families_with_young_children double precision,
one_parent_families_with_young_children double precision,
father_one_parent_families_with_young_children double precision,
men_45_to_64 double precision,
men_45_to_49 double precision,
men_50_to_54 double precision,
men_55_to_59 double precision,
men_60_61 double precision,
men_62_64 double precision,
black_men_45_54 double precision,
black_men_55_64 double precision,
hispanic_men_45_54 double precision,
hispanic_men_55_64 double precision,
white_men_45_54 double precision,
white_men_55_64 double precision,
asian_men_45_54 double precision,
asian_men_55_64 double precision,
men_45_64_less_than_9_grade double precision,
men_45_64_grade_9_12 double precision,
men_45_64_high_school double precision,
men_45_64_some_college double precision,
men_45_64_associates_degree double precision,
men_45_64_bachelors_degree double precision,
men_45_64_graduate_degree double precision,
father_in_labor_force_one_parent_families_with_young_children double precision,
pop_15_and_over double precision,
pop_never_married double precision,
pop_now_married double precision,
pop_separated double precision,
pop_widowed double precision,
pop_divorced double precision,
commuters_16_over double precision,
commute_less_10_mins double precision,
commute_10_14_mins double precision,
commute_15_19_mins double precision,
commute_20_24_mins double precision,
commute_25_29_mins double precision,
commute_30_34_mins double precision,
commute_35_44_mins double precision,
commute_45_59_mins double precision,
commute_60_more_mins double precision,
aggregate_travel_time_to_work double precision,
income_less_10000 double precision,
income_10000_14999 double precision,
income_15000_19999 double precision,
income_20000_24999 double precision,
income_25000_29999 double precision,
income_30000_34999 double precision,
income_35000_39999 double precision,
income_40000_44999 double precision,
income_45000_49999 double precision,
income_50000_59999 double precision,
income_60000_74999 double precision,
income_75000_99999 double precision,
income_100000_124999 double precision,
income_125000_149999 double precision,
income_150000_199999 double precision,
income_200000_or_more double precision
);
INSERT INTO obs_ab038198aaab3f3cb055758638ee4de28ad70146 (cartodb_id, the_geom, the_geom_webmercator, geoid, total_pop, male_pop, female_pop, median_age, white_pop, black_pop, asian_pop, hispanic_pop, amerindian_pop, other_race_pop, two_or_more_races_pop, not_hispanic_pop, not_us_citizen_pop, workers_16_and_over, commuters_by_car_truck_van, commuters_drove_alone, commuters_by_carpool, commuters_by_public_transportation, commuters_by_bus, commuters_by_subway_or_elevated, walked_to_work, worked_at_home, children, households, population_3_years_over, in_school, in_grades_1_to_4, in_grades_5_to_8, in_grades_9_to_12, in_undergrad_college, pop_25_years_over, high_school_diploma, less_one_year_college, one_year_more_college, associates_degree, bachelors_degree, masters_degree, pop_5_years_over, speak_only_english_at_home, speak_spanish_at_home, pop_determined_poverty_status, poverty, median_income, gini_index, income_per_capita, housing_units, vacant_housing_units, vacant_housing_units_for_rent, vacant_housing_units_for_sale, median_rent, percent_income_spent_on_rent, owner_occupied_housing_units, million_dollar_housing_units, mortgaged_housing_units, families_with_young_children, two_parent_families_with_young_children, two_parents_in_labor_force_families_with_young_children, two_parents_father_in_labor_force_families_with_young_children, two_parents_mother_in_labor_force_families_with_young_children, two_parents_not_in_labor_force_families_with_young_children, one_parent_families_with_young_children, father_one_parent_families_with_young_children, men_45_to_64, men_45_to_49, men_50_to_54, men_55_to_59, men_60_61, men_62_64, black_men_45_54, black_men_55_64, hispanic_men_45_54, hispanic_men_55_64, white_men_45_54, white_men_55_64, asian_men_45_54, asian_men_55_64, men_45_64_less_than_9_grade, men_45_64_grade_9_12, men_45_64_high_school, men_45_64_some_college, men_45_64_associates_degree, men_45_64_bachelors_degree, men_45_64_graduate_degree, father_in_labor_force_one_parent_families_with_young_children, pop_15_and_over, pop_never_married, pop_now_married, pop_separated, pop_widowed, pop_divorced, commuters_16_over, commute_less_10_mins, commute_10_14_mins, commute_15_19_mins, commute_20_24_mins, commute_25_29_mins, commute_30_34_mins, commute_35_44_mins, commute_45_59_mins, commute_60_more_mins, aggregate_travel_time_to_work, income_less_10000, income_10000_14999, income_15000_19999, income_20000_24999, income_25000_29999, income_30000_34999, income_35000_39999, income_40000_44999, income_45000_49999, income_50000_59999, income_60000_74999, income_75000_99999, income_100000_124999, income_125000_149999, income_150000_199999, income_200000_or_more) VALUES (44715, NULL, NULL, '36047048500', 2794, 1793, 1001, 28, 1528, 80, 100, 1066, 0, 14, 6, 1728, 316, 1996, 117, 101, 16, 1453, 46, 1394, 145, 81, 174, 897, 2728, 554, 20, 13, 35, 182, 2064, 335, 19, 197, 109, 801, 299, 2715, 1696, 839, 2794, 564, 73170, 0.38919999999999999, 29516, 1009, 112, 21, 0, 1733, 29.3999999999999986, 106, 0, 74, 91, 61, 22, 25, 0, 14, 30, 17, 150, 31, 67, 6, 15, 31, 0, 0, 37, 52, 61, 0, 0, 0, 18, 6, 53, 6, 16, 23, 28, 17, 2627, 2035, 393, 65, 35, 19, 1915, 82, 24, 77, 172, 169, 461, 457, 297, 176, 67175, 10, 11, 37, 96, 29, 52, 19, 24, 11, 57, 123, 151, 68, 94, 45, 70);
CREATE SCHEMA IF NOT EXISTS observatory;
ALTER TABLE obs_ab038198aaab3f3cb055758638ee4de28ad70146 SET SCHEMA observatory;

View File

@ -1816,4 +1816,4 @@ INSERT INTO obs_column_table (cartodb_id, the_geom, the_geom_webmercator, column
INSERT INTO obs_column_table (cartodb_id, the_geom, the_geom_webmercator, column_id, table_id, colname, extra) VALUES (1812, NULL, NULL, '"us.census.acs".B19001017_quantile', '"us.census.acs".quantiles_puma_5yr_2013_e9f0d7bc6c', 'income_200000_or_more_quantile', NULL);
CREATE SCHEMA IF NOT EXISTS observatory;
ALTER TABLE OBS_column_table SET SCHEMA observatory;
ALTER TABLE OBS_column_table SET SCHEMA observatory;

File diff suppressed because one or more lines are too long

View File

@ -5,7 +5,7 @@
-- OBS_GeomTable
-- get table with known geometry_id
-- should give back a table like obs_{hex hash}
SELECT
SELECT
cdb_observatory.OBS_GeomTable(
CDB_LatLng(40.7128,-74.0059),
'"us.census.tiger".census_tract'
@ -13,19 +13,26 @@ SELECT
-- get null for unknown geometry_id
-- should give back null
SELECT
SELECT
cdb_observatory.OBS_GeomTable(
CDB_LatLng(40.7128,-74.0059),
'"us.census.tiger".nonexistant_id'
'"us.census.tiger".nonexistant_id' -- not in catalog
);
-- future test: give back nulls when geometry doesn't intersect
-- SELECT
-- cdb_observatory.OBS_GeomTable(
-- CDB_LatLng(0,0), -- should give back null since it's in the ocean?
-- '"us.census.tiger".census_tract'
-- );
-- OBS_GetColumnData
-- should give back:
-- colname | tablename | aggregate
-- -----------|-----------------|-----------
-- geoid | obs_{hex table} | null
-- total_pop | obs_{hex table} | sum
SELECT
SELECT
(unnest(cdb_observatory.OBS_GetColumnData(
'"us.census.tiger".census_tract',
Array['"us.census.tiger".census_tract_geoid', '"us.census.acs".B01001001'],
@ -33,18 +40,39 @@ SELECT
))).*
ORDER BY colname, tablename ASC;
-- should be null-valued
SELECT
(unnest(cdb_observatory.OBS_GetColumnData(
'"us.census.tiger".census_tract',
Array['"us.census.tiger".baloney'], -- entry not in catalog
'2009 - 2013'
))).*
ORDER BY 1 ASC;
-- OBS_LookupCensusHuman
-- should give back: {"\"us.census.acs\".B19083001"}
SELECT
SELECT
cdb_observatory.OBS_LookupCensusHuman(
Array['gini_index']
);
-- should be empty array
SELECT
cdb_observatory.OBS_LookupCensusHuman(
Array['cookies']
);
-- OBS_BuildSnapshotQuery
-- Should give back: SELECT vals[1] As total_pop, vals[2] As male_pop, vals[3] As female_pop, vals[4] As median_age
SELECT
SELECT
cdb_observatory.OBS_BuildSnapshotQuery(
Array['total_pop','male_pop','female_pop','median_age']
);
-- should give back: SELECT vals[1] As mandarin_orange
SELECT
cdb_observatory.OBS_BuildSnapshotQuery(
Array['mandarin_orange']
);
\i test/sql/drop_fixtures.sql

View File

@ -0,0 +1,135 @@
SELECT set_config(
'search_path',
current_setting('search_path') || ',cdb_observatory,observatory',
false
) WHERE current_setting('search_path') !~ '(^|,)(cdb_observatory|observatory)(,|$)';
\i test/sql/load_fixtures.sql
--
SELECT * FROM
cdb_observatory.OBS_GetDemographicSnapshot(
cdb_observatory._TestPoint(),
'2009 - 2013',
'"us.census.tiger".block_group'
) As snapshot;
--
-- dimension | dimension_value
-- ----------|----------------
-- total_pop | 9516.27915900609
-- male_pop | 6152.51885204623
SELECT *
FROM
cdb_observatory.OBS_GetCensus(
cdb_observatory._TestPoint(),
Array['total_pop','male_pop']::text[]
);
-- what happens on null island?
-- expect nulls back: {female_pop, male_pop} | {NULL, NULL}
SELECT *
FROM
cdb_observatory.OBS_GetCensus(
ST_Buffer(CDB_LatLng(0, 0)::geography, 5000)::geometry,
Array['female_pop','male_pop']::text[]
);
-- expect nulls back {female_pop, male_pop} | {NULL, NULL}
SELECT *
FROM
cdb_observatory.OBS_GetCensus(
CDB_LatLng(0, 0),
Array['female_pop', 'male_pop']::text[]
);
--
-- names | vals
-- -----------|-------
-- gini_index | 0.3494
SELECT * FROM
cdb_observatory.OBS_Get(
cdb_observatory._TestPoint(),
Array['"us.census.acs".B19083001']::text[],
'2009 - 2013',
'"us.census.tiger".block_group'
);
-- gini index at null island
SELECT * FROM
cdb_observatory.OBS_Get(
CDB_LatLng(0, 0),
Array['"us.census.acs".B19083001']::text[],
'2009 - 2013',
'"us.census.tiger".block_group'
);
-- OBS_GetPoints
-- obs_getpoints
-- --------------------
-- {4809.33511352425}
SELECT
cdb_observatory.OBS_GetPoints(
cdb_observatory._TestPoint(),
'obs_a92e1111ad3177676471d66bb8036e6d057f271b'::text, -- see example in obs_geomtable
Array[('total_pop','obs_ab038198aaab3f3cb055758638ee4de28ad70146','sum')::cdb_observatory.OBS_ColumnData]
);
-- what happens at null island
SELECT
cdb_observatory.OBS_GetPoints(
CDB_LatLng(0, 0),
'obs_a92e1111ad3177676471d66bb8036e6d057f271b'::text, -- see example in obs_geomtable
Array[('total_pop','obs_ab038198aaab3f3cb055758638ee4de28ad70146','sum')::cdb_observatory.OBS_ColumnData]
);
-- OBS_GetPolygons
-- obs_getpolygons
-- --------------------
-- {12996.8172420752}
SELECT
OBS_GetPolygons(
_TestArea(),
'obs_a92e1111ad3177676471d66bb8036e6d057f271b'::text, -- see example in obs_geomtable
Array[('total_pop','obs_ab038198aaab3f3cb055758638ee4de28ad70146','sum')::OBS_ColumnData]
);
-- see what happens around null island
SELECT
OBS_GetPolygons(
ST_Buffer(CDB_LatLng(0, 0)::geography, 500)::geometry,
'obs_a92e1111ad3177676471d66bb8036e6d057f271b'::text, -- see example in obs_geomtable
Array[('total_pop','obs_ab038198aaab3f3cb055758638ee4de28ad70146','sum')::OBS_ColumnData]
);
SELECT * FROM
cdb_observatory.OBS_GetSegmentSnapshot(
_TestPoint(),
'"us.census.tiger".census_tract'
);
-- segmentation around null island
SELECT * FROM
cdb_observatory.OBS_GetSegmentSnapshot(
CDB_LatLng(0, 0),
'"us.census.tiger".census_tract'
);
SELECT * FROM
cdb_observatory.OBS_GetCategories(
_TestPoint(),
Array['"us.census.spielman_singleton_segments".X10'],
'"us.census.tiger".census_tract'
);
SELECT * FROM
cdb_observatory.OBS_GetCategories(
CDB_LatLng(0, 0),
Array['"us.census.spielman_singleton_segments".X10'],
'"us.census.tiger".census_tract'
);
\i test/sql/drop_fixtures.sql

View File

@ -27,4 +27,20 @@ DROP TABLE observatory.obs_85328201013baa14e8e8a4a57a01e6f6fbc5f9b1;
DROP TABLE observatory.obs_3e7cc9cfd403b912c57b42d5f9195af9ce2f3cdb;
\echo Done.
\echo Dropping obs_ab038198aaab3f3cb055758638ee4de28ad70146 fixture table...
DROP TABLE observatory.obs_ab038198aaab3f3cb055758638ee4de28ad70146;
\echo Done.
\echo Dropping obs_a92e1111ad3177676471d66bb8036e6d057f271b fixture table...
DROP TABLE observatory.obs_a92e1111ad3177676471d66bb8036e6d057f271b;
\echo Done.
\echo Dropping obs_11ee8b82c877c073438bc935a91d3dfccef875d1 fixture table...
DROP TABLE observatory.obs_11ee8b82c877c073438bc935a91d3dfccef875d1;
\echo Done.
\echo Dropping obs_d34555209878e8c4b37cf0b2b3d072ff129ec470 fixture table...
DROP TABLE observatory.obs_d34555209878e8c4b37cf0b2b3d072ff129ec470;
\echo Done.
\unset ECHO

View File

@ -27,4 +27,20 @@ SET client_min_messages TO WARNING;
\i test/fixtures/obs_3e7cc9cfd403b912c57b42d5f9195af9ce2f3cdb.sql
\echo Done.
\echo Loading obs_ab038198aaab3f3cb055758638ee4de28ad70146.sql fixture file...
\i test/fixtures/obs_ab038198aaab3f3cb055758638ee4de28ad70146.sql
\echo Done.
\echo Loading obs_a92e1111ad3177676471d66bb8036e6d057f271b.sql fixture file...
\i test/fixtures/obs_a92e1111ad3177676471d66bb8036e6d057f271b.sql
\echo Done.
\echo Loading obs_11ee8b82c877c073438bc935a91d3dfccef875d1.sql fixture file...
\i test/fixtures/obs_11ee8b82c877c073438bc935a91d3dfccef875d1.sql
\echo Done.
\echo Loading obs_d34555209878e8c4b37cf0b2b3d072ff129ec470.sql fixture file...
\i test/fixtures/obs_d34555209878e8c4b37cf0b2b3d072ff129ec470.sql
\echo Done.
\unset ECHO