Skip to content

Commit

Permalink
use new source of total population
Browse files Browse the repository at this point in the history
  • Loading branch information
damonmcc committed Jan 2, 2025
1 parent b63951f commit 23ea7b4
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 15 deletions.
2 changes: 2 additions & 0 deletions products/cdbg/models/intermediate/_intermediate_models.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ models:
- name: residential_floor_area
- name: residential_floor_area_percentage
- name: total_population
- name: potential_lowmod_population
- name: lowmod_population
- name: lowmod_population_percentage
- name: low_mod_income_population_percentage_source

- name: int__block_groups_raw
description: census block group geoemtries and demographic data
Expand Down
50 changes: 38 additions & 12 deletions products/cdbg/models/intermediate/int__block_groups.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,30 @@ WITH lot_block_groups AS (
SELECT * FROM {{ ref("int__lot_block_groups_details") }}
),

block_groups_population AS (
SELECT * FROM {{ ref("int__block_groups_raw") }}
),

block_groups_income AS (
SELECT * FROM {{ ref("stg__low_mod_by_block_group") }}
),

block_groups_demographics as (
SELECT
block_groups_population.geoid,
block_groups_population.borough_code,
block_groups_population.borough_name,
block_groups_population.total_population,
block_groups_income.tract,
block_groups_income.block_group,
block_groups_income.potential_lowmod_population,
block_groups_income.low_mod_income_population,
block_groups_income.low_mod_income_population_percentage
FROM block_groups_population
LEFT JOIN block_groups_income
ON block_groups_population.geoid = block_groups_income.geoid
),

block_groups_floor_area AS (
SELECT
block_group_geoid AS geoid,
Expand All @@ -18,22 +38,28 @@ block_groups_floor_area AS (
block_group_details AS (
SELECT
block_groups_floor_area.geoid,
block_groups_income.boro AS borough_name,
block_groups_income.tract,
block_groups_income.block_group,
total_floor_area,
residential_floor_area,
block_groups_demographics.borough_name,
block_groups_demographics.tract,
block_groups_demographics.block_group,
block_groups_floor_area.total_floor_area,
block_groups_floor_area.residential_floor_area,
CASE
WHEN total_floor_area = 0
WHEN block_groups_floor_area.total_floor_area = 0
THEN 0
ELSE (residential_floor_area / total_floor_area) * 100
ELSE (block_groups_floor_area.residential_floor_area / block_groups_floor_area.total_floor_area) * 100
END AS residential_floor_area_percentage,
block_groups_income.total_population,
block_groups_income.lowmod_population AS low_mod_income_population,
block_groups_income.lowmod_pct AS low_mod_income_population_percentage
block_groups_demographics.total_population,
block_groups_demographics.potential_lowmod_population,
block_groups_demographics.low_mod_income_population,
CASE
WHEN block_groups_demographics.total_population = 0
THEN 0
ELSE (block_groups_demographics.low_mod_income_population / block_groups_demographics.total_population) * 100
END AS low_mod_income_population_percentage,
block_groups_demographics.low_mod_income_population_percentage AS low_mod_income_population_percentage_source
FROM block_groups_floor_area
LEFT JOIN block_groups_income
ON block_groups_floor_area.geoid = block_groups_income.geoid
LEFT JOIN block_groups_demographics
ON block_groups_floor_area.geoid = block_groups_demographics.geoid
)

SELECT * FROM block_group_details
6 changes: 3 additions & 3 deletions products/cdbg/models/staging/stg__low_mod_by_block_group.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ SELECT
"BORO" AS boro,
"TRACT" AS tract,
"BLKGRP" AS block_group,
REPLACE("LOWMODUNIV", ',', '')::numeric AS total_population,
REPLACE("LOWMOD", ',', '')::numeric AS lowmod_population,
RTRIM("LOWMOD_PCT", '%')::numeric AS lowmod_pct
REPLACE("LOWMODUNIV", ',', '')::numeric AS potential_lowmod_population,
REPLACE("LOWMOD", ',', '')::numeric AS low_mod_income_population,
RTRIM("LOWMOD_PCT", '%')::numeric AS low_mod_income_population_percentage
FROM {{ source("recipe_sources", "hud_lowmodincomebyblockgroup") }}

0 comments on commit 23ea7b4

Please sign in to comment.