"""Count recorded labels in an exact selected directory, not live accounts or statewide adoption.

Usage: python3 reproduce-minnesota-platform-breadth-2026-v1.py minnesota-creators-2026.json
Standard library only. No network, writes, reclassification or new observations.
"""
from pathlib import Path
import hashlib,json,sys
SOURCE_SHA='668b4bfbe392047a59621c573dda9bb75f1b5025a003fd5c94986840fad49e88'
CORE=['Instagram','YouTube','Facebook','TikTok']
def derive(raw):
 if hashlib.sha256(raw).hexdigest()!=SOURCE_SHA:raise ValueError('Use the exact fixed reliability edition; no substituted or refreshed input.')
 data=json.loads(raw);records=data['records']
 if len(records)!=47 or len({r['entity_id']for r in records})!=47:raise ValueError('Unexpected selected cohort or duplicate identities')
 if any(r['entity_type']not in['Person','Organization']for r in records):raise ValueError('Unknown entity type')
 groups=[]
 for count in range(1,5):
  selected=[r for r in records if len(set(r['primary_platforms'])&set(CORE))==count]
  groups.append(dict(recorded_core_labels=count,people=sum(r['entity_type']=='Person'for r in selected),organizations=sum(r['entity_type']=='Organization'for r in selected),entities=len(selected),record_ids=sorted(r['entity_id']for r in selected)))
 if sum(g['entities']for g in groups)!=47:raise ValueError('Missing or zero-label rows require explicit treatment, not silent exclusion')
 allfour=[dict(entity_id=r['entity_id'],name=r['display_name'],entity_type=r['entity_type'],record_url='https://joshliljenquist.com/minnesota/creators/#record-'+r['entity_id'])for r in sorted(records,key=lambda r:r['display_name'].casefold())if set(CORE)<=set(r['primary_platforms'])]
 return dict(view_id='MN-PLATFORM-LABEL-BREADTH-2026-v1',source_sha256=SOURCE_SHA,source_edition='reference-2026-10-29-reliability',core_platform_labels=CORE,selected_entities=47,people=37,organizations=10,label_memberships=sum(g['recorded_core_labels']*g['entities']for g in groups),groups=groups,all_four_records=allfour,limits=['Counts stored metadata among four named networks, not every publishing channel.','Missing labels do not prove absent accounts; one label does not establish exclusive use.','No active-account, audience, strategy, growth or statewide-adoption inference.','People and organizations are distinct; an organization counts once.','Individual evidence dates and historical observations stay unchanged.'])
if __name__=='__main__':
 if len(sys.argv)!=2:raise SystemExit(__doc__)
 try:print(json.dumps(derive(Path(sys.argv[1]).read_bytes()),indent=2,ensure_ascii=False))
 except(ValueError,KeyError)as e:raise SystemExit(str(e))
