-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor singular test to use intermediate tables:
* These intermediate tables can also be used to populate reports to share with DOF
- Loading branch information
Showing
9 changed files
with
194 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
version: 2 | ||
|
||
models: | ||
- name: qaqc_int__active_condo_bbl_unitsres_corrections | ||
description: | | ||
Contains condo bbls that are being corrected for res units in final PLUTO, using `pluto_input_research.csv` file | ||
columns: | ||
- name: bbl | ||
- name: old_value | ||
|
||
- name: qaqc_int__devdb_bbl_units_summary | ||
description: | | ||
This table provides total number of units per bbl, based on the most recent construction records in DevDB, excluding demolitions. | ||
columns: | ||
- name: bbl | ||
- name: units_co | ||
description: Total number of certificate of occupancy (CO) units | ||
- name: classa_prop | ||
description: Total number of Class A units (residential units) | ||
- name: count_bins | ||
description: Total number of BINs per BBL that had modification in DevDB. Note, this may not represent all building on a lot |
28 changes: 28 additions & 0 deletions
28
products/pluto/models/qaqc/intermediate/qaqc_int__active_condo_bbl_unitsres_corrections.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{{ config( | ||
materialized = 'table' | ||
) }} | ||
|
||
WITH historical_condo_unit_corrections AS ( | ||
SELECT | ||
bbl, | ||
old_value::numeric | ||
FROM {{ source("recipe_sources", "pluto_input_research") }} | ||
WHERE field = 'unitsres' | ||
AND substring(bbl, 7, 2) = '75' | ||
), | ||
|
||
primebbl_condo_units AS ( | ||
SELECT | ||
primebbl, | ||
sum(coop_apts) AS coop_apts, | ||
sum(units) AS units | ||
FROM {{ ref('pluto_rpad_geo') }} | ||
WHERE tl NOT LIKE '75%' | ||
GROUP BY primebbl | ||
) | ||
|
||
SELECT l.* | ||
FROM historical_condo_unit_corrections AS l | ||
INNER JOIN primebbl_condo_units AS r | ||
ON l.bbl = r.primebbl | ||
WHERE l.old_value = r.coop_apts |
42 changes: 42 additions & 0 deletions
42
products/pluto/models/qaqc/intermediate/qaqc_int__devdb_bbl_units_summary.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{{ config( | ||
materialized = 'table' | ||
) }} | ||
|
||
WITH completed_construction_records AS ( | ||
SELECT | ||
bbl, | ||
bin, | ||
units_co, | ||
CASE | ||
WHEN classa_prop IS null AND job_status = '5. Completed Construction' THEN 0 | ||
ELSE classa_prop | ||
END AS classa_prop_modified, | ||
job_type, | ||
job_status, | ||
date_complete, | ||
row_number() OVER (PARTITION BY bbl, bin ORDER BY date_complete DESC) AS order_num | ||
FROM {{ ref("stg__dcp_developments") }} | ||
WHERE job_status IN ('5. Completed Construction', '4. Partially Completed Construction') | ||
), | ||
|
||
most_recent_construction_by_bin AS ( | ||
SELECT | ||
bbl, | ||
bin, | ||
units_co, | ||
classa_prop_modified AS classa_prop, | ||
job_type, | ||
job_status, | ||
date_complete | ||
FROM completed_construction_records | ||
WHERE order_num = 1 -- Selecting the most recent record per BIN | ||
) | ||
|
||
SELECT | ||
bbl, | ||
sum(units_co) AS units_co, | ||
sum(classa_prop) AS classa_prop, | ||
count(*) AS count_bins | ||
FROM most_recent_construction_by_bin | ||
WHERE job_type <> 'Demolition' -- Exclude demolished buildings as property taxes may still be paid, aligning with the DOF data | ||
GROUP BY bbl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
version: 2 | ||
|
||
models: | ||
- name: qaqc_reports__dof_incorrect_condo_res_units | ||
description: | | ||
This report is to be shared with DOF. | ||
It contains DOF records that need to be corrected for res unit count at the source, supplied with DevDB unit counts | ||
columns: | ||
- name: primebbl | ||
- name: units | ||
description: DOF number of total units (including non-residential) per BBL | ||
- name: coop_apts | ||
description: DOF number of residential units per BBL | ||
- name: units_co | ||
description: DevDB number of units on Certificate of Occupancy | ||
- name: classa_prop | ||
description: DevDB number of class A units | ||
- name: dof_matches_devdb_units | ||
description: Flag to indicate whether DOF res units match DevDB res units (coop_apts == classa_prop) | ||
- name: diff | ||
description: Difference in residential units between | ||
|
||
- name: qaqc_reports__dof_pts_incorrect_condo_res_units | ||
description: | | ||
This report is to be shared with DOF. | ||
It contains raw DOF PTS data filtered for condo records in `qaqc_reports__dof_incorrect_condo_res_units`` |
27 changes: 27 additions & 0 deletions
27
products/pluto/models/qaqc/reports/qaqc_reports__dof_incorrect_condo_res_units.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
WITH active_condo_unitsres_corrections AS ( | ||
SELECT bbl | ||
FROM {{ ref('qaqc_int__active_condo_bbl_unitsres_corrections') }} | ||
), | ||
|
||
dof_condo_units AS ( | ||
SELECT | ||
primebbl, | ||
sum(coop_apts) AS coop_apts, | ||
sum(units) AS units | ||
FROM {{ ref('pluto_rpad_geo') }} | ||
WHERE | ||
primebbl IN (SELECT bbl FROM active_condo_unitsres_corrections) | ||
AND tl NOT LIKE '75%' | ||
GROUP BY primebbl | ||
) | ||
|
||
SELECT | ||
l.*, | ||
r.units_co, | ||
r.classa_prop, | ||
r.count_bins, | ||
l.coop_apts = r.classa_prop AS dof_matches_devdb_units, | ||
r.classa_prop - l.coop_apts AS diff | ||
FROM dof_condo_units AS l | ||
INNER JOIN {{ ref('qaqc_int__devdb_bbl_units_summary') }} AS r | ||
ON l.primebbl = r.bbl |
18 changes: 18 additions & 0 deletions
18
products/pluto/models/qaqc/reports/qaqc_reports__dof_pts_incorrect_condo_res_units.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
WITH active_condo_unitsres_corrections AS ( | ||
SELECT bbl | ||
FROM {{ ref('qaqc_int__active_condo_bbl_unitsres_corrections') }} | ||
), | ||
|
||
filtered_dof_pts_propmaster AS ( | ||
SELECT boro || tb || tl AS bbl | ||
FROM {{ ref('dof_pts_propmaster') }} | ||
WHERE primebbl IN ( | ||
SELECT bbl FROM active_condo_unitsres_corrections | ||
) | ||
) | ||
|
||
SELECT * FROM | ||
{{ source("recipe_sources", "pluto_pts") }} | ||
WHERE (boro || block || lot) IN ( | ||
SELECT bbl FROM filtered_dof_pts_propmaster | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
version: 2 | ||
|
||
seeds: | ||
- name: ignored_bbls_for_unit_count_test | ||
description: | | ||
List of manually researched bbls that have correct count of residential units in DOF PTS data, | ||
despite failing `assert_condo_bbl_unit_count_research_required` test. These records are ignored | ||
during the test. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
bbl,pluto_version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters