"""Original arithmetic from declared public inputs or explicit worked assumptions."""
import csv
from pathlib import Path
results={}
for name,b,se in [('sales',.000402,.000816),('purchasers',.000048,.0000218),('orders',.000052,.000028)]:
 for scale,label in [(1e6,'per_million_assigned'),(1e6/.4,'per_million_exposed_assuming40pct')]:
  results[name+'_'+label+'_point']=b*scale;results[name+'_'+label+'_lower95']=(b-1.96*se)*scale;results[name+'_'+label+'_upper95']=(b+1.96*se)*scale
 results[name+'_z_before']=b/se;results[name+'_z_after_fixed_rescaling']=(b/.4)/(se/.4)
 assert abs(results[name+'_z_before']-results[name+'_z_after_fixed_rescaling'])<1e-12
results['ratio_of_effects_not_AOV']=.000402/.000048
p=Path(__file__).parent/"data";p.mkdir(exist_ok=True)
with (p/"message-exposure-scaling.csv").open("w",newline="") as f:
 w=csv.writer(f);w.writerow(["metric","value"]);w.writerows(results.items())
print(results)
