-
Notifications
You must be signed in to change notification settings - Fork 15
Add QAQC tables for Condo Checks #428
base: main
Are you sure you want to change the base?
Changes from 10 commits
4bbcbc1
a827d79
7c71fe8
e7b0949
ec9b541
814b2b2
51f87f4
7ca3a4a
5d57405
d0f4c12
8b97245
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| -- Create qaqc table All PLUTO records where there is a match in Housing Database | ||
| -- and the PLUTO residential units value does not match the housing database certificates | ||
| -- of occupancy value. Have flag indicating if bbl has residential unit correction in manual corrections table. | ||
| -- select PLUTO records that have a match in the HousingDB subset where unitsres does not equal units co | ||
|
||
|
|
||
|
|
||
| -- Data Dictionary | ||
| -- bbl - billing BBL | ||
| -- job_number - The DOB job application number assigned when the applicant begins the application. This is the unique identifier for the application submitted to the Department of Buildings (DOB). | ||
| -- units_res - The number of residential units as reported by dcp_housing database | ||
|
||
| -- units_co - The number of units listed on the DOB issued Certificate of Occupancy | ||
| -- new_value | ||
| -- old_value | ||
|
||
|
|
||
|
|
||
| CREATE TABLE IF NOT EXISTS qaqc_housing_units( | ||
| bbl text, | ||
| job_number text, | ||
| unitsres text, | ||
| units_co text, | ||
| new_value text, | ||
| old_value text | ||
| ); | ||
|
|
||
| INSERT INTO qaqc_housing_units | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are duplicate records in the output table in DO. This may have to do with the |
||
| WITH base as( | ||
| SELECT DISTINCT round(a.bbl::numeric,0)::text as bbl,b.job_number,a.unitsres,round(b.units_co::numeric,0)::text as units_co | ||
| FROM pluto a, dcp_housing b | ||
| WHERE b.bbl||b.date_lastupdt IN ( | ||
| -- get the most recent DOB record for a BBL based on date of last update field | ||
| SELECT bbl||max(date_lastupdt::date) maxDate | ||
| FROM dcp_housing | ||
| GROUP BY bbl) | ||
| AND round(a.bbl::numeric,0)::text=b.bbl | ||
| AND a.unitsres<>round(b.units_co::numeric,0)::text), | ||
| -- select only corrections to unitsres field | ||
| corrections_subset as ( | ||
| SELECT * | ||
| FROM pluto_corrections | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're no longer pulling in |
||
| WHERE field='unitsres') | ||
| -- combine PLUTO, DOB, and corrections data for final output | ||
| SELECT a.*, c.new_value, c.old_value | ||
| FROM base a | ||
| LEFT JOIN corrections_subset c | ||
| ON a.bbl=c.bbl; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| -- Record PTS records that meet the criteria of | ||
| -- The units and coop_apts values are greater than one for the billing bbl AND | ||
| -- Two or more unit bbl records have units and coop_apts values greater than 1 | ||
|
|
||
| -- Data Dictionary | ||
|
|
||
| -- primebbl - Billing BBL | ||
| -- bbl - Unit level BBl | ||
| -- units - The number of units listed by Department of Finance for the property (compare to units_co in dcp_housing) | ||
| -- coop_apts - The number of coop apartments listed for the property | ||
|
||
| -- job_number - The DOB job application number assigned when the applicant begins the application. This is the unique identifier for the application submitted to the Department of Buildings (DOB). | ||
| -- units_co - The number of units listed on the DOB issued Certificate of Occupancy | ||
| -- date_lastupdt - The date of the last update to the DOB record for the job filing. | ||
| -- new_value - The new number of units as reported by the pluto_corrections file | ||
| -- old_value - The previous number of units as reported by the pluto_correction file | ||
|
|
||
|
|
||
| CREATE TABLE IF NOT EXISTS qaqc_pts_condo( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are duplicate records in the output table in DO. This may have to do with the CREATE TABLE IF NOT EXISTS and INSERT INTO statements. I confirmed that the duplicates do not appear when querying the database directly. |
||
| primebbl text, | ||
| bbl text, | ||
| units numeric, | ||
| coop_apts numeric, | ||
| job_number text, | ||
| units_co text, | ||
| date_lastupdt varchar, | ||
| new_value text, | ||
| old_value text | ||
| ); | ||
|
|
||
| INSERT INTO qaqc_pts_condo | ||
| WITH pts_subset as ( | ||
| SELECT primebbl, bbl, units, coop_apts | ||
| FROM pluto_rpad_geo | ||
| WHERE primebbl IN ( | ||
| SELECT primebbl FROM ( | ||
| SELECT primebbl, COUNT(*) | ||
| FROM pluto_rpad_geo | ||
| WHERE tl NOT LIKE '75%' | ||
| AND RIGHT(primebbl,4) LIKE '75%' | ||
| AND units::integer > 1 | ||
| AND coop_apts::integer > 1 | ||
| GROUP BY primebbl, units, coop_apts) as badbases | ||
| WHERE count>1) | ||
| AND primebbl IN ( | ||
| SELECT primebbl FROM ( | ||
| SELECT primebbl | ||
| FROM pluto_rpad_geo | ||
| WHERE tl LIKE '75%' | ||
| AND units::integer > 1 | ||
| AND coop_apts::integer > 1) as badbillings)), | ||
| -- get the most recent DOB record for a BBL based on date of last update field | ||
| dob_subset as ( | ||
| SELECT * FROM dcp_housing b | ||
| WHERE b.bbl||b.date_lastupdt IN ( | ||
| SELECT bbl||max(date_lastupdt::date) maxDate | ||
| FROM dcp_housing | ||
| GROUP BY bbl)), | ||
| -- select only corrections to unitsres field | ||
| corrections_subset as ( | ||
| SELECT * | ||
| FROM pluto_corrections | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're no longer pulling in pluto_corrections per PR #425 so this needs to be changed. |
||
| WHERE field='unitsres'), | ||
| -- Join PTS and DOB subsets, preserving all PTS records | ||
| pts_dob as ( | ||
| SELECT a.*, b.job_number, round(b.units_co::numeric,0)::text as units_co, b.date_lastupdt | ||
| FROM pts_subset a | ||
| LEFT JOIN dob_subset b | ||
| ON a.bbl=b.bbl | ||
| AND a.coop_apts::text<>round(b.units_co::numeric,0)::text) | ||
| -- Join on corrections to produce final output | ||
| SELECT a.*, c.new_value, c.old_value | ||
| FROM pts_dob a | ||
| LEFT JOIN corrections_subset c | ||
| ON a.bbl=c.bbl; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing "of"
I think this need to be " Create qaqc table of all PLUTO records where there is a match in Housing Database"