from pathlib import Path
from collections import Counter
import json,sys
ROOT=Path(__file__).resolve().parents[1];sys.path.insert(0,str(Path(__file__).parent));from analyze import csvout,dump
rows=[]
for p in sorted((ROOT/'visuals/data').glob('*.js')):
 if p.stem=='index':continue
 s=p.read_text();r=json.loads(s[len('FLOW.register('):-3]);es=r['events'];cc=Counter('MISSING' if not e.get('source_image') else 'same_GUI_evidence' if e['source_image'].get('same_GUI') else 'historical_representative_unverified' for e in es)
 rows.append(dict(run=r['summary']['run'],executions=len(es),same_GUI_source=cc['same_GUI_evidence'],representative_source=cc['historical_representative_unverified'],missing_source=cc['MISSING'],meaning='image availability, not executable Concrete inventory'))
csvout('analysis/gui-availability.csv',rows);dump('analysis/gui-availability.json',rows);print(rows)
