From 3beaf710a7d4c8000f13ce9246773dadf5b3f3a5 Mon Sep 17 00:00:00 2001 From: Andy Eschbacher Date: Thu, 14 Apr 2016 13:22:44 -0400 Subject: [PATCH 01/10] minor changes --- .../fixtures/obs_3e7cc9cfd403b912c57b42d5f9195af9ce2f3cdb.sql | 4 ++-- .../fixtures/obs_85328201013baa14e8e8a4a57a01e6f6fbc5f9b1.sql | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/pg/test/fixtures/obs_3e7cc9cfd403b912c57b42d5f9195af9ce2f3cdb.sql b/src/pg/test/fixtures/obs_3e7cc9cfd403b912c57b42d5f9195af9ce2f3cdb.sql index 8068636..10c22b6 100644 --- a/src/pg/test/fixtures/obs_3e7cc9cfd403b912c57b42d5f9195af9ce2f3cdb.sql +++ b/src/pg/test/fixtures/obs_3e7cc9cfd403b912c57b42d5f9195af9ce2f3cdb.sql @@ -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; \ No newline at end of file +ALTER TABLE obs_3e7cc9cfd403b912c57b42d5f9195af9ce2f3cdb SET SCHEMA observatory; diff --git a/src/pg/test/fixtures/obs_85328201013baa14e8e8a4a57a01e6f6fbc5f9b1.sql b/src/pg/test/fixtures/obs_85328201013baa14e8e8a4a57a01e6f6fbc5f9b1.sql index e156884..fdec876 100644 --- a/src/pg/test/fixtures/obs_85328201013baa14e8e8a4a57a01e6f6fbc5f9b1.sql +++ b/src/pg/test/fixtures/obs_85328201013baa14e8e8a4a57a01e6f6fbc5f9b1.sql @@ -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; - From 094b2da61d191977fd67238d1d2f4a1012cc23ea Mon Sep 17 00:00:00 2001 From: Andy Eschbacher Date: Thu, 14 Apr 2016 13:23:04 -0400 Subject: [PATCH 02/10] adding new data fixtures subset --- ...2e1111ad3177676471d66bb8036e6d057f271b.sql | 12 ++ ...038198aaab3f3cb055758638ee4de28ad70146.sql | 129 ++++++++++++++++++ 2 files changed, 141 insertions(+) create mode 100644 src/pg/test/fixtures/obs_a92e1111ad3177676471d66bb8036e6d057f271b.sql create mode 100644 src/pg/test/fixtures/obs_ab038198aaab3f3cb055758638ee4de28ad70146.sql diff --git a/src/pg/test/fixtures/obs_a92e1111ad3177676471d66bb8036e6d057f271b.sql b/src/pg/test/fixtures/obs_a92e1111ad3177676471d66bb8036e6d057f271b.sql new file mode 100644 index 0000000..b19ac2a --- /dev/null +++ b/src/pg/test/fixtures/obs_a92e1111ad3177676471d66bb8036e6d057f271b.sql @@ -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; diff --git a/src/pg/test/fixtures/obs_ab038198aaab3f3cb055758638ee4de28ad70146.sql b/src/pg/test/fixtures/obs_ab038198aaab3f3cb055758638ee4de28ad70146.sql new file mode 100644 index 0000000..705fc30 --- /dev/null +++ b/src/pg/test/fixtures/obs_ab038198aaab3f3cb055758638ee4de28ad70146.sql @@ -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; From 3468d6e5e9f974505a9baaa373a461080351c707 Mon Sep 17 00:00:00 2001 From: Andy Eschbacher Date: Thu, 14 Apr 2016 13:23:40 -0400 Subject: [PATCH 03/10] add new fixtures to process --- src/pg/test/sql/drop_fixtures.sql | 8 ++++++++ src/pg/test/sql/load_fixtures.sql | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/src/pg/test/sql/drop_fixtures.sql b/src/pg/test/sql/drop_fixtures.sql index 90f761d..9d49a14 100644 --- a/src/pg/test/sql/drop_fixtures.sql +++ b/src/pg/test/sql/drop_fixtures.sql @@ -27,4 +27,12 @@ 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. + \unset ECHO diff --git a/src/pg/test/sql/load_fixtures.sql b/src/pg/test/sql/load_fixtures.sql index 738c8b6..cd7306d 100644 --- a/src/pg/test/sql/load_fixtures.sql +++ b/src/pg/test/sql/load_fixtures.sql @@ -27,4 +27,12 @@ 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. + \unset ECHO From 874a397d3b43685f5bebad406c49c0d0c5e85428 Mon Sep 17 00:00:00 2001 From: Andy Eschbacher Date: Thu, 14 Apr 2016 14:26:19 -0400 Subject: [PATCH 04/10] adding percentile fixtures --- ...ee8b82c877c073438bc935a91d3dfccef875d1.sql | 17 +++ ...4555209878e8c4b37cf0b2b3d072ff129ec470.sql | 130 ++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 src/pg/test/fixtures/obs_11ee8b82c877c073438bc935a91d3dfccef875d1.sql create mode 100644 src/pg/test/fixtures/obs_d34555209878e8c4b37cf0b2b3d072ff129ec470.sql diff --git a/src/pg/test/fixtures/obs_11ee8b82c877c073438bc935a91d3dfccef875d1.sql b/src/pg/test/fixtures/obs_11ee8b82c877c073438bc935a91d3dfccef875d1.sql new file mode 100644 index 0000000..7ef56d8 --- /dev/null +++ b/src/pg/test/fixtures/obs_11ee8b82c877c073438bc935a91d3dfccef875d1.sql @@ -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; diff --git a/src/pg/test/fixtures/obs_d34555209878e8c4b37cf0b2b3d072ff129ec470.sql b/src/pg/test/fixtures/obs_d34555209878e8c4b37cf0b2b3d072ff129ec470.sql new file mode 100644 index 0000000..fd4062d --- /dev/null +++ b/src/pg/test/fixtures/obs_d34555209878e8c4b37cf0b2b3d072ff129ec470.sql @@ -0,0 +1,130 @@ + +CREATE TABLE IF NOT EXISTS obs_d34555209878e8c4b37cf0b2b3d072ff129ec470 ( + cartodb_id integer, + the_geom geometry(Geometry,4326), + the_geom_webmercator geometry(Geometry,3857), + geoid text, + total_pop_quantile double precision, + male_pop_quantile double precision, + female_pop_quantile double precision, + median_age_quantile double precision, + white_pop_quantile double precision, + black_pop_quantile double precision, + asian_pop_quantile double precision, + hispanic_pop_quantile double precision, + amerindian_pop_quantile double precision, + other_race_pop_quantile double precision, + two_or_more_races_pop_quantile double precision, + not_hispanic_pop_quantile double precision, + not_us_citizen_pop_quantile double precision, + workers_16_and_over_quantile double precision, + commuters_by_car_truck_van_quantile double precision, + commuters_drove_alone_quantile double precision, + commuters_by_carpool_quantile double precision, + commuters_by_public_transportation_quantile double precision, + commuters_by_bus_quantile double precision, + commuters_by_subway_or_elevated_quantile double precision, + walked_to_work_quantile double precision, + worked_at_home_quantile double precision, + children_quantile double precision, + households_quantile double precision, + population_3_years_over_quantile double precision, + in_school_quantile double precision, + in_grades_1_to_4_quantile double precision, + in_grades_5_to_8_quantile double precision, + in_grades_9_to_12_quantile double precision, + in_undergrad_college_quantile double precision, + pop_25_years_over_quantile double precision, + high_school_diploma_quantile double precision, + less_one_year_college_quantile double precision, + one_year_more_college_quantile double precision, + associates_degree_quantile double precision, + bachelors_degree_quantile double precision, + masters_degree_quantile double precision, + pop_5_years_over_quantile double precision, + speak_only_english_at_home_quantile double precision, + speak_spanish_at_home_quantile double precision, + pop_determined_poverty_status_quantile double precision, + poverty_quantile double precision, + median_income_quantile double precision, + gini_index_quantile double precision, + income_per_capita_quantile double precision, + housing_units_quantile double precision, + vacant_housing_units_quantile double precision, + vacant_housing_units_for_rent_quantile double precision, + vacant_housing_units_for_sale_quantile double precision, + median_rent_quantile double precision, + percent_income_spent_on_rent_quantile double precision, + owner_occupied_housing_units_quantile double precision, + million_dollar_housing_units_quantile double precision, + mortgaged_housing_units_quantile double precision, + families_with_young_children_quantile double precision, + two_parent_families_with_young_children_quantile double precision, + two_parents_in_labor_force_families_with_young_children_quantil 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_qua double precision, + one_parent_families_with_young_children_quantile double precision, + father_one_parent_families_with_young_children_quantile double precision, + men_45_to_64_quantile double precision, + men_45_to_49_quantile double precision, + men_50_to_54_quantile double precision, + men_55_to_59_quantile double precision, + men_60_61_quantile double precision, + men_62_64_quantile double precision, + black_men_45_54_quantile double precision, + black_men_55_64_quantile double precision, + hispanic_men_45_54_quantile double precision, + hispanic_men_55_64_quantile double precision, + white_men_45_54_quantile double precision, + white_men_55_64_quantile double precision, + asian_men_45_54_quantile double precision, + asian_men_55_64_quantile double precision, + men_45_64_less_than_9_grade_quantile double precision, + men_45_64_grade_9_12_quantile double precision, + men_45_64_high_school_quantile double precision, + men_45_64_some_college_quantile double precision, + men_45_64_associates_degree_quantile double precision, + men_45_64_bachelors_degree_quantile double precision, + men_45_64_graduate_degree_quantile double precision, + father_in_labor_force_one_parent_families_with_young_children_q double precision, + pop_15_and_over_quantile double precision, + pop_never_married_quantile double precision, + pop_now_married_quantile double precision, + pop_separated_quantile double precision, + pop_widowed_quantile double precision, + pop_divorced_quantile double precision, + commuters_16_over_quantile double precision, + commute_less_10_mins_quantile double precision, + commute_10_14_mins_quantile double precision, + commute_15_19_mins_quantile double precision, + commute_20_24_mins_quantile double precision, + commute_25_29_mins_quantile double precision, + commute_30_34_mins_quantile double precision, + commute_35_44_mins_quantile double precision, + commute_45_59_mins_quantile double precision, + commute_60_more_mins_quantile double precision, + aggregate_travel_time_to_work_quantile double precision, + income_less_10000_quantile double precision, + income_10000_14999_quantile double precision, + income_15000_19999_quantile double precision, + income_20000_24999_quantile double precision, + income_25000_29999_quantile double precision, + income_30000_34999_quantile double precision, + income_35000_39999_quantile double precision, + income_40000_44999_quantile double precision, + income_45000_49999_quantile double precision, + income_50000_59999_quantile double precision, + income_60000_74999_quantile double precision, + income_75000_99999_quantile double precision, + income_100000_124999_quantile double precision, + income_125000_149999_quantile double precision, + income_150000_199999_quantile double precision, + income_200000_or_more_quantile double precision +); + +INSERT INTO obs_d34555209878e8c4b37cf0b2b3d072ff129ec470 (cartodb_id, the_geom, the_geom_webmercator, geoid, total_pop_quantile, male_pop_quantile, female_pop_quantile, median_age_quantile, white_pop_quantile, black_pop_quantile, asian_pop_quantile, hispanic_pop_quantile, amerindian_pop_quantile, other_race_pop_quantile, two_or_more_races_pop_quantile, not_hispanic_pop_quantile, not_us_citizen_pop_quantile, workers_16_and_over_quantile, commuters_by_car_truck_van_quantile, commuters_drove_alone_quantile, commuters_by_carpool_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, less_one_year_college_quantile, one_year_more_college_quantile, associates_degree_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, mortgaged_housing_units_quantile, families_with_young_children_quantile, two_parent_families_with_young_children_quantile, two_parents_in_labor_force_families_with_young_children_quantil, 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_qua, one_parent_families_with_young_children_quantile, father_one_parent_families_with_young_children_quantile, men_45_to_64_quantile, men_45_to_49_quantile, men_50_to_54_quantile, men_55_to_59_quantile, men_60_61_quantile, men_62_64_quantile, black_men_45_54_quantile, black_men_55_64_quantile, hispanic_men_45_54_quantile, hispanic_men_55_64_quantile, white_men_45_54_quantile, white_men_55_64_quantile, asian_men_45_54_quantile, asian_men_55_64_quantile, men_45_64_less_than_9_grade_quantile, men_45_64_grade_9_12_quantile, men_45_64_high_school_quantile, men_45_64_some_college_quantile, men_45_64_associates_degree_quantile, men_45_64_bachelors_degree_quantile, men_45_64_graduate_degree_quantile, father_in_labor_force_one_parent_families_with_young_children_q, pop_15_and_over_quantile, pop_never_married_quantile, pop_now_married_quantile, pop_separated_quantile, pop_widowed_quantile, pop_divorced_quantile, commuters_16_over_quantile, commute_less_10_mins_quantile, commute_10_14_mins_quantile, commute_15_19_mins_quantile, commute_20_24_mins_quantile, commute_25_29_mins_quantile, commute_30_34_mins_quantile, commute_35_44_mins_quantile, commute_45_59_mins_quantile, commute_60_more_mins_quantile, aggregate_travel_time_to_work_quantile, income_less_10000_quantile, income_10000_14999_quantile, income_15000_19999_quantile, income_20000_24999_quantile, income_25000_29999_quantile, income_30000_34999_quantile, income_35000_39999_quantile, income_40000_44999_quantile, income_45000_49999_quantile, income_50000_59999_quantile, income_60000_74999_quantile, income_75000_99999_quantile, income_100000_124999_quantile, income_125000_149999_quantile, income_150000_199999_quantile, income_200000_or_more_quantile) VALUES (52953, NULL, NULL, '36047048500', 0.234783783783784006, 0.422405405405404999, 0.0987567567567567972, 0.0714999999999999941, 0.295310810810811009, 0.407189189189189005, 0.625608108108107963, 0.79520270270270299, 0, 0.858121621621621977, 0.155202702702703005, 0.160445945945945995, 0.703797297297297009, 0.592270270270270016, 0.0180540540540541014, 0.0188243243243243, 0.0334054054054054028, 0.993756756756757009, 0.728162162162162008, 0.995972972972973047, 0.929135135135135015, 0.625432432432431962, 0.038608108108108101, 0.157121621621621993, 0.241878378378378001, 0.173783783783784007, 0.0380675675675676006, 0.0308108108108108014, 0.0486216216216215982, 0.479743243243243023, 0.297675675675675988, 0.190351351351351006, 0.0339324324324324009, 0.158513513513514004, 0.232527027027026989, 0.802513513513513965, 0.757148648648648948, 0.255405405405405017, 0.196094594594594995, 0.816851351351351007, 0.252513513513513976, 0.560054054054053951, 0.77747297297297302, 0.336932432432431983, 0.655378378378377979, 0.141810810810811011, 0.362824324324323988, 0.463837837837837996, 0, 0.93904054054054098, 0.419445945945945975, 0.0387972972972972993, 0, 0.0475675675675676021, 0.0944459459459458944, 0.160324324324324002, 0.132824324324324006, 0.303256756756757007, 0, 0.924499999999999988, 0.232770270270270002, 0.579662162162162042, 0.0422432432432432031, 0.0560675675675676027, 0.165040540540540986, 0.0195810810810811003, 0.168486486486486009, 0.242094594594595008, 0, 0, 0.707283783783783981, 0.850162162162162005, 0.201621621621622005, 0, 0, 0, 0.578743243243243, 0.18727027027026999, 0.154256756756757013, 0.0275270270270270012, 0.292027027027026986, 0.193445945945945996, 0.435770270270269988, 0.614432432432431952, 0.327310810810810981, 0.923756756756756947, 0.0570540540540541014, 0.548918918918918974, 0.0795135135135135035, 0.0187162162162161985, 0.594202702702703034, 0.187472972972972995, 0.0326216216216215979, 0.100270270270269996, 0.361067567567568026, 0.786391891891891959, 0.876067567567567984, 0.983445945945946032, 0.889270270270269947, 0.719621621621622021, 0.452013513513512988, 0.059310810810810799, 0.0956216216216216053, 0.246567567567568008, 0.638864864864865045, 0.179837837837837994, 0.350094594594595021, 0.121972972972973007, 0.15340540540540501, 0.0852972972972973059, 0.194959459459459, 0.423648648648648984, 0.438256756756757015, 0.34521621621621601, 0.700472972972972951, 0.507418918918918993, 0.714310810810811048); + + +CREATE SCHEMA IF NOT EXISTS observatory; +ALTER TABLE obs_d34555209878e8c4b37cf0b2b3d072ff129ec470 SET SCHEMA observatory; From 3ee448016aa35071931784f5d8227cb2e79a4276 Mon Sep 17 00:00:00 2001 From: Andy Eschbacher Date: Thu, 14 Apr 2016 14:27:34 -0400 Subject: [PATCH 05/10] whitespace --- src/pg/test/fixtures/obs_column_table.sql | 2 +- src/pg/test/sql/40_observatory_utility_test.sql | 12 ++++++------ src/pg/test/sql/drop_fixtures.sql | 8 ++++++++ src/pg/test/sql/load_fixtures.sql | 8 ++++++++ 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/pg/test/fixtures/obs_column_table.sql b/src/pg/test/fixtures/obs_column_table.sql index 17352fa..9c3216c 100644 --- a/src/pg/test/fixtures/obs_column_table.sql +++ b/src/pg/test/fixtures/obs_column_table.sql @@ -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; \ No newline at end of file +ALTER TABLE OBS_column_table SET SCHEMA observatory; diff --git a/src/pg/test/sql/40_observatory_utility_test.sql b/src/pg/test/sql/40_observatory_utility_test.sql index 9e7c644..e0d49ce 100644 --- a/src/pg/test/sql/40_observatory_utility_test.sql +++ b/src/pg/test/sql/40_observatory_utility_test.sql @@ -10,7 +10,7 @@ SELECT set_config( -- 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' @@ -18,7 +18,7 @@ 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' @@ -30,7 +30,7 @@ SELECT -- -----------|-----------------|----------- -- 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'], @@ -40,16 +40,16 @@ ORDER BY 1 ASC; -- OBS_LookupCensusHuman -- should give back: {"\"us.census.acs\".B19083001"} -SELECT +SELECT cdb_observatory.OBS_LookupCensusHuman( Array['gini_index'] ); -- 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'] ); -\i test/sql/drop_fixtures.sql \ No newline at end of file +\i test/sql/drop_fixtures.sql diff --git a/src/pg/test/sql/drop_fixtures.sql b/src/pg/test/sql/drop_fixtures.sql index 9d49a14..5201029 100644 --- a/src/pg/test/sql/drop_fixtures.sql +++ b/src/pg/test/sql/drop_fixtures.sql @@ -35,4 +35,12 @@ DROP TABLE observatory.obs_ab038198aaab3f3cb055758638ee4de28ad70146; 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 diff --git a/src/pg/test/sql/load_fixtures.sql b/src/pg/test/sql/load_fixtures.sql index cd7306d..721558a 100644 --- a/src/pg/test/sql/load_fixtures.sql +++ b/src/pg/test/sql/load_fixtures.sql @@ -35,4 +35,12 @@ SET client_min_messages TO WARNING; \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 From 4b6b3118236c187910012c3aabcac840ea01665e Mon Sep 17 00:00:00 2001 From: Andy Eschbacher Date: Thu, 14 Apr 2016 14:27:56 -0400 Subject: [PATCH 06/10] augmentation tests --- .../41_observatory_augmentation_test.out | 88 +++++++++++++++++++ .../sql/41_observatory_augmentation_test.sql | 80 +++++++++++++++++ 2 files changed, 168 insertions(+) create mode 100644 src/pg/test/expected/41_observatory_augmentation_test.out create mode 100644 src/pg/test/sql/41_observatory_augmentation_test.sql diff --git a/src/pg/test/expected/41_observatory_augmentation_test.out b/src/pg/test/expected/41_observatory_augmentation_test.out new file mode 100644 index 0000000..8ac2b1f --- /dev/null +++ b/src/pg/test/expected/41_observatory_augmentation_test.out @@ -0,0 +1,88 @@ +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. + obs_getdemographicsnapshot +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + (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) + + names | vals +--------------+---------- + {gini_index} | {0.3494} +(1 row) + + obs_getpoints +-------------------- + {4809.33380072727} +(1 row) + + obs_getpolygons +-------------------- + {1570.72353789469} +(1 row) + + obs_getsegmentsnapshot +-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + ("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) + + obs_getcategories +----------------------------------------------------------------------------------- + ("{X10,x10}","{""Wealthy, urban without Kids"",""Wealthy, urban without Kids""}") +(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. diff --git a/src/pg/test/sql/41_observatory_augmentation_test.sql b/src/pg/test/sql/41_observatory_augmentation_test.sql new file mode 100644 index 0000000..8824224 --- /dev/null +++ b/src/pg/test/sql/41_observatory_augmentation_test.sql @@ -0,0 +1,80 @@ +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 + cdb_observatory.OBS_GetDemographicSnapshot( + cdb_observatory._TestPoint(), + '2009 - 2013', + '"us.census.tiger".block_group' + ); + +-- +-- 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[] + ); + +-- +-- 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' + ); + +-- 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] + ); + +-- 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] +); + +SELECT + cdb_observatory.OBS_GetSegmentSnapshot( + _TestPoint(), + '"us.census.tiger".census_tract' +); + +SELECT + cdb_observatory.OBS_GetCategories( + _TestPoint(), + Array['"us.census.spielman_singleton_segments".X10'], + '"us.census.tiger".census_tract' +); + +\i test/sql/drop_fixtures.sql From c434cacd109e52d0d274192c7011b4865de46607 Mon Sep 17 00:00:00 2001 From: Andy Eschbacher Date: Thu, 14 Apr 2016 14:52:23 -0400 Subject: [PATCH 07/10] adding null cases --- .../expected/40_observatory_utility_test.out | 107 ++++++++++-------- .../test/sql/40_observatory_utility_test.sql | 30 ++++- 2 files changed, 91 insertions(+), 46 deletions(-) diff --git a/src/pg/test/expected/40_observatory_utility_test.out b/src/pg/test/expected/40_observatory_utility_test.out index 9799c7f..9ee815d 100644 --- a/src/pg/test/expected/40_observatory_utility_test.out +++ b/src/pg/test/expected/40_observatory_utility_test.out @@ -1,51 +1,46 @@ SELECT set_config( 'search_path', - current_setting('search_path') || ',cdb_observatory', + current_setting('search_path') || ',cdb_observatory,observatory', false -) WHERE current_setting('search_path') !~ '(^|,)cdb_observatory(,|$)'; - set_config ------------------------------------------- - "$user", public, cartodb,cdb_observatory +) WHERE current_setting('search_path') !~ '(^|,)(cdb_observatory|observatory)(,|$)'; + set_config +------------------------------------------------------ + "$user", public, cartodb,cdb_observatory,observatory (1 row) --- 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' - ); +\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. obs_geomtable ---------------------------------------------- obs_a92e1111ad3177676471d66bb8036e6d057f271b (1 row) --- get null for unknown geometry_id --- should give back null -SELECT - cdb_observatory.OBS_GeomTable( - CDB_LatLng(40.7128,-74.0059), - '"us.census.tiger".nonexistant_id' - ); obs_geomtable --------------- (1 row) --- OBS_GetColumnData --- should give back: --- colname | tablename | aggregate --- -----------|-----------------|----------- --- geoid | obs_{hex table} | null --- total_pop | obs_{hex table} | sum -SELECT - (unnest(cdb_observatory.OBS_GetColumnData( - '"us.census.tiger".census_tract', - Array['"us.census.tiger".census_tract_geoid', '"us.census.acs".B01001001'], - '2009 - 2013' - ))).* -ORDER BY 1 ASC; colname | tablename | aggregate -----------+----------------------------------------------+----------- geoid | obs_11ee8b82c877c073438bc935a91d3dfccef875d1 | @@ -55,25 +50,47 @@ ORDER BY 1 ASC; total_pop | obs_ab038198aaab3f3cb055758638ee4de28ad70146 | sum (5 rows) --- OBS_LookupCensusHuman --- should give back: {"\"us.census.acs\".B19083001"} -SELECT - cdb_observatory.OBS_LookupCensusHuman( - Array['gini_index'] - ); + colname | tablename | aggregate +---------+-----------+----------- +(0 rows) + obs_lookupcensushuman --------------------------------- {"\"us.census.acs\".B19083001"} (1 row) --- 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 - cdb_observatory.OBS_BuildSnapshotQuery( - Array['total_pop','male_pop','female_pop','median_age'] - ); + obs_lookupcensushuman +----------------------- + +(1 row) + obs_buildsnapshotquery ------------------------------------------------------------------------------------------------- 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... +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. diff --git a/src/pg/test/sql/40_observatory_utility_test.sql b/src/pg/test/sql/40_observatory_utility_test.sql index e0d49ce..88ad8ba 100644 --- a/src/pg/test/sql/40_observatory_utility_test.sql +++ b/src/pg/test/sql/40_observatory_utility_test.sql @@ -21,9 +21,16 @@ 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 @@ -38,6 +45,15 @@ SELECT ))).* ORDER BY 1 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 @@ -45,6 +61,12 @@ SELECT 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 @@ -52,4 +74,10 @@ SELECT 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 From f72754e1d5d02d751f5b71310d9cb361162c0b9c Mon Sep 17 00:00:00 2001 From: Andy Eschbacher Date: Thu, 14 Apr 2016 16:22:32 -0400 Subject: [PATCH 08/10] fixing case where point doesn't intersect so area is null --- src/pg/sql/41_observatory_augmentation.sql | 49 +++++++++++++--------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/src/pg/sql/41_observatory_augmentation.sql b/src/pg/sql/41_observatory_augmentation.sql index 8eebead..38008b5 100644 --- a/src/pg/sql/41_observatory_augmentation.sql +++ b/src/pg/sql/41_observatory_augmentation.sql @@ -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 ', From c1fb6c36948b481b79d397d5b5c25f1d55c63ee0 Mon Sep 17 00:00:00 2001 From: Andy Eschbacher Date: Thu, 14 Apr 2016 16:25:09 -0400 Subject: [PATCH 09/10] adding null cases to augmentation --- .../41_observatory_augmentation_test.out | 28 +++++++++++++------ .../sql/41_observatory_augmentation_test.sql | 24 +++++++++++++--- 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/src/pg/test/expected/41_observatory_augmentation_test.out b/src/pg/test/expected/41_observatory_augmentation_test.out index 8ac2b1f..e561c75 100644 --- a/src/pg/test/expected/41_observatory_augmentation_test.out +++ b/src/pg/test/expected/41_observatory_augmentation_test.out @@ -31,9 +31,9 @@ Loading obs_11ee8b82c877c073438bc935a91d3dfccef875d1.sql fixture file... Done. Loading obs_d34555209878e8c4b37cf0b2b3d072ff129ec470.sql fixture file... Done. - obs_getdemographicsnapshot ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ - (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,,) + 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 @@ -41,6 +41,16 @@ Done. {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} @@ -56,14 +66,14 @@ Done. {1570.72353789469} (1 row) - obs_getsegmentsnapshot --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - ("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) + 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) - obs_getcategories ------------------------------------------------------------------------------------ - ("{X10,x10}","{""Wealthy, urban without Kids"",""Wealthy, urban without Kids""}") + names | categories +-----------+--------------------------------------------------------------- + {X10,x10} | {"Wealthy, urban without Kids","Wealthy, urban without Kids"} (1 row) Dropping obs_table.sql fixture table... diff --git a/src/pg/test/sql/41_observatory_augmentation_test.sql b/src/pg/test/sql/41_observatory_augmentation_test.sql index 8824224..77ad9fb 100644 --- a/src/pg/test/sql/41_observatory_augmentation_test.sql +++ b/src/pg/test/sql/41_observatory_augmentation_test.sql @@ -7,12 +7,12 @@ SELECT set_config( \i test/sql/load_fixtures.sql -- -SELECT +SELECT * FROM cdb_observatory.OBS_GetDemographicSnapshot( cdb_observatory._TestPoint(), '2009 - 2013', '"us.census.tiger".block_group' - ); + ) As snapshot; -- -- dimension | dimension_value @@ -27,6 +27,22 @@ FROM 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 -- -----------|------- @@ -64,13 +80,13 @@ SELECT Array[('total_pop','obs_ab038198aaab3f3cb055758638ee4de28ad70146','sum')::OBS_ColumnData] ); -SELECT +SELECT * FROM cdb_observatory.OBS_GetSegmentSnapshot( _TestPoint(), '"us.census.tiger".census_tract' ); -SELECT +SELECT * FROM cdb_observatory.OBS_GetCategories( _TestPoint(), Array['"us.census.spielman_singleton_segments".X10'], From 4977b942810a8e915b55b0fcd7acef11e7b14dd6 Mon Sep 17 00:00:00 2001 From: Andy Eschbacher Date: Thu, 14 Apr 2016 16:35:30 -0400 Subject: [PATCH 10/10] more robust tests around null island --- .../41_observatory_augmentation_test.out | 25 ++++++++++++ .../sql/41_observatory_augmentation_test.sql | 39 +++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/src/pg/test/expected/41_observatory_augmentation_test.out b/src/pg/test/expected/41_observatory_augmentation_test.out index e561c75..7d759df 100644 --- a/src/pg/test/expected/41_observatory_augmentation_test.out +++ b/src/pg/test/expected/41_observatory_augmentation_test.out @@ -56,9 +56,19 @@ Done. {gini_index} | {0.3494} (1 row) + names | vals +--------------+------ + {gini_index} | {} +(1 row) + obs_getpoints -------------------- {4809.33380072727} +(1 row) + + obs_getpoints +--------------- + (1 row) obs_getpolygons @@ -66,16 +76,31 @@ Done. {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... diff --git a/src/pg/test/sql/41_observatory_augmentation_test.sql b/src/pg/test/sql/41_observatory_augmentation_test.sql index 77ad9fb..bf8f0cb 100644 --- a/src/pg/test/sql/41_observatory_augmentation_test.sql +++ b/src/pg/test/sql/41_observatory_augmentation_test.sql @@ -56,6 +56,15 @@ SELECT * FROM '"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 -- -------------------- @@ -68,6 +77,14 @@ SELECT 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 -- -------------------- @@ -80,12 +97,27 @@ SELECT 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(), @@ -93,4 +125,11 @@ SELECT * FROM '"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