"""Print the numbers the lesson quotes. Run: python3 show_numbers.py"""
from budget import Budget, CheckOnlyBudget, cost, dollars
from inflight import BURST_INPUT, fire
from sim import RULES, SEED, simulate_day

LIMIT = 250_000

print(f"A short question (60 in, 30 out) costs {cost(60, 30)} micro-dollars; a long document (50,000 in, 2,000 out) costs {cost(50_000, 2_000)}: "
      f"{cost(50_000, 2_000) / cost(60, 30):.1f} times as much.")
print(f"\nOne simulated day (seed {SEED}), ten users, one heavy:")
for rule, name in RULES:
    day = simulate_day(rule)
    print(f"  {name:20} bill {dollars(day.bill)}  heavy share {day.percent(0)}%  heavy calls refused {day.refused[0]} of {day.served[0] + day.refused[0]}"
          f"  ordinary calls refused {day.ordinary_refused} of {day.ordinary_asked}  ordinary users {min(day.percent(u) for u in range(1, 10))}-{max(day.percent(u) for u in range(1, 10))}% each")
print(f"\n20 calls at once, each costing ${cost(BURST_INPUT, 800) / 1e6:.3f}; the budget is {dollars(LIMIT)}:")
for label, budget, kwargs in (("check only", CheckOnlyBudget(LIMIT), {}), ("set aside first", Budget(LIMIT), {}), ("set aside, input guessed at half", Budget(LIMIT), {"estimate": BURST_INPUT // 2})):
    statuses, charged = fire(budget, **kwargs)
    print(f"  {label:34} admitted {statuses.count(200):2}  refused {statuses.count(429):2}  charged {dollars(charged)} ({charged / LIMIT:.2f} times the budget)")
