"""Six fictional workplace arithmetic examples; no real employee records or personnel decisions."""
import argparse,json
from decimal import Decimal
from pathlib import Path
D=Decimal
INPUTS={'employer-employee--operating-systems': {'total': 24, 'setup': 21, 'ready': 18}, 'employer-employee--databases': {'staff': 20, 'assignments': 32}, 'employer-employee--programming': {'total': 30, 'automatic': 18, 'review': 7, 'missing': 5}, 'employer-employee--networks': {'a_total': 20, 'a_met': 17, 'b_total': 20, 'b_met': 11}, 'employer-employee--cloud': {'total': 22, 'entitled': 18, 'opened': 15, 'completed': 12}, 'employer-employee--cybersecurity': {'total': 26, 'necessary': 17, 'excessive': 6, 'unresolved': 3}}
def percent(n,d):return None if d==0 else D(str(n))/D(str(d))*100
def calculate(id,x):
 if id not in INPUTS:raise ValueError('Unknown case')
 if set(x)!=set(INPUTS[id]):raise ValueError('Missing or unexpected fields')
 if any(type(v) is not int or v<0 for v in x.values()):raise ValueError('Use non-negative integer fixture values')
 p=lambda a,b:percent(x[a],x[b])
 def nested(*keys):
  if any(x[a]<x[b] for a,b in zip(keys,keys[1:])):raise ValueError('Inconsistent nested counts')
 def shares(total,*keys):
  if sum(x[k] for k in keys)!=x[total]:raise ValueError('Categories do not reconcile')
  return {k+'Percent':p(k,total) for k in keys}
 d=id.split('--')[1]
 if d=='operating-systems':
  nested('total','setup','ready');return dict(setupPercent=p('setup','total'),readyPercent=p('ready','total'),setupReadyPercent=p('ready','setup'),setupNotReady=x['setup']-x['ready'],missingSetup=x['total']-x['setup'])
 if d=='databases':
  nested('assignments','staff');extra=x['assignments']-x['staff'];return dict(extraRows=extra,inflationPercent=percent(extra,x['staff']),assignmentsPerStaff=None if x['staff']==0 else D(x['assignments'])/x['staff'])
 if d=='programming':return dict(**shares('total','automatic','review','missing'),completeAutomaticPercent=percent(x['automatic'],x['automatic']+x['review']))
 if d=='networks':
  nested('a_total','a_met');nested('b_total','b_met');a=p('a_met','a_total');b=p('b_met','b_total');return dict(aPercent=a,bPercent=b,pooledPercent=percent(x['a_met']+x['b_met'],x['a_total']+x['b_total']),pointGap=None if a is None or b is None else a-b)
 if d=='cloud':
  nested('total','entitled','opened','completed');return dict(entitlementPercent=p('entitled','total'),accessPercent=p('opened','total'),completionPercent=p('completed','total'),entitledCompletionPercent=p('completed','entitled'))
 if d=='cybersecurity':return dict(**shares('total','necessary','excessive','unresolved'),decidedPercent=percent(x['necessary']+x['excessive'],x['total']))
 raise ValueError('Unknown case')
def fixture_results():return {id:calculate(id,x) for id,x in INPUTS.items()}
def self_test():
 assert percent(0,0) is None
 assert len(fixture_results())==6
 return 'Bounded fixture checks passed; not independent expert validation.'
if __name__=='__main__':
 p=argparse.ArgumentParser(description=__doc__);p.add_argument('--case',default='all',choices=['all',*INPUTS]);p.add_argument('--input-file');p.add_argument('--self-test',action='store_true');a=p.parse_args()
 if a.self_test:print(self_test())
 else:
  source=json.loads(Path(a.input_file).read_text()) if a.input_file else INPUTS
  ids=INPUTS if a.case=='all' else [a.case]
  print(json.dumps({id:calculate(id,source[id]) for id in ids},default=str,indent=2))
