Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve cdbg exports #1364

Merged
merged 6 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions products/cdbg/models/intermediate/int__block_groups.sql
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ block_group_details AS (
SELECT
block_groups_floor_area.geoid,
block_groups_demographics.borough_name,
block_groups_demographics.borough_code,
block_groups_demographics.tract,
block_groups_demographics.block_group,
block_groups_floor_area.total_floor_area,
Expand Down
36 changes: 14 additions & 22 deletions products/cdbg/models/product/_product_models.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ models:
description: Census block groups and their Community Development Block Grant (CDBG) eligibility details
config:
contract:
enforced: false
enforced: true

columns:
- name: geoid
Expand All @@ -18,25 +18,17 @@ models:
data_type: string
tests: [not_null]

# - name: borough_code
# data_type: integer
# tests: [not_null]
#
# - name: borough_tract
# data_type: string
# tests: [not_null]
#
# - name: tract
# data_type: string
# tests: [not_null]
#
# - name: borough_tract_block_group
# data_type: string
# tests: [not_null]
#
# - name: block_group
# data_type: string
# tests: [not_null]
- name: borough_code
data_type: integer
tests: [not_null]

- name: tract
data_type: string
tests: [not_null]

- name: block_group
data_type: string
tests: [not_null]

- name: total_floor_area
data_type: integer
Expand All @@ -47,15 +39,15 @@ models:
tests: [not_null]

- name: residential_floor_area_percentage
data_type: float
data_type: decimal
tests: [not_null]

- name: low_mod_income_population
data_type: integer
tests: [not_null]

- name: low_mod_income_population_percentage
data_type: float
data_type: decimal
tests: [not_null]

- name: eligibility_flag
Expand Down
11 changes: 10 additions & 1 deletion products/cdbg/models/product/cdbg_block_groups.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@ WITH block_groups AS (

eligibility_calculation AS (
SELECT
*,
geoid,
borough_name,
borough_code,
tract,
block_group,
round(total_floor_area::numeric)::integer AS total_floor_area,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the data type before the cast to numeric?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess double precision - I forgot you can't just round that.

I do think you can just cast a double precision to integer to round though

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gotcha. I wasn't sure if casting to integer would round correcting, always round in one direction, or truncate

round(residential_floor_area::numeric)::integer AS residential_floor_area,
round(residential_floor_area_percentage::numeric, 2) AS residential_floor_area_percentage,
low_mod_income_population,
round(low_mod_income_population_percentage::numeric, 2) AS low_mod_income_population_percentage,
low_mod_income_population_percentage > 51 AND residential_floor_area_percentage > 50 AS eligibility_flag
FROM block_groups
),
Expand Down
2 changes: 1 addition & 1 deletion products/cdbg/models/staging/stg__census_data_blocks.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
SELECT
geoid20 AS bctcb2020,
borocode AS borough_code,
borocode::integer AS borough_code,
geogname AS borough_name,
"pop1.1"::numeric AS total_population -- noqa: RF01
FROM {{ source("recipe_sources", "dcp_censusdata_blocks") }}
Expand Down
8 changes: 4 additions & 4 deletions products/cdbg/models/staging/stg__low_mod_by_block_group.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
SELECT
"GEOID"::text AS geoid, -- TODO: coerce to text in ingest
"BORO" AS boro,
"TRACT" AS tract,
"BLKGRP" AS block_group,
REPLACE("LOWMODUNIV", ',', '')::numeric AS potential_lowmod_population,
REPLACE("LOWMOD", ',', '')::numeric AS low_mod_income_population,
"TRACT"::text AS tract,
"BLKGRP"::text AS block_group,
REPLACE("LOWMODUNIV", ',', '')::integer AS potential_lowmod_population,
REPLACE("LOWMOD", ',', '')::integer AS low_mod_income_population,
RTRIM("LOWMOD_PCT", '%')::numeric AS low_mod_income_population_percentage
FROM {{ source("recipe_sources", "hud_lowmodincomebyblockgroup") }}