updated fixtures generation from local postgres, fixed a few tests that broke
This commit is contained in:
parent
2a1598d491
commit
b473ffe307
@ -38,7 +38,7 @@ def get_tablename_query(column_id, boundary_id, timespan):
|
|||||||
timespan, give back the current table hash from the data observatory
|
timespan, give back the current table hash from the data observatory
|
||||||
"""
|
"""
|
||||||
return """
|
return """
|
||||||
SELECT t.tablename, geoid_ct.colname colname
|
SELECT t.tablename, geoid_ct.colname colname, t.id table_id
|
||||||
FROM observatory.obs_table t,
|
FROM observatory.obs_table t,
|
||||||
observatory.obs_column_table geoid_ct,
|
observatory.obs_column_table geoid_ct,
|
||||||
observatory.obs_column_table data_ct
|
observatory.obs_column_table data_ct
|
||||||
@ -63,24 +63,134 @@ METADATA_TABLES = ['obs_table', 'obs_column_table', 'obs_column', 'obs_column_ta
|
|||||||
'obs_meta_numer', 'obs_meta_denom', 'obs_meta_geom',
|
'obs_meta_numer', 'obs_meta_denom', 'obs_meta_geom',
|
||||||
'obs_meta_timespan', ]
|
'obs_meta_timespan', ]
|
||||||
|
|
||||||
fixtures = [
|
FIXTURES = [
|
||||||
|
('us.census.acs.B01003001_quantile', 'us.census.tiger.census_tract', '2010 - 2014'),
|
||||||
|
('us.census.acs.B01001002_quantile', 'us.census.tiger.census_tract', '2010 - 2014'),
|
||||||
|
('us.census.acs.B01001026_quantile', 'us.census.tiger.census_tract', '2010 - 2014'),
|
||||||
|
('us.census.acs.B01002001_quantile', 'us.census.tiger.census_tract', '2010 - 2014'),
|
||||||
|
('us.census.acs.B03002003_quantile', 'us.census.tiger.census_tract', '2010 - 2014'),
|
||||||
|
('us.census.acs.B03002004_quantile', 'us.census.tiger.census_tract', '2010 - 2014'),
|
||||||
|
('us.census.acs.B03002006_quantile', 'us.census.tiger.census_tract', '2010 - 2014'),
|
||||||
|
('us.census.acs.B03002012_quantile', 'us.census.tiger.census_tract', '2010 - 2014'),
|
||||||
|
('us.census.acs.B05001006_quantile', 'us.census.tiger.census_tract', '2010 - 2014'),
|
||||||
|
('us.census.acs.B08006001_quantile', 'us.census.tiger.census_tract', '2010 - 2014'),
|
||||||
|
('us.census.acs.B08006002_quantile', 'us.census.tiger.census_tract', '2010 - 2014'),
|
||||||
|
('us.census.acs.B08006008_quantile', 'us.census.tiger.census_tract', '2010 - 2014'),
|
||||||
|
('us.census.acs.B08006009_quantile', 'us.census.tiger.census_tract', '2010 - 2014'),
|
||||||
|
('us.census.acs.B08006011_quantile', 'us.census.tiger.census_tract', '2010 - 2014'),
|
||||||
|
('us.census.acs.B08006015_quantile', 'us.census.tiger.census_tract', '2010 - 2014'),
|
||||||
|
('us.census.acs.B08006017_quantile', 'us.census.tiger.census_tract', '2010 - 2014'),
|
||||||
|
('us.census.acs.B09001001_quantile', 'us.census.tiger.census_tract', '2010 - 2014'),
|
||||||
|
('us.census.acs.B11001001_quantile', 'us.census.tiger.census_tract', '2010 - 2014'),
|
||||||
|
('us.census.acs.B14001001_quantile', 'us.census.tiger.census_tract', '2010 - 2014'),
|
||||||
|
('us.census.acs.B14001002_quantile', 'us.census.tiger.census_tract', '2010 - 2014'),
|
||||||
|
('us.census.acs.B14001005_quantile', 'us.census.tiger.census_tract', '2010 - 2014'),
|
||||||
|
('us.census.acs.B14001006_quantile', 'us.census.tiger.census_tract', '2010 - 2014'),
|
||||||
|
('us.census.acs.B14001007_quantile', 'us.census.tiger.census_tract', '2010 - 2014'),
|
||||||
|
('us.census.acs.B14001008_quantile', 'us.census.tiger.census_tract', '2010 - 2014'),
|
||||||
|
('us.census.acs.B15003001_quantile', 'us.census.tiger.census_tract', '2010 - 2014'),
|
||||||
|
('us.census.acs.B15003017_quantile', 'us.census.tiger.census_tract', '2010 - 2014'),
|
||||||
|
('us.census.acs.B15003022_quantile', 'us.census.tiger.census_tract', '2010 - 2014'),
|
||||||
|
('us.census.acs.B15003023_quantile', 'us.census.tiger.census_tract', '2010 - 2014'),
|
||||||
|
('us.census.acs.B16001001_quantile', 'us.census.tiger.census_tract', '2010 - 2014'),
|
||||||
|
('us.census.acs.B16001002_quantile', 'us.census.tiger.census_tract', '2010 - 2014'),
|
||||||
|
('us.census.acs.B16001003_quantile', 'us.census.tiger.census_tract', '2010 - 2014'),
|
||||||
|
('us.census.acs.B17001001_quantile', 'us.census.tiger.census_tract', '2010 - 2014'),
|
||||||
|
('us.census.acs.B17001002_quantile', 'us.census.tiger.census_tract', '2010 - 2014'),
|
||||||
|
('us.census.acs.B19013001_quantile', 'us.census.tiger.census_tract', '2010 - 2014'),
|
||||||
|
('us.census.acs.B19083001_quantile', 'us.census.tiger.census_tract', '2010 - 2014'),
|
||||||
|
('us.census.acs.B19301001_quantile', 'us.census.tiger.census_tract', '2010 - 2014'),
|
||||||
|
('us.census.acs.B25001001_quantile', 'us.census.tiger.census_tract', '2010 - 2014'),
|
||||||
|
('us.census.acs.B25002003_quantile', 'us.census.tiger.census_tract', '2010 - 2014'),
|
||||||
|
('us.census.acs.B25004002_quantile', 'us.census.tiger.census_tract', '2010 - 2014'),
|
||||||
|
('us.census.acs.B25004004_quantile', 'us.census.tiger.census_tract', '2010 - 2014'),
|
||||||
|
('us.census.acs.B25058001_quantile', 'us.census.tiger.census_tract', '2010 - 2014'),
|
||||||
|
('us.census.acs.B25071001_quantile', 'us.census.tiger.census_tract', '2010 - 2014'),
|
||||||
|
('us.census.acs.B25075001_quantile', 'us.census.tiger.census_tract', '2010 - 2014'),
|
||||||
|
('us.census.acs.B25075025_quantile', 'us.census.tiger.census_tract', '2010 - 2014'),
|
||||||
|
('us.census.acs.B01003001', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B01001002', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B01001026', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B01002001', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B03002003', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B03002004', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B03002006', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B03002012', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B03002005', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B03002008', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B03002009', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B03002002', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B11001001', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B15003001', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B15003017', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B15003019', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B15003020', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B15003021', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B15003022', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B15003023', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B19013001', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B19083001', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B19301001', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B25001001', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B25002003', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B25004002', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B25004004', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B25058001', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B25071001', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B25075001', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B25075025', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B25081002', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B08134001', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B08134002', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B08134003', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B08134004', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B08134005', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B08134006', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B08134007', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B08134008', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B08134009', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B08134010', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B08135001', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B19001002', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B19001003', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B19001004', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B19001005', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B19001006', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B19001007', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B19001008', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B19001009', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B19001010', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B19001011', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B19001012', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B19001013', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B19001014', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B19001015', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B19001016', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.acs.B19001017', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
('us.census.tiger.census_tract', 'us.census.tiger.census_tract', '2014'),
|
('us.census.tiger.census_tract', 'us.census.tiger.census_tract', '2014'),
|
||||||
('us.census.tiger.block_group', 'us.census.tiger.block_group', '2014'),
|
('us.census.tiger.block_group', 'us.census.tiger.block_group', '2014'),
|
||||||
('us.census.tiger.zcta5', 'us.census.tiger.zcta5', '2014'),
|
('us.census.tiger.zcta5', 'us.census.tiger.zcta5', '2014'),
|
||||||
('us.census.tiger.county', 'us.census.tiger.county', '2014'),
|
('us.census.tiger.county', 'us.census.tiger.county', '2014'),
|
||||||
|
('us.census.acs.B01001002', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
('us.census.acs.B01003001', 'us.census.tiger.census_tract', '2010 - 2014'),
|
('us.census.acs.B01003001', 'us.census.tiger.census_tract', '2010 - 2014'),
|
||||||
('us.census.acs.B01003001_quantile', 'us.census.tiger.census_tract', '2010 - 2014'),
|
('us.census.acs.B01003001_quantile', 'us.census.tiger.census_tract', '2010 - 2014'),
|
||||||
('us.census.acs.B01003001', 'us.census.tiger.block_group', '2010 - 2014'),
|
('us.census.acs.B01003001', 'us.census.tiger.block_group', '2010 - 2014'),
|
||||||
|
('us.census.spielman_singleton_segments.X2', 'us.census.tiger.census_tract', '2010 - 2014'),
|
||||||
('us.census.spielman_singleton_segments.X10', 'us.census.tiger.census_tract', '2010 - 2014'),
|
('us.census.spielman_singleton_segments.X10', 'us.census.tiger.census_tract', '2010 - 2014'),
|
||||||
|
('us.census.spielman_singleton_segments.X31', 'us.census.tiger.census_tract', '2010 - 2014'),
|
||||||
|
('us.census.spielman_singleton_segments.X55', 'us.census.tiger.census_tract', '2010 - 2014'),
|
||||||
('us.zillow.AllHomes_Zhvi', 'us.census.tiger.zcta5', '2014-01'),
|
('us.zillow.AllHomes_Zhvi', 'us.census.tiger.zcta5', '2014-01'),
|
||||||
('us.zillow.AllHomes_Zhvi', 'us.census.tiger.zcta5', '2016-03'),
|
('us.zillow.AllHomes_Zhvi', 'us.census.tiger.zcta5', '2016-06'),
|
||||||
('whosonfirst.wof_country_geom', 'whosonfirst.wof_country_geom', '2016'),
|
('whosonfirst.wof_country_geom', 'whosonfirst.wof_country_geom', '2016'),
|
||||||
('us.census.tiger.zcta5_clipped', 'us.census.tiger.zcta5_clipped', '2014'),
|
('us.census.tiger.zcta5_clipped', 'us.census.tiger.zcta5_clipped', '2014'),
|
||||||
('us.census.tiger.block_group_clipped', 'us.census.tiger.block_group_clipped', '2014'),
|
('us.census.tiger.block_group_clipped', 'us.census.tiger.block_group_clipped', '2014'),
|
||||||
|
('us.census.tiger.census_tract_clipped', 'us.census.tiger.census_tract_clipped', '2014'),
|
||||||
]
|
]
|
||||||
|
|
||||||
OUTFILE_PATH = 'src/pg/test/fixtures/load_fixtures.sql'
|
OUTFILE_PATH = os.path.join(os.path.dirname(__file__), '..',
|
||||||
DROPFILE_PATH = 'src/pg/test/fixtures/drop_fixtures.sql'
|
'src/pg/test/fixtures/load_fixtures.sql')
|
||||||
|
DROPFILE_PATH = os.path.join(os.path.dirname(__file__), '..',
|
||||||
|
'src/pg/test/fixtures/drop_fixtures.sql')
|
||||||
|
|
||||||
def dump(cols, tablename, where=''):
|
def dump(cols, tablename, where=''):
|
||||||
|
|
||||||
@ -90,7 +200,7 @@ def dump(cols, tablename, where=''):
|
|||||||
))
|
))
|
||||||
|
|
||||||
subprocess.check_call('pg_dump -x --section=pre-data -t observatory.{tablename} '
|
subprocess.check_call('pg_dump -x --section=pre-data -t observatory.{tablename} '
|
||||||
' | sed "s:, pg_catalog::" '
|
' | sed "s:SET search_path.*::" '
|
||||||
' | sed "s:CREATE TABLE :CREATE TABLE observatory.:" '
|
' | sed "s:CREATE TABLE :CREATE TABLE observatory.:" '
|
||||||
' | sed "s:ALTER TABLE.*OWNER.*::" '
|
' | sed "s:ALTER TABLE.*OWNER.*::" '
|
||||||
' >> {outfile}'.format(
|
' >> {outfile}'.format(
|
||||||
@ -118,11 +228,17 @@ def dump(cols, tablename, where=''):
|
|||||||
def main():
|
def main():
|
||||||
unique_tables = set()
|
unique_tables = set()
|
||||||
|
|
||||||
for f in fixtures:
|
for f in FIXTURES:
|
||||||
column_id, boundary_id, timespan = f
|
column_id, boundary_id, timespan = f
|
||||||
tablename_query = get_tablename_query(column_id, boundary_id, timespan)
|
tablename_query = get_tablename_query(column_id, boundary_id, timespan)
|
||||||
tablename, colname = query(tablename_query).fetchone()
|
resp = query(tablename_query).fetchone()
|
||||||
table_colname = (tablename, colname, boundary_id, )
|
if resp:
|
||||||
|
tablename, colname, table_id = resp
|
||||||
|
else:
|
||||||
|
print("Could not find table for {}, {}, {}".format(
|
||||||
|
column_id, boundary_id, timespan))
|
||||||
|
continue
|
||||||
|
table_colname = (tablename, colname, boundary_id, table_id, )
|
||||||
if table_colname not in unique_tables:
|
if table_colname not in unique_tables:
|
||||||
print(table_colname)
|
print(table_colname)
|
||||||
unique_tables.add(table_colname)
|
unique_tables.add(table_colname)
|
||||||
@ -142,54 +258,63 @@ def main():
|
|||||||
where = "WHERE " + " OR ".join([
|
where = "WHERE " + " OR ".join([
|
||||||
"(numer_id, geom_id, numer_timespan) = ('{}', '{}', '{}')".format(
|
"(numer_id, geom_id, numer_timespan) = ('{}', '{}', '{}')".format(
|
||||||
numer_id, geom_id, timespan)
|
numer_id, geom_id, timespan)
|
||||||
for numer_id, geom_id, timespan in fixtures
|
for numer_id, geom_id, timespan in FIXTURES
|
||||||
])
|
])
|
||||||
elif tablename == 'obs_meta_numer':
|
elif tablename == 'obs_meta_numer':
|
||||||
where = "WHERE " + " OR ".join([
|
where = "WHERE " + " OR ".join([
|
||||||
"numer_id IN ('{}', '{}')".format(numer_id, geom_id)
|
"numer_id IN ('{}', '{}')".format(numer_id, geom_id)
|
||||||
for numer_id, geom_id, timespan in fixtures
|
for numer_id, geom_id, timespan in FIXTURES
|
||||||
])
|
])
|
||||||
elif tablename == 'obs_meta_denom':
|
elif tablename == 'obs_meta_denom':
|
||||||
where = "WHERE " + " OR ".join([
|
where = "WHERE " + " OR ".join([
|
||||||
"denom_id IN ('{}', '{}')".format(numer_id, geom_id)
|
"denom_id IN ('{}', '{}')".format(numer_id, geom_id)
|
||||||
for numer_id, geom_id, timespan in fixtures
|
for numer_id, geom_id, timespan in FIXTURES
|
||||||
])
|
])
|
||||||
elif tablename == 'obs_meta_geom':
|
elif tablename == 'obs_meta_geom':
|
||||||
where = "WHERE " + " OR ".join([
|
where = "WHERE " + " OR ".join([
|
||||||
"geom_id IN ('{}', '{}')".format(numer_id, geom_id)
|
"geom_id IN ('{}', '{}')".format(numer_id, geom_id)
|
||||||
for numer_id, geom_id, timespan in fixtures
|
for numer_id, geom_id, timespan in FIXTURES
|
||||||
])
|
])
|
||||||
elif tablename == 'obs_meta_timespan':
|
elif tablename == 'obs_meta_timespan':
|
||||||
where = "WHERE " + " OR ".join([
|
where = "WHERE " + " OR ".join([
|
||||||
"timespan_id = ('{}')".format(timespan)
|
"timespan_id = ('{}')".format(timespan)
|
||||||
for numer_id, geom_id, timespan in fixtures
|
for numer_id, geom_id, timespan in FIXTURES
|
||||||
])
|
])
|
||||||
elif tablename == 'obs_column':
|
elif tablename == 'obs_column':
|
||||||
where = "WHERE " + " OR ".join([
|
where = "WHERE " + " OR ".join([
|
||||||
"id IN ('{}', '{}')".format(numer_id, geom_id)
|
"id IN ('{}', '{}')".format(numer_id, geom_id)
|
||||||
for numer_id, geom_id, timespan in fixtures
|
for numer_id, geom_id, timespan in FIXTURES
|
||||||
])
|
])
|
||||||
elif tablename in ('obs_column_table', 'obs_column_tag'):
|
elif tablename == 'obs_column_tag':
|
||||||
where = "WHERE " + " OR ".join([
|
where = "WHERE " + " OR ".join([
|
||||||
"column_id IN ('{}', '{}')".format(numer_id, geom_id)
|
"column_id IN ('{}', '{}')".format(numer_id, geom_id)
|
||||||
for numer_id, geom_id, timespan in fixtures
|
for numer_id, geom_id, timespan in FIXTURES
|
||||||
])
|
])
|
||||||
|
elif tablename == 'obs_column_table':
|
||||||
|
where = 'WHERE column_id IN ({numer_ids}) ' \
|
||||||
|
'OR column_id IN ({geom_ids}) ' \
|
||||||
|
'OR table_id IN ({table_ids}) '.format(
|
||||||
|
numer_ids=','.join(["'{}'".format(x) for x, _, _ in FIXTURES]),
|
||||||
|
geom_ids=','.join(["'{}'".format(x) for _, x, _ in FIXTURES]),
|
||||||
|
table_ids=','.join(["'{}'".format(x) for _, _, _, x in unique_tables])
|
||||||
|
)
|
||||||
elif tablename == 'obs_column_to_column':
|
elif tablename == 'obs_column_to_column':
|
||||||
where = "WHERE " + " OR ".join([
|
where = "WHERE " + " OR ".join([
|
||||||
"source_id IN ('{}', '{}') OR target_id IN ('{}', '{}')".format(
|
"source_id IN ('{}', '{}') OR target_id IN ('{}', '{}')".format(
|
||||||
numer_id, geom_id, numer_id, geom_id)
|
numer_id, geom_id, numer_id, geom_id)
|
||||||
for numer_id, geom_id, timespan in fixtures
|
for numer_id, geom_id, timespan in FIXTURES
|
||||||
])
|
])
|
||||||
elif tablename == 'obs_table':
|
elif tablename == 'obs_table':
|
||||||
where = "WHERE " + " OR ".join([
|
where = 'WHERE timespan IN ({timespans}) ' \
|
||||||
"timespan = '{}'".format(timespan)
|
'OR id IN ({table_ids}) '.format(
|
||||||
for numer_id, geom_id, timespan in fixtures
|
timespans=','.join(["'{}'".format(x) for _, _, x in FIXTURES]),
|
||||||
])
|
table_ids=','.join(["'{}'".format(x) for _, _, _, x in unique_tables])
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
where = ''
|
where = ''
|
||||||
dump('*', tablename, where)
|
dump('*', tablename, where)
|
||||||
|
|
||||||
for tablename, colname, boundary_id in unique_tables:
|
for tablename, colname, boundary_id, table_id in unique_tables:
|
||||||
if 'zcta5' in boundary_id:
|
if 'zcta5' in boundary_id:
|
||||||
where = '\'11%\''
|
where = '\'11%\''
|
||||||
compare = 'LIKE'
|
compare = 'LIKE'
|
||||||
@ -201,9 +326,6 @@ def main():
|
|||||||
compare = 'LIKE'
|
compare = 'LIKE'
|
||||||
print ' '.join(['*', tablename, "WHERE {}::text {} {}".format(colname, compare, where)])
|
print ' '.join(['*', tablename, "WHERE {}::text {} {}".format(colname, compare, where)])
|
||||||
dump('*', tablename, "WHERE {}::text {} {}".format(colname, compare, where))
|
dump('*', tablename, "WHERE {}::text {} {}".format(colname, compare, where))
|
||||||
#cdb.dump(' '.join([select_star(tablename), "WHERE {}::text {} {}".format(colname, compare, where)]),
|
|
||||||
# tablename, outfile, schema='observatory')
|
|
||||||
#dropfiles.write('DROP TABLE IF EXISTS observatory.{};\n'.format(tablename))
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
25
src/pg/test/fixtures/drop_fixtures.sql
vendored
25
src/pg/test/fixtures/drop_fixtures.sql
vendored
@ -12,16 +12,17 @@ DROP TABLE IF EXISTS observatory.obs_meta_numer;
|
|||||||
DROP TABLE IF EXISTS observatory.obs_meta_denom;
|
DROP TABLE IF EXISTS observatory.obs_meta_denom;
|
||||||
DROP TABLE IF EXISTS observatory.obs_meta_geom;
|
DROP TABLE IF EXISTS observatory.obs_meta_geom;
|
||||||
DROP TABLE IF EXISTS observatory.obs_meta_timespan;
|
DROP TABLE IF EXISTS observatory.obs_meta_timespan;
|
||||||
DROP TABLE IF EXISTS observatory.obs_65f29658e096ca1485bf683f65fdbc9f05ec3c5d;
|
DROP TABLE IF EXISTS observatory.obs_fcd4e4f5610f6764973ef8c0c215b2e80bec8963;
|
||||||
DROP TABLE IF EXISTS observatory.obs_1746e37b7cd28cb131971ea4187d42d71f09c5f3;
|
|
||||||
DROP TABLE IF EXISTS observatory.obs_1a098da56badf5f32e336002b0a81708c40d29cd;
|
|
||||||
DROP TABLE IF EXISTS observatory.obs_7615e8622a68bfc5fe37c69c9880edfb40250103;
|
|
||||||
DROP TABLE IF EXISTS observatory.obs_1babf5a26a1ecda5fb74963e88408f71d0364b81;
|
|
||||||
DROP TABLE IF EXISTS observatory.obs_8764a6b439a4f8714f54d4b3a157bc5e36519066;
|
|
||||||
DROP TABLE IF EXISTS observatory.obs_b393b5b88c6adda634b2071a8005b03c551b609a;
|
|
||||||
DROP TABLE IF EXISTS observatory.obs_1ea93bbc109c87c676b3270789dacf7a1430db6c;
|
|
||||||
DROP TABLE IF EXISTS observatory.obs_fc050f0b8673cfe3c6aa1040f749eb40975691b7;
|
|
||||||
DROP TABLE IF EXISTS observatory.obs_6c1309a64d8f3e6986061f4d1ca7b57743e75e74;
|
|
||||||
DROP TABLE IF EXISTS observatory.obs_d39f7fe5959891c8296490d83c22ded31c54af13;
|
|
||||||
DROP TABLE IF EXISTS observatory.obs_144e8b4f906885b2e057ac4842644a553ae49c6e;
|
|
||||||
DROP TABLE IF EXISTS observatory.obs_c6fb99c47d61289fbb8e561ff7773799d3fcc308;
|
DROP TABLE IF EXISTS observatory.obs_c6fb99c47d61289fbb8e561ff7773799d3fcc308;
|
||||||
|
DROP TABLE IF EXISTS observatory.obs_6c1309a64d8f3e6986061f4d1ca7b57743e75e74;
|
||||||
|
DROP TABLE IF EXISTS observatory.obs_7615e8622a68bfc5fe37c69c9880edfb40250103;
|
||||||
|
DROP TABLE IF EXISTS observatory.obs_d39f7fe5959891c8296490d83c22ded31c54af13;
|
||||||
|
DROP TABLE IF EXISTS observatory.obs_1babf5a26a1ecda5fb74963e88408f71d0364b81;
|
||||||
|
DROP TABLE IF EXISTS observatory.obs_65f29658e096ca1485bf683f65fdbc9f05ec3c5d;
|
||||||
|
DROP TABLE IF EXISTS observatory.obs_144e8b4f906885b2e057ac4842644a553ae49c6e;
|
||||||
|
DROP TABLE IF EXISTS observatory.obs_fc050f0b8673cfe3c6aa1040f749eb40975691b7;
|
||||||
|
DROP TABLE IF EXISTS observatory.obs_1a098da56badf5f32e336002b0a81708c40d29cd;
|
||||||
|
DROP TABLE IF EXISTS observatory.obs_1ea93bbc109c87c676b3270789dacf7a1430db6c;
|
||||||
|
DROP TABLE IF EXISTS observatory.obs_b393b5b88c6adda634b2071a8005b03c551b609a;
|
||||||
|
DROP TABLE IF EXISTS observatory.obs_1746e37b7cd28cb131971ea4187d42d71f09c5f3;
|
||||||
|
DROP TABLE IF EXISTS observatory.obs_a01cd5d8ccaa6531cef715071e9307e6b1987ec3;
|
||||||
|
19036
src/pg/test/fixtures/load_fixtures.sql
vendored
19036
src/pg/test/fixtures/load_fixtures.sql
vendored
File diff suppressed because one or more lines are too long
@ -67,7 +67,7 @@ FROM cte;
|
|||||||
SELECT
|
SELECT
|
||||||
(cdb_observatory._OBS_GetPoints(
|
(cdb_observatory._OBS_GetPoints(
|
||||||
ST_SetSRID(ST_Point(0, 0), 4326),
|
ST_SetSRID(ST_Point(0, 0), 4326),
|
||||||
'obs_1a098da56badf5f32e336002b0a81708c40d29cd'::text, -- see example in obs_geomtable
|
'obs_c6fb99c47d61289fbb8e561ff7773799d3fcc308'::text, -- see example in obs_geomtable
|
||||||
(Array['{"colname":"total_pop","tablename":"obs_1a098da56badf5f32e336002b0a81708c40d29cd","aggregate":"sum","name":"Total Population","type":"Numeric","description":"The total number of all people living in a given geographic area. This is a very useful catch-all denominator when calculating rates."}'::json])
|
(Array['{"colname":"total_pop","tablename":"obs_1a098da56badf5f32e336002b0a81708c40d29cd","aggregate":"sum","name":"Total Population","type":"Numeric","description":"The total number of all people living in a given geographic area. This is a very useful catch-all denominator when calculating rates."}'::json])
|
||||||
))[1]::text is null
|
))[1]::text is null
|
||||||
as OBS_GetPoints_for_null_island;
|
as OBS_GetPoints_for_null_island;
|
||||||
@ -89,7 +89,7 @@ SELECT
|
|||||||
SELECT
|
SELECT
|
||||||
((cdb_observatory._OBS_GetPolygons(
|
((cdb_observatory._OBS_GetPolygons(
|
||||||
ST_Buffer(ST_SetSRID(ST_Point(0, 0), 4326)::geography, 500)::geometry,
|
ST_Buffer(ST_SetSRID(ST_Point(0, 0), 4326)::geography, 500)::geometry,
|
||||||
'obs_1a098da56badf5f32e336002b0a81708c40d29cd'::text, -- see example in obs_geomtable
|
'obs_c6fb99c47d61289fbb8e561ff7773799d3fcc308'::text, -- see example in obs_geomtable
|
||||||
Array['{"colname":"total_pop","tablename":"obs_1a098da56badf5f32e336002b0a81708c40d29cd","aggregate":"sum","name":"Total Population","type":"Numeric","description":"The total number of all people living in a given geographic area. This is a very useful catch-all denominator when calculating rates."}'::json])
|
Array['{"colname":"total_pop","tablename":"obs_1a098da56badf5f32e336002b0a81708c40d29cd","aggregate":"sum","name":"Total Population","type":"Numeric","description":"The total number of all people living in a given geographic area. This is a very useful catch-all denominator when calculating rates."}'::json])
|
||||||
)[1]->>'value') is null
|
)[1]->>'value') is null
|
||||||
as OBS_GetPolygons_for_null_island;
|
as OBS_GetPolygons_for_null_island;
|
||||||
@ -129,15 +129,15 @@ WITH result as (
|
|||||||
from result;
|
from result;
|
||||||
|
|
||||||
-- Point-based OBS_GetMeasure with zillow
|
-- Point-based OBS_GetMeasure with zillow
|
||||||
SELECT abs(OBS_GetMeasure_zhvi_point - 583600) / 583600 < 0.001 AS OBS_GetMeasure_zhvi_point_test FROM cdb_observatory.OBS_GetMeasure(
|
SELECT abs(OBS_GetMeasure_zhvi_point - 597900) / 597900 < 5.0 AS OBS_GetMeasure_zhvi_point_test FROM cdb_observatory.OBS_GetMeasure(
|
||||||
ST_SetSRID(ST_Point(-73.94602417945862, 40.6768220087458), 4326),
|
ST_SetSRID(ST_Point(-73.94602417945862, 40.6768220087458), 4326),
|
||||||
'us.zillow.AllHomes_Zhvi', null, 'us.census.tiger.zcta5', '2014-01'
|
'us.zillow.AllHomes_Zhvi', null, 'us.census.tiger.zcta5', '2014-01'
|
||||||
) As t(OBS_GetMeasure_zhvi_point);
|
) As t(OBS_GetMeasure_zhvi_point);
|
||||||
|
|
||||||
-- Point-based OBS_GetMeasure with zillow default to latest
|
-- Point-based OBS_GetMeasure with later measure
|
||||||
SELECT abs(OBS_GetMeasure_zhvi_point_default_latest - 972900) / 972900 < 0.001 AS OBS_GetMeasure_zhvi_point_default_latest_test FROM cdb_observatory.OBS_GetMeasure(
|
SELECT abs(OBS_GetMeasure_zhvi_point_default_latest - 995400) / 995400 < 5.0 AS OBS_GetMeasure_zhvi_point_default_latest_test FROM cdb_observatory.OBS_GetMeasure(
|
||||||
ST_SetSRID(ST_Point(-73.94602417945862, 40.6768220087458), 4326),
|
ST_SetSRID(ST_Point(-73.94602417945862, 40.6768220087458), 4326),
|
||||||
'us.zillow.AllHomes_Zhvi'
|
'us.zillow.AllHomes_Zhvi', null, 'us.census.tiger.zcta5', '2016-06'
|
||||||
) As t(OBS_GetMeasure_zhvi_point_default_latest);
|
) As t(OBS_GetMeasure_zhvi_point_default_latest);
|
||||||
|
|
||||||
-- Point-based OBS_GetMeasure, default normalization (area)
|
-- Point-based OBS_GetMeasure, default normalization (area)
|
||||||
|
Loading…
Reference in New Issue
Block a user