Skip to content

Commit

Permalink
add boros to cdbg
Browse files Browse the repository at this point in the history
  • Loading branch information
fvankrieken authored and damonmcc committed Jan 3, 2025
1 parent 509daca commit 06787e0
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 43 deletions.
12 changes: 12 additions & 0 deletions products/cdbg/models/intermediate/_intermediate_models.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ models:
- name: total_population
tests: [not_null]

- name: int__boros
description: residential area and low-to-moderate income data aggregated by boro
columns:
- name: borough_name
tests: [unique, not_null]
- name: total_floor_area
- name: residential_floor_area
- name: residential_floor_area_percentage
- name: total_population
- name: lowmod_population
- name: lowmod_population_percentage

- name: int__lot_block_groups_details
description: int__lot_block_groups joined to pluto for lot info
columns:
Expand Down
24 changes: 24 additions & 0 deletions products/cdbg/models/intermediate/int__boros.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
WITH tracts AS (
SELECT * FROM {{ ref("int__tracts") }}
),

boros AS (
SELECT
borough_name,
sum(total_floor_area) AS total_floor_area,
sum(residential_floor_area) AS residential_floor_area,
sum(total_population) AS total_population,
sum(low_mod_income_population) AS low_mod_income_population
FROM tracts
GROUP BY borough_name
),

boro_calculation AS (
SELECT
*,
(residential_floor_area / total_floor_area) * 100 AS residential_floor_area_percentage,
(low_mod_income_population / total_population) * 100 AS low_mod_income_population_percentage
FROM boros
)

SELECT * FROM boro_calculation
86 changes: 43 additions & 43 deletions products/cdbg/models/product/_product_models.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
version: 2

models:
- name: cdbg_tracts
description: Census tracts and their Community Development Block Grant (CDBG) eligibility details
- name: cdbg_block_groups
description: Census block groups and their Community Development Block Grant (CDBG) eligibility details
config:
contract:
enforced: false
Expand All @@ -28,6 +28,14 @@ models:
#
# - 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: total_floor_area
Expand Down Expand Up @@ -58,8 +66,39 @@ models:
data_type: string
tests: [not_null]

- name: cdbg_block_groups
description: Census block groups and their Community Development Block Grant (CDBG) eligibility details
- name: cdbg_borough
description: Borough and city-wide Community Development Block Grant (CDBG) details
config:
contract:
enforced: true

columns:
- name: borough_name
data_type: string
tests: [not_null]

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

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

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

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

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

- name: cdbg_tracts
description: Census tracts and their Community Development Block Grant (CDBG) eligibility details
config:
contract:
enforced: false
Expand All @@ -85,14 +124,6 @@ models:
#
# - 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: total_floor_area
Expand Down Expand Up @@ -122,34 +153,3 @@ models:
- name: eligibility
data_type: string
tests: [not_null]

# - name: cdbg_borough
# description: Borough and city-wide Community Development Block Grant (CDBG) details
# config:
# contract:
# enforced: true
#
# columns:
# - name: borough_name
# data_type: string
# tests: [not_null]
#
# - name: total_floor_area
# data_type: integer
# tests: [not_null]
#
# - name: residential_floor_area
# data_type: integer
# tests: [not_null]
#
# - name: residential_floor_area_percentage
# data_type: float
# tests: [not_null]
#
# - name: low_mod_income_population
# data_type: integer
# tests: [not_null]
#
# - name: low_mod_income_population_percentage
# data_type: float
# tests: [not_null]
22 changes: 22 additions & 0 deletions products/cdbg/models/product/cdbg_boros.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
WITH boros AS (
SELECT * FROM {{ ref("int__boros") }}
),

eligibility_calculation AS (
SELECT
*,
low_mod_income_population_percentage > 51 AND residential_floor_area_percentage > 50 AS eligibility_flag
FROM boros
),

eligibility AS (
SELECT
*,
CASE
WHEN eligibility_flag THEN 'CD Eligible'
ELSE 'Ineligible'
END AS eligibility
FROM eligibility_calculation
)

SELECT * FROM eligibility

0 comments on commit 06787e0

Please sign in to comment.