# Ten winters of NYC heat and hot water complaints

The analysis behind `/nyc-heat-complaints`. Python 3, standard library only.

```
python3 -I analysis/heat/fetch.py     # downloads about 460 MB into analysis/heat/raw/ (not committed)
python3 -I analysis/heat/analyze.py   # prints a report, writes analysis/heat/derived/results.json
python3 -I analysis/heat/charts.py    # writes guides-src/tools/heat-chart-*.html and the lookup's citywide figures
node build-guides.mjs
```

The data was pulled on November 16, 2026. `fetch.py` has that date as `END`; change it to re-run later, and expect the
numbers to move a little because HPD's file is updated daily.

## Sources and exact queries

All Socrata queries go to `https://data.cityofnewyork.us/resource/<id>.csv`.

**Complaints**: Housing Maintenance Code Complaints and Problems, `ygpa-z7cr`. One request per calendar month from
2016-10 through 2026-11:

```
$select=complaint_id,problem_id,received_date,bbl,building_id,borough,apartment,unit_type,space_type,problem_code,problem_duplicate_flag,complaint_anonymous_flag
$where=major_category='HEAT/HOT WATER' AND received_date>='2016-10-01' AND received_date<'2016-11-01'
$order=problem_id&$limit=1000000
```

**Lots**: PLUTO, `64uk-42ks`, every lot with a residential unit, paged 50,000 at a time:

```
$select=bbl,unitsres,unitstotal,yearbuilt,numfloors,numbldgs,bldgclass,ownername,landuse,borough
$where=unitsres>=1&$order=bbl
```

**HPD's building list**: Buildings Subject to HPD Jurisdiction, `kj4p-ruqc`, all rows.

**Weather**: NOAA NCEI daily summaries for Central Park:

```
https://www.ncei.noaa.gov/access/services/data/v1?dataset=daily-summaries&stations=USW00094728&startDate=2016-07-01&endDate=2026-11-16&dataTypes=TMIN,TMAX&units=standard&format=json
```

**The lookup on the page** runs this from the visitor's browser, then folds months into winters:

```
$select=date_trunc_ym(received_date) as m,count(distinct complaint_id) as n
$where=(bbl='<bbl>' OR (borough='<BOROUGH>' AND block=<block> AND house_number='<number>' AND street_name='<STREET>'))
       AND major_category='HEAT/HOT WATER' AND received_date>='2016-10-01'
$group=m
```

The address clause is there because about 2% of complaints carry a lot number that PLUTO no longer uses.

## Definitions

- **Complaint**: a distinct `complaint_id` with at least one problem row whose `major_category` is `HEAT/HOT WATER`.
  The file has one row per problem; 2,470,814 rows collapse to 2,445,429 complaints.
- **Winter**: October 1 through May 31, the legal heat season, keyed by the year it starts. "Last winter" is
  October 1, 2025 through May 31, 2026. June through September complaints are dropped.
- **Building**: the tax lot (`bbl`). Complaints with a missing or malformed `bbl` count in citywide totals only.
- **Apartments in a building**: PLUTO `unitsres`.
- **The list of buildings**: PLUTO lots with `unitsres >= 3`, excluding lots whose `ownername` contains
  "HOUSING AUTHORITY" (171,942 lots). Condos are lots with a building class starting `R`; co-ops are classes
  `C6`, `C8`, `D0`, `D4`.
- **Distinct apartments**: the `apartment` field upper-cased, stripped of punctuation, a leading APT/UNIT and
  leading zeros. `BLDG` and blanks name no apartment.
- **Heating degree days**: for each day, `max(0, 65 - (TMAX + TMIN) / 2)`, summed over the winter.
- **Cold day**: a day with a low under 45°F. The nth cold day is counted from October 1 of that season.
- **Gap days**: days from November through March with fewer than 60 complaints. There are six, all the last Sunday
  of a year or the day after, 2017 to 2021. They are dropped from per-day statistics and kept in winter totals.
- **Year-to-year figures**: for each pair of consecutive winters, lots in the building list are grouped by complaints
  in the first winter and tallied in the second. Unless noted, figures pool the four latest pairs (2021-22 to 2025-26).
- **Weather-only change**: mean complaints per day by 5°F band of the daily low, split into October-November and the
  rest, taken from winters 2022-23 to 2024-25, then applied to the daily lows of 2024-25 and 2025-26.

## Known problems with the data

- A complaint is a report to 311, not a measurement. One apartment filed 2,399 last winter.
- Public housing is absent. NYCHA tenants report to NYCHA.
- In September 2021 anonymous complaints stopped carrying apartment numbers and the building-wide share rose from
  about 50% to about 65%. Apartment counts use winters after the change only.
- Before 2014 the category was `HEATING`. The ten winters used here are all after the rename.
- About 2% of complaints do not match a PLUTO lot with residential units, and 0.3% have no usable `bbl`.
- A lot can hold several buildings. `building_id` would be finer, but unit counts and the address lookup are per lot.

## Files

- `fetch.py`, `load.py`, `analyze.py`, `charts.py`
- `derived/results.json`: every figure in the article, plus the points for the charts
- `raw/`: downloads, ignored by git
