"""Illustrative cost per clip/generated minute; all inputs are explicit."""
import argparse,json,math
p=argparse.ArgumentParser(description=__doc__)
for name in ('stock-seconds','paiton-seconds','video-seconds','gpu-price','active-hours','wall-watts','electricity-per-kwh'):
    p.add_argument('--'+name,type=float,required=True)
p.add_argument('--currency',default='USD')
a=p.parse_args()
for k,v in vars(a).items():
    if k!='currency' and (not math.isfinite(v) or v<=0):p.error(k+' must be finite and positive')
hourly=a.gpu_price/a.active_hours+(a.wall_watts/1000)*a.electricity_per_kwh
result={'currency':a.currency,'inputs':vars(a),'hourly_modeled_cost':hourly,'scope':'Scenario, not measured wall power. GPU capex plus assumed whole-system electricity; excludes host capex, idle hours, cooling, maintenance, financing, tax, residual value, review and rejected outputs.'}
for engine,t in [('stock',a.stock_seconds),('paiton',a.paiton_seconds)]:
    result[engine]={'seconds_per_clip':t,'clips_per_hour':3600/t,'cost_per_clip':hourly*t/3600,'cost_per_generated_minute':hourly*t/3600*60/a.video_seconds,'clips_per_100_currency':100/(hourly*t/3600),'generated_hours_per_active_lifetime':a.active_hours*a.video_seconds/t}
result['cost_reduction_percent']=(1-a.paiton_seconds/a.stock_seconds)*100
result['throughput_gain_percent']=(a.stock_seconds/a.paiton_seconds-1)*100
print(json.dumps(result,indent=2))
