"""Reproduce the frozen public declaration counts. Python3, standard library only. Downloaded files: ep-animal-ingredient-analysis-20261024.py.txt and ep-animal-ingredient-panel-20261024.json.txt Usage: python3 ep-animal-ingredient-analysis-20261024.py.txt ep-animal-ingredient-panel-20261024.json.txt With no argument, the actual sibling downloadable dataset name is used. The downloadable .json.txt file has the same JSON content. """ import sys,json,hashlib,collections from pathlib import Path default=Path(__file__).resolve().parent/'ep-animal-ingredient-panel-20261024.json.txt' if not default.exists():default=Path(__file__).resolve().parents[1]/'data/ep-animal-ingredient-panel-20261024.json.txt' p=Path(sys.argv[1]) if len(sys.argv)>1 else default x=json.loads(p.read_text());rows=x['records'];ids=[r['product_id'] for r in rows] assert len(ids)==len(set(ids)), 'Duplicate native product identity in frozen one-formulation panel' counts=collections.Counter() for r in rows: assert hashlib.sha256(r['composition'].encode()).hexdigest()==r['composition_sha256'],f'Composition changed for {r["product_id"]}' terms=r['explicit_animal_terms'];assert terms,'No explicit animal terms, separate rule required' cls='all_explicit_animal_terms_source_named' if all(t['named_common_animal_source'] for t in terms) else 'includes_broad_or_unspecified_animal_term' assert cls==r['classification'],f'Classification mismatch for {r["product_id"]}' counts[cls]+=1 print(json.dumps({'formulations':len(rows),'brands':len(set(r['brand'] for r in rows)),'counts':dict(counts),'candidate_exclusions':len(x['exclusions'])},indent=2))