Skip to content

Commit 2ff36fe

Browse files
authored
slight tweaks with devdb cos (#2159)
* add dob_cofos ingest templates * refactor _co.sql
1 parent a8f33db commit 2ff36fe

File tree

3 files changed

+95
-54
lines changed

3 files changed

+95
-54
lines changed

ingest_templates/dob_bis_cofos.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
id: dob_bis_cofos
2+
acl: public-read
3+
4+
attributes:
5+
name: DOB BIS Certificate Of Occupancy
6+
description: >-
7+
A Certificate of Occupancy (CO) states a building's legal use and/or type of
8+
permitted occupancy. New buildings must have a CO, and existing buildings must have
9+
a current or amended CO when there is a change in use, egress or type of occupancy.
10+
No one may legally occupy a building until the Department has issued a Certificate
11+
of Occupancy or Temporary Certificate of Occupancy. The Department issues a final
12+
Certificate of Occupancy when the completed work matches the submitted plans for new
13+
buildings or major alterations. It issues a Letter of Completion for minor
14+
alterations to properties. These documents confirm the work complies with all
15+
applicable laws, all paperwork has been completed, all fees owed to the Department
16+
have been paid, all relevant violations have been resolved and all necessary
17+
approvals have been received from other City Agencies.
18+
19+
This dataset contains all Certificates of Occupancy issued from 7/12/2012 to March
20+
2021. PDFs of the actual COs are viewable in www.nyc.gov/bis.
21+
22+
For COs issued since March 2021, see DOB NOW: Certificate of Occupancy dataset.
23+
url: https://data.cityofnewyork.us/Housing-Development/DOB-Certificate-Of-Occupancy/bs8b-p36w/about_data
24+
25+
ingestion:
26+
source:
27+
type: socrata
28+
org: nyc
29+
uid: bs8b-p36w
30+
format: csv
31+
file_format:
32+
type: csv
33+
processing_steps:
34+
- name: clean_column_names
35+
args: { "lower": True }

ingest_templates/dob_now_cofos.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
id: dob_now_cofos
2+
acl: public-read
3+
4+
attributes:
5+
name: DOB NOW Certificate Of Occupancy
6+
description: >-
7+
This data set includes certificates of occupancy issued through the New York City
8+
Department of Buildings' DOB NOW: Certificate of Occupancy module. This module was
9+
released in March of 2021, anbd from that point onward this data set should be
10+
utilized instead of the "DOB Certificate of Occupancy" data set. The data is
11+
collected because the Department of Buildings tracks Certificates of Occupancies
12+
issued. This data include items such as job filing name, job filing label, BIN,
13+
Address, and Certificate of Occupancy status, sequence, label, and issuance date.
14+
15+
"A Certificate of Occupancy (CO) states a legal use and/or type of permitted
16+
occupancy of a building. New buildings must have a CO, and existing buildings must
17+
have a current or amended CO when there is a change in use, egress or type of
18+
occupancy. No one may legally occupy a building until the Department has issued a CO
19+
or Temporary Certificate of Occupancy (TCO).
20+
21+
A CO confirms that the completed work complies with all applicable laws, all
22+
paperwork has been completed, all fees owed to the Department have been paid, all
23+
relevant violations have been resolved, and all necessary approvals have been
24+
received from other City Agencies. The Department issues a final CO when the
25+
completed work matches the submitted plans for new buildings or major alterations."
26+
url: https://data.cityofnewyork.us/Housing-Development/DOB-NOW-Certificate-of-Occupancy/pkdm-hqz6/about_data
27+
28+
ingestion:
29+
source:
30+
type: socrata
31+
org: nyc
32+
uid: pkdm-hqz6
33+
format: csv
34+
file_format:
35+
type: csv
36+
processing_steps:
37+
- name: clean_column_names
38+
args: { "lower": True }

products/developments/sql/_co.sql

Lines changed: 22 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -28,62 +28,30 @@ IN PREVIOUS VERSION:
2828
co_.sql
2929
*/
3030
DROP TABLE IF EXISTS co_devdb;
31-
WITH
32-
order_certtype AS (
33-
SELECT
34-
*,
35-
CASE
36-
WHEN certificatetype = 'T- TCO' THEN 2
37-
WHEN certificatetype = 'C- CO' THEN 1
38-
END AS certorder
31+
CREATE TABLE co_devdb AS
32+
WITH latest_co AS (
33+
SELECT DISTINCT ON (jobnum)
34+
jobnum,
35+
numofdwellingunits::numeric,
36+
effectivedate::date,
37+
certificatetype
3938
FROM dob_cofos
39+
WHERE jobnum IN (SELECT job_number FROM init_devdb)
40+
ORDER BY
41+
jobnum ASC, effectivedate::date DESC, certificatetype ASC
4042
),
41-
order_co AS (
42-
SELECT
43-
jobnum AS job_number,
44-
effectivedate::date AS effectivedate,
45-
numofdwellingunits::numeric AS units,
46-
certificatetype AS certtype,
47-
row_number() OVER (
48-
PARTITION BY jobnum
49-
ORDER BY effectivedate::date DESC, certorder ASC
50-
) AS latest,
51-
row_number() OVER (
52-
PARTITION BY jobnum
53-
ORDER BY effectivedate::date ASC
54-
) AS earliest
55-
FROM order_certtype
56-
WHERE jobnum IN (
57-
SELECT DISTINCT job_number
58-
FROM init_devdb
59-
)
60-
),
61-
draft_co AS (
43+
earliest_co AS (
6244
SELECT
63-
a.*,
64-
b._date_complete
65-
FROM (
66-
SELECT
67-
job_number,
68-
effectivedate AS co_latest_effectivedate,
69-
units AS co_latest_units,
70-
certtype AS co_latest_certtype
71-
FROM order_co
72-
WHERE latest = 1
73-
) AS a
74-
LEFT JOIN (
75-
SELECT
76-
job_number,
77-
effectivedate AS _date_complete
78-
FROM order_co
79-
WHERE earliest = 1
80-
) AS b ON a.job_number = b.job_number
45+
jobnum,
46+
min(effectivedate::date) AS _date_complete
47+
FROM dob_cofos
48+
GROUP BY jobnum
8149
)
8250
SELECT
83-
job_number,
84-
_date_complete,
85-
co_latest_effectivedate,
86-
co_latest_units,
87-
co_latest_certtype
88-
INTO co_devdb
89-
FROM draft_co;
51+
latest_co.jobnum AS job_number,
52+
earliest_co._date_complete,
53+
latest_co.effectivedate AS co_latest_effectivedate,
54+
latest_co.numofdwellingunits AS co_latest_units,
55+
latest_co.certificatetype AS co_latest_certtype
56+
FROM latest_co
57+
INNER JOIN earliest_co ON latest_co.jobnum = earliest_co.jobnum;

0 commit comments

Comments
 (0)