"""Reproduce the counts in Aridalia's DBPR snapshot guide. Requires Python 3 and pandas. Run from the extracted download folder: python analyze_mold_snapshots.py Or supply one or more local CSV paths as arguments. The script reads files and prints aggregate results; it does not modify CSVs. """ from pathlib import Path import hashlib import json import sys import pandas as pd COLUMNS = [ "board", "type", "name", "dba", "class_code", "address_1", "address_2", "address_3", "city", "state", "zip", "county", "license_number", "primary_status", "secondary_status", "original_date", "effective_date", "expiration_date", "reserved", "renewal_period", "alternate_number", "ce_exemption", ] def read_snapshot(path): frame = pd.read_csv(path, header=None, dtype=str, encoding="latin-1", keep_default_na=False) if frame.shape[1] != 22: raise ValueError(f"Expected 22 columns, got {frame.shape[1]}: {path}") frame.columns = COLUMNS for column in ["type", "license_number", "primary_status", "secondary_status"]: frame[column] = frame[column].str.strip() active = frame.loc[ frame["type"].isin(["MRSA", "MRSR"]) & frame["primary_status"].eq("C") & frame["secondary_status"].eq("A") ].copy() keys = ["type", "license_number"] if active.duplicated(keys).any(): raise ValueError(f"Duplicate type + license_number in {path}") return frame, active.set_index(keys) def main(): root = Path(__file__).resolve().parent paths = [Path(p) for p in sys.argv[1:]] or [ root / f"lic07mold-{date}.csv" for date in ["2026-08-04", "2026-10-26", "2026-11-01"] ] results = [] active_frames = [] for path in paths: frame, active = read_snapshot(path) active_frames.append(active) results.append({ "file": path.name, "sha256": hashlib.sha256(path.read_bytes()).hexdigest(), "raw_rows": len(frame), "type_counts": frame["type"].value_counts().sort_index().to_dict(), "current_active_licenses": len(active), "active_by_type": active.groupby(level="type").size().to_dict(), }) output = {"snapshots": results} if len(active_frames) >= 2: before, after = active_frames[:2] entered = after.loc[~after.index.isin(before.index)] left = before.loc[~before.index.isin(after.index)] dates = pd.to_datetime(entered["original_date"].str.strip(), format="%m/%d/%Y", errors="raise") output["first_to_second"] = { "entered_active_selection": len(entered), "left_active_selection": len(left), "net_change": len(after) - len(before), "percent_change": round((len(after) / len(before) - 1) * 100, 1), "entered_original_year_counts": dates.dt.year.value_counts().sort_index().to_dict(), } print(json.dumps(output, indent=2)) if __name__ == "__main__": main()