"""Builds the seattle-dogs-vs-children tables from source_values.json plus figures typed in from published reports (listed in REPORTED below). Run: python3 build.py -> writes comparison.csv, timeline.csv, results.json""" import csv, json src = json.load(open("source_values.json"))["values"] acs = {y: src[f"ACSDP1Y{y}.DP05"] for y in (2017, 2022, 2025)} hh = int(src["ACSDP1Y2025.DP02"]["DP02_0001E"]) hh_moe = int(src["ACSDP1Y2025.DP02"]["DP02_0001M"]) dp1 = src["DECENNIALDP2020.DP1"] kids2020 = int(dp1["DP1_0001C"]) - int(dp1["DP1_0021C"]) lic = {r["species"]: int(r["count"]) for r in src["seattle-pet-licenses-count"]["result"]} # Figures typed in from reports (no machine-readable copy). REPORTED = { "shelter": [ # Seattle Animal Shelter estimates of all dogs, as reported (2006, 125000, "about", "st-2006"), (2017, 150000, "", "spr-2017"), (2022, 187000, "", "st-2022"), (2025, 180000, "more than", "st-2025"), ], "licensed": [ # licensed dogs as reported, plus our own count (2022, 30500, "about", "st-2022"), (2025, 30000, "around", "st-2025"), ], } AVMA_SHARE, AVMA_PER_HH = 0.437, 1.5 # AVMA 2026, dogs kids2025 = int(acs[2025]["DP05_0019E"]); kids2025_moe = int(acs[2025]["DP05_0019M"]) avma_dogs = hh * AVMA_SHARE * AVMA_PER_HH avma_low = (hh - hh_moe) * AVMA_SHARE * AVMA_PER_HH avma_high = (hh + hh_moe) * AVMA_SHARE * AVMA_PER_HH third_dogs = hh / 3 * AVMA_PER_HH tie_households = kids2025 / AVMA_PER_HH tie_share = tie_households / hh comparison = [ dict(label="Children under 18", kind="Children (Census Bureau)", count=kids2025, moe=kids2025_moe, low=kids2025 - kids2025_moe, high=kids2025 + kids2025_moe, period="2025", value_type="estimated", qualifier="", basis="Census Bureau survey estimate, 90% margin of error", source_ids="acs-dp05-2025"), dict(label="Licensed dogs", kind="Dogs counted (city licenses)", count=lic["Dog"], moe="", low="", high="", period="2026-10", value_type="observed", qualifier="", basis="Count of active dog licenses on the city's list", source_ids="seattle-pet-licenses"), dict(label="All dogs: shelter estimate", kind="Dogs estimated", count=180000, moe="", low="", high="", period="2025", value_type="estimated", qualifier="more than", basis="Seattle Animal Shelter estimate, method not published; plotted at its stated floor", source_ids="st-2025"), dict(label="All dogs: U.S. pet survey rate", kind="Dogs estimated", count=int(round(avma_dogs, -4)), moe="", low=round(avma_low), high=round(avma_high), period="2025-2026", value_type="estimated", qualifier="about", basis="381,340 households x 43.7% owning dogs x 1.5 dogs each, rounded to the nearest 10,000", source_ids="acs-dp02-2025;avma-2026"), ] timeline = [] for y in (2017, 2022, 2025): v = int(acs[y]["DP05_0019E"]); m = int(acs[y]["DP05_0019M"]) timeline.append(dict(year=y, series="Children under 18", count=v, moe=m, qualifier="", value_type="estimated", basis="Census Bureau yearly survey (ACS 1-year)", source_ids=f"acs-dp05-{y}")) timeline.append(dict(year=2020, series="Children under 18", count=kids2020, moe="", qualifier="", value_type="observed", basis="2020 census count", source_ids="census-dp1-2020")) for y, v, q, s in REPORTED["shelter"]: timeline.append(dict(year=y, series="All dogs (shelter estimate)", count=v, moe="", qualifier=q, value_type="estimated", basis="Seattle Animal Shelter estimate as reported", source_ids=s)) for y, v, q, s in REPORTED["licensed"]: timeline.append(dict(year=y, series="Licensed dogs", count=v, moe="", qualifier=q, value_type="observed", basis="License total as rounded in the report", source_ids=s)) timeline.append(dict(year=2026, series="Licensed dogs", count=lic["Dog"], moe="", qualifier="", value_type="observed", basis="Our count of active dog licenses, list as of Oct. 6, 2026", source_ids="seattle-pet-licenses")) order = {"Children under 18": 0, "All dogs (shelter estimate)": 1, "Licensed dogs": 2} timeline.sort(key=lambda r: (order[r["series"]], r["year"])) def write(name, rows): with open(name, "w", newline="") as f: w = csv.DictWriter(f, fieldnames=list(rows[0].keys()), lineterminator="\n") w.writeheader(); w.writerows(rows) write("comparison.csv", comparison) write("timeline.csv", timeline) results = dict(avma_dogs=avma_dogs, avma_low=avma_low, avma_high=avma_high, third_dogs=third_dogs, tie_households=tie_households, tie_share=tie_share, kids2020=kids2020, licensed_share_of_shelter=lic["Dog"] / 180000, licensed_cats=lic["Cat"]) json.dump(results, open("results.json", "w"), indent=1) print(json.dumps(results, indent=1))