File size: 13,011 Bytes
719cc9b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | """
City registry for the local agent.
Each entry encodes everything the 311 + permits tools need to query
the city's Socrata-hosted open data: dataset IDs, the field names
used for category/cost/date/location, the actual flood-related
category values, and a short context blurb that gets injected into
the local-agent prompt so Gemma 4 has accurate sewer-system info
when it interprets the signals.
All entries verified live on 2026-05-04 against the cities' open-data
portals. The honesty-tax: most cities don't expose project cost in
their permits dataset, and not every city categorizes 311 floods
explicitly. Each config field documents what's actually available
so the dossier can degrade gracefully (e.g. show permit COUNT but
suppress the dollar narrative when no cost field exists).
"""
from typing import Optional
# Standardize state matching: accept full name OR 2-letter code.
def _state_match(input_state: str, codes: tuple[str, ...]) -> bool:
s = (input_state or "").strip().lower()
return any(s == c.lower() for c in codes)
CITIES: list[dict] = [
# ---- CHICAGO --------------------------------------------------------
{
"id": "chicago",
"name": "Chicago",
"state_codes": ("IL", "Illinois"),
"match_fn": lambda city, state: "chicago" in (city or "").lower() and _state_match(state, ("IL", "Illinois")),
"context_blurb": (
"Chicago has a combined sewer system covering ~80% of the city. "
"Combined sewer overflows after ~0.67 in/hr of rain. 42% of Cook "
"County is impervious surface. MWRD's Deep Tunnel (TARP) provides "
"buffering but local sewers still bottleneck at neighborhood scale."
),
"311": {
"url": "https://data.cityofchicago.org/resource/v6vf-nfxy.json",
"category_field": "sr_short_code",
# Chicago uses short codes: WIB = Water in Basement, SFL = Street Flooding
"flood_categories": ("WIB", "SFL"),
"category_in_clause": "sr_short_code in('WIB','SFL')",
"date_field": "created_date",
"location_field": "location",
"select_fields": "sr_short_code,created_date,street_address,ward",
"address_field_template": "street_address",
},
"permits": {
"url": "https://data.cityofchicago.org/resource/ydr8-5enu.json",
"permit_type_field": "permit_type",
"permit_type_values": (
"PERMIT - NEW CONSTRUCTION",
"PERMIT - RENOVATION/ALTERATION",
),
"cost_field": "reported_cost",
"date_field": "issue_date",
"location_field": "location",
"select_fields": (
"permit_type,work_description,reported_cost,issue_date,"
"latitude,longitude,street_number,street_direction,"
"street_name,total_fee"
),
"address_keys": ("street_number", "street_direction", "street_name"),
"new_construction_marker": "NEW CONSTRUCTION",
"renovation_marker": "RENOVATION",
"has_cost": True,
},
},
# ---- NEW YORK CITY --------------------------------------------------
{
"id": "nyc",
"name": "New York City",
"state_codes": ("NY", "New York"),
"match_fn": lambda city, state: any(t in (city or "").lower() for t in ("new york", "manhattan", "brooklyn", "queens", "bronx", "staten island")) and _state_match(state, ("NY", "New York")),
"context_blurb": (
"NYC has combined sewer systems across 60% of the city β including "
"all of Manhattan, much of Brooklyn, and parts of Queens and the "
"Bronx. Storm intensity above ~1.5 in/hr triggers combined-sewer "
"overflows into NY Harbor and basement backups. NYC DEP's bluebelts "
"and grey infrastructure are unevenly distributed."
),
"311": {
"url": "https://data.cityofnewyork.us/resource/erm2-nwe9.json",
"category_field": "complaint_type",
# NYC complaint_type values verified 2026-05 (top flood-related)
"flood_categories": ("Sewer", "Sewer Maintenance"),
"category_in_clause": "complaint_type in('Sewer','Sewer Maintenance')",
"date_field": "created_date",
"location_field": "location",
# NYC uses lat/lon directly:
"select_fields": "complaint_type,descriptor,created_date,incident_address,borough",
"address_field_template": "incident_address",
},
# NYC permits intentionally DEFERRED. The DOB datasets are fragmented:
# ipu4-2q9a (legacy "DOB Permit Issuance") β most recent NB rows
# are from 2022; the dataset stopped being updated regularly.
# rbx6-tga4 (DOB NOW: Build β Approved Permits) β has cost
# (estimated_job_costs) and lat/lon, but NO date column
# suitable for "last 3 years" filtering.
# w9ak-ipjd (Active Construction Permits) β has filing_date and
# initial_cost in the right format, but is filtered to currently-
# active permits, so the historical 3-year window is empty for
# most areas.
# The right fix is a custom NYC client that joins multiple datasets;
# for the hackathon scope NYC ships with 311-only and the dossier
# honestly says permits-deferred.
"permits": None,
},
# ---- SAN FRANCISCO --------------------------------------------------
{
"id": "sf",
"name": "San Francisco",
"state_codes": ("CA", "California"),
"match_fn": lambda city, state: "san francisco" in (city or "").lower() and _state_match(state, ("CA", "California")),
"context_blurb": (
"San Francisco operates a fully combined sewer system citywide β "
"the only major California city to do so. Heavy rain plus high "
"tide concentrates overflows. SF Public Utilities Commission has "
"documented chronic flooding hotspots in Mission, Bayview, and "
"the South of Market areas."
),
"311": {
"url": "https://data.sfgov.org/resource/vw6y-z8j6.json",
"category_field": "service_name",
"flood_categories": ("Sewer Issues", "Sewer"),
"category_in_clause": "service_name in('Sewer Issues','Sewer')",
"date_field": "requested_datetime",
"location_field": "point",
"select_fields": "service_name,service_subtype,requested_datetime,address",
"address_field_template": "address",
},
"permits": {
"url": "https://data.sfgov.org/resource/i98e-djp9.json",
"permit_type_field": "permit_type_definition",
"permit_type_values": (
"new construction",
"new construction wood frame",
"additions alterations or repairs",
),
"cost_field": "estimated_cost",
"cost_is_string": True, # SF stores estimated_cost as text
"date_field": "issued_date",
"location_field": "location", # SF permits has a real Socrata Point column
"select_fields": (
"permit_type,permit_type_definition,description,estimated_cost,"
"revised_cost,issued_date,filed_date,street_number,street_name,"
"street_suffix,zipcode"
),
"address_keys": ("street_number", "street_name", "street_suffix"),
"new_construction_marker": "new construction",
"renovation_marker": "alterations",
"has_cost": True,
},
},
# ---- LOS ANGELES ----------------------------------------------------
{
"id": "la",
"name": "Los Angeles",
"state_codes": ("CA", "California"),
"match_fn": lambda city, state: any(t in (city or "").lower() for t in ("los angeles", "los-angeles")) and _state_match(state, ("CA", "California")),
"context_blurb": (
"Los Angeles has a separated storm-sanitary sewer system β the "
"two pipe networks don't co-mingle, so basement sewer-backup "
"flooding is rare. The dominant LA flood mode is FLASH FLOODING "
"during winter atmospheric-river events, when concrete-channelized "
"rivers (LA River, Ballona Creek) and soft-bottomed creeks rise "
"rapidly. Hillside debris flows after wildfire are a separate "
"wet-season hazard."
),
"311": None, # LA's 311 dataset doesn't categorize floods cleanly enough; deferred
"permits": {
"url": "https://data.lacity.org/resource/pi9x-tg5x.json",
"permit_type_field": "permit_type",
"permit_type_values": ("Bldg-New", "Bldg-Alter/Repair", "Bldg-Addition"),
"cost_field": "valuation",
"cost_is_string": True, # LA stores valuation as text
"date_field": "issue_date",
"location_field": None,
"select_fields": (
"permit_type,permit_sub_type,work_desc,valuation,issue_date,"
"primary_address,zip_code,lat,lon"
),
"address_keys": ("primary_address",),
"new_construction_marker": "New",
"renovation_marker": "Alter",
"has_cost": True,
"lat_field": "lat",
"lon_field": "lon",
"lat_lon_is_string": True, # LA stores lat/lon as text β need cast
},
},
# ---- AUSTIN ---------------------------------------------------------
{
"id": "austin",
"name": "Austin",
"state_codes": ("TX", "Texas"),
"match_fn": lambda city, state: "austin" in (city or "").lower() and _state_match(state, ("TX", "Texas")),
"context_blurb": (
"Austin has separated storm and sanitary sewers, but the storm "
"drain system is undersized for the increasingly extreme rainfall "
"events of the post-2010 Texas climate. Onion Creek and Williamson "
"Creek have historic flash-flood corridors. Austin's hilly topo "
"concentrates runoff into well-known low-point intersections β the "
"city publishes a 'Flood Early Warning System' map for these spots."
),
"311": {
"url": "https://data.austintexas.gov/resource/xwdj-i9he.json",
"category_field": "sr_type_desc",
"flood_categories": (
"Flooding Current (Non-Emergency)",
"Flooding - Past",
"WPD - Flooding Current",
"WPD - Flooding Past",
"WPD - Channels/Creek/Drainage Issues",
"WPD - Storm Drain Services",
),
"category_in_clause": (
"sr_type_desc in("
"'Flooding Current (Non-Emergency)',"
"'Flooding - Past',"
"'WPD - Flooding Current',"
"'WPD - Flooding Past',"
"'WPD - Channels/Creek/Drainage Issues',"
"'WPD - Storm Drain Services'"
")"
),
"date_field": "sr_created_date",
"location_field": "sr_location_lat_long", # real Point column
"select_fields": "sr_type_desc,sr_created_date,sr_location",
"address_field_template": "sr_location",
},
"permits": {
"url": "https://data.austintexas.gov/resource/3syk-w9eu.json",
"permit_type_field": "permittype",
# Austin permittype: BP=building, MP=mechanical, etc. We want the
# construction-relevant ones via permit_class_mapped + work_class.
"permit_type_values": ("BP",),
"cost_field": None, # Austin permits dataset has no cost field
"date_field": "issue_date",
"location_field": "location",
"select_fields": (
"permittype,permit_type_desc,permit_class_mapped,work_class,"
"description,issue_date,permit_location,latitude,longitude,"
"original_address1,original_zip"
),
"address_keys": ("original_address1",),
"new_construction_marker": "New",
"renovation_marker": "Remodel",
"has_cost": False,
"lat_field": "latitude",
"lon_field": "longitude",
},
},
]
def find_city(city: str, state: str) -> Optional[dict]:
"""Look up a registry entry for the given geocoded city/state, or None."""
for entry in CITIES:
try:
if entry["match_fn"](city, state):
return entry
except Exception:
continue
return None
def supported_city_names() -> list[str]:
return [c["name"] for c in CITIES]
|