#!/usr/bin/env python3 """Rebuild the AutoWarranty.Autos Repair Bill Lab CSV with Python 3.8+. Download the hourly-rate CSV in a browser from https://autowarranty.autos/research/repair-labor-cost-gap/data, then run python reproduce.py --source autowarranty-repair-labor-cost-gap.csv Or run python reproduce.py to fetch the published source. Use --output FILE to choose another destination. The default is metro-scenarios.csv in the current directory. If the website changes or is unavailable, run with --snapshot to use the four source columns retained here. All three options reproduce the November 26, 2026 release with no third-party dependencies. Each row models one visit with $600 of parts fully approved, no tax or fees, one $100 deductible, and no payout ceiling. The selected 50 independent-shop rate midpoints are modeled values. Hours and allowances are experiment inputs, not manufacturer labor times, regional shop quotes or terms of named plans. """ import argparse import csv import hashlib import io from decimal import Decimal from pathlib import Path from urllib.request import urlopen SOURCE = "https://autowarranty.autos/research/repair-labor-cost-gap/data" # Published metro identifiers and rates, sorted by slug. SOURCE_SNAPSHOT = """metro,state,slug,modeled_independent_hourly_mid_usd Atlanta,GA,atlanta-ga,153.51 Austin,TX,austin-tx,148.45 Baltimore,MD,baltimore-md,149.31 Birmingham,AL,birmingham-al,142.65 Boston,MA,boston-ma,169.58 Buffalo,NY,buffalo-ny,136.73 Charlotte,NC,charlotte-nc,149.90 Chicago,IL,chicago-il,153.35 Cincinnati,OH,cincinnati-oh,144.37 Cleveland,OH,cleveland-oh,148.99 Columbus,OH,columbus-oh,130.23 Dallas,TX,dallas-tx,144.15 Denver,CO,denver-co,169.05 Detroit,MI,detroit-mi,152.11 Grand Rapids,MI,grand-rapids-mi,145.82 Houston,TX,houston-tx,141.89 Indianapolis,IN,indianapolis-in,141.95 Jacksonville,FL,jacksonville-fl,141.95 Kansas City,MO,kansas-city-mo,147.75 Las Vegas,NV,las-vegas-nv,143.45 Los Angeles,CA,los-angeles-ca,164.58 Louisville,KY,louisville-ky,133.99 Memphis,TN,memphis-tn,141.95 Miami,FL,miami-fl,144.37 Milwaukee,WI,milwaukee-wi,160.55 Minneapolis,MN,minneapolis-mn,162.65 Nashville,TN,nashville-tn,149.64 New Orleans,LA,new-orleans-la,139.80 New York,NY,new-york-ny,159.80 Norfolk,VA,norfolk-va,154.64 Oklahoma City,OK,oklahoma-city-ok,142.27 Orlando,FL,orlando-fl,138.56 Philadelphia,PA,philadelphia-pa,151.52 Phoenix,AZ,phoenix-az,148.18 Pittsburgh,PA,pittsburgh-pa,136.78 Portland,OR,portland-or,171.41 Providence,RI,providence-ri,141.84 Raleigh,NC,raleigh-nc,145.06 Richmond,VA,richmond-va,136.89 Rochester,NY,rochester-ny,149.58 Sacramento,CA,sacramento-ca,176.73 Salt Lake City,UT,salt-lake-city-ut,136.68 San Antonio,TX,san-antonio-tx,134.58 San Diego,CA,san-diego-ca,165.77 San Francisco,CA,san-francisco-ca,195.77 Seattle,WA,seattle-wa,166.63 St. Louis,MO,st-louis-mo,147.48 Tampa,FL,tampa-fl,138.88 Tucson,AZ,tucson-az,135.17 Washington,DC,washington-dc,171.89 """ EXPECTED_CSV_SHA256 = "cda288ec5e2d012efcf33fc53b9a1996eb874a3ba9e2608b28ebd65f82f25216" PARTS = 60000 DEDUCTIBLE = 10000 FIELDS = [ "metro", "state", "metro_slug", "shop_rate_usd_per_hour", "shop_hours", "approved_hours", "allowance_usd_per_hour", "applied_rate_usd_per_hour", "approved_parts_usd", "shop_labor_usd", "approved_labor_usd", "shop_total_usd", "rate_gap_usd", "hours_gap_usd", "deductible_usd", "modeled_contract_payment_usd", "modeled_driver_share_usd", ] def money(cents): return f"{cents // 100}.{cents % 100:02d}" def metro_rates(source_bytes): rates = {} for row in csv.DictReader(io.StringIO(source_bytes.decode("utf-8-sig"))): slug = row["slug"] amount = Decimal(row["modeled_independent_hourly_mid_usd"]) * 100 if not amount.is_finite() or amount != amount.to_integral_value() or amount <= 0: raise ValueError(f"Expected a positive hourly rate in whole cents for {slug}") if not slug or slug in rates: raise ValueError(f"Missing or duplicate metro slug: {slug}") rates[slug] = (row["metro"], row["state"], int(amount)) if len(rates) != 50: raise ValueError(f"Expected the 50-metro release, received {len(rates)} rows") return rates def scenarios(rates): for slug, (metro, state, rate) in sorted(rates.items()): for shop_hours in (4, 8, 12): for hours_removed in (0, 1, 2): approved_hours = shop_hours - hours_removed for allowance in (12500, 15000, 17500): applied = min(rate, allowance) shop_labor = shop_hours * rate approved_labor = approved_hours * applied shop_total = PARTS + shop_labor rate_gap = shop_hours * (rate - applied) hours_gap = hours_removed * applied payment = max(0, PARTS + approved_labor - DEDUCTIBLE) driver = shop_total - payment yield [metro, state, slug, money(rate), shop_hours, approved_hours, money(allowance), money(applied), money(PARTS), money(shop_labor), money(approved_labor), money(shop_total), money(rate_gap), money(hours_gap), money(DEDUCTIBLE), money(payment), money(driver)] def main(): parser = argparse.ArgumentParser(description=__doc__) source = parser.add_mutually_exclusive_group() source.add_argument("--source", type=Path, help="Saved hourly-rate source CSV") source.add_argument("--snapshot", action="store_true", help="Use the frozen source columns offline") parser.add_argument("--output", type=Path, default=Path("metro-scenarios.csv")) args = parser.parse_args() if args.snapshot: data = SOURCE_SNAPSHOT.encode("utf-8") elif args.source: data = args.source.read_bytes() else: with urlopen(SOURCE, timeout=30) as response: data = response.read() rates = metro_rates(data) if rates != metro_rates(SOURCE_SNAPSHOT.encode("utf-8")): raise ValueError("Source inputs differ from the November 2026 edition; use --snapshot to reproduce it.") with args.output.open("w", encoding="utf-8", newline="") as handle: writer = csv.writer(handle, lineterminator="\n") writer.writerow(FIELDS) writer.writerows(scenarios(rates)) print("Source SHA-256:", hashlib.sha256(data).hexdigest()) checksum = hashlib.sha256(args.output.read_bytes()).hexdigest() if checksum != EXPECTED_CSV_SHA256: raise ValueError("Output did not match the published November 2026 release") print("Output SHA-256:", checksum) if __name__ == "__main__": main()