import csv,json
from pathlib import Path
ROOT=Path(__file__).parent
weights={'procedure':25,'inputs':20,'review':20,'access':20,'value':15}
rows=[]
with (ROOT/'readiness-scenarios.csv').open(newline='') as f:
 for r in csv.DictReader(f):
  scores={k:int(r[k]) for k in weights}
  if any(not 0<=scores[k]<=weights[k] for k in weights):raise ValueError('Dimension out of range')
  total=sum(scores.values());missing=[k for k in ['access_authorized','reviewer_named','stop_path_defined','baseline_recorded'] if r[k]!='yes']
  decision='hold: unresolved gate' if missing else ('foundation first' if total<40 else 'redesign before pilot' if total<70 else 'bounded pilot candidate' if total<85 else 'controlled-scale candidate only after pilot evidence')
  rows.append({'scenario':r['scenario'],'total':total,'missing_gates':missing,'decision':decision})
result={'method':'Fixed Labs planning model, not empirical readiness validation','synthetic':True,'scenarios':rows}
(ROOT/'readiness-results.json').write_text(json.dumps(result,indent=2)+'\n')
print(json.dumps(result,indent=2))
