Skip to content

Commit

Permalink
Add 2020 rent stab unit counts to the Tenant Platform (#2201)
Browse files Browse the repository at this point in the history
This PR swaps in 2020 rent stabilized unit counts to three queries within the tenant platform that make use of rs units:

the "DDO" sql query that generates building-level statistics for Data Driven Onboardin
the sql query that gets triggered in the rent history tool to detect a history of any rs units going back to 2007
the sql query that gets called in the housingtype API call
  • Loading branch information
sraby authored Sep 20, 2021
1 parent f5d2147 commit 8d4f69d
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
10 changes: 5 additions & 5 deletions data_driven_onboarding/data-driven-onboarding.sql
Original file line number Diff line number Diff line change
Expand Up @@ -208,19 +208,19 @@ select
-- will not return null, will return 0
coalesce(R.unitsstab2007,0) as stabilized_unit_count_2007,

-- number of stabilized units at entered bbl in 2019
-- number of stabilized units at entered bbl in 2020
-- drawn from rentstab_v2
-- will not return null, will return 0
coalesce(R2.uc2019,0) as stabilized_unit_count,
coalesce(R2.uc2020,0) as stabilized_unit_count,

-- year that latest rent stabilized unit count comes from
-- hard-coded in to the SQL query itself
2019 as stabilized_unit_count_year,
2020 as stabilized_unit_count_year,

-- maximum number of stabilized units at entered bbl on any year between 2007 and 2019
-- maximum number of stabilized units at entered bbl on any year between 2007 and 2020
-- false if there have been no stabilized units at any point
-- will not return null, will return 0
greatest(R.unitstotal, R2.uc2018, R2.uc2019, 0) as stabilized_unit_count_maximum,
greatest(R.unitstotal, R2.uc2018, R2.uc2020, 0) as stabilized_unit_count_maximum,

-- average wait time for repairs after a landlord has been notified of a violation. for the entered bbl
-- may return null if unknown
Expand Down
2 changes: 1 addition & 1 deletion nycx/address_housingtype.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
SELECT
CASE
WHEN N.DEVELOPMENT IS NOT NULL THEN 'NYCHA'
WHEN R.UC2019 > 0 THEN 'RENT_STABILIZED'
WHEN R.UC2020 > 0 THEN 'RENT_STABILIZED'
WHEN P.UNITSRES > 0 THEN 'MARKET_RATE'
ELSE NULL
END AS HOUSINGTYPE
Expand Down
2 changes: 1 addition & 1 deletion rh/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def get_slack_notify_text(rhr: models.RentalHistoryRequest) -> str:
def run_rent_stab_sql_query(bbl: str) -> Optional[Dict[str, Any]]:
sql_query = """
select uc2007, uc2008, uc2009, uc2010, uc2011, uc2012, uc2013,
uc2014, uc2015, uc2016, uc2017, uc2018, uc2019
uc2014, uc2015, uc2016, uc2017, uc2018, uc2019, uc2020
from rentstab
full join rentstab_v2 using(ucbbl)
where ucbbl = %(bbl)s
Expand Down
2 changes: 1 addition & 1 deletion rh/tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def test_rh_form_grabs_rent_stab_info(db, graphql_client, monkeypatch, mock_geoc
ob = _exec_rh_form(graphql_client)
assert ob["errors"] == []
assert ob["session"]["rentStabInfo"] == {
"latestYear": "2019",
"latestYear": "2020",
"latestUnitCount": 12,
}

Expand Down
5 changes: 4 additions & 1 deletion rh/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"uc2017": 12,
"uc2018": 12,
"uc2019": 12,
"uc2020": 12,
}

# Data for 69 Montrose Avenue, had rent stab units in 2008 but not after
Expand All @@ -32,6 +33,7 @@
"uc2017": None,
"uc2018": None,
"uc2019": None,
"uc2020": None,
}

# Data for 93 Knickerbocker Ave, has record in rent stab data but lists 0 units each year
Expand All @@ -49,12 +51,13 @@
"uc2017": None,
"uc2018": None,
"uc2019": None,
"uc2020": None,
}


def test_process_rent_stab_data_works_when_data_is_given():
assert process_rent_stab_data(EXAMPLE_RENT_STAB_DATA) == {
"latest_year": "2019",
"latest_year": "2020",
"latest_unit_count": 12,
}
assert process_rent_stab_data(EXAMPLE_OLD_RENT_STAB_DATA) == {
Expand Down

0 comments on commit 8d4f69d

Please sign in to comment.