(a) Example action · Simulating multiple scenarios into the future · Day 28
start_day=nm.vars.current_day
cash=nm.query('SELECT SUM(amount) cash FROM ledger')['rows'][0]['cash']
⋯ 10+ lines suppressed
def simulate(params):
    history={}; active=0
    for day in range(start_day+1,230):
        ad_spend=params['ad_spend'](day)
        new_subs=ad_spend*params['subs_per_dollar'](day)
        revenue=new_subs*params['avg_price'](day)
        if day in params.get('enterprise_days',[]): revenue+=params['enterprise_value']
⋯ 25+ lines suppressed
        churn=active*params['churn'](day)
        active+=new_subs-churn
        cost=ad_spend+active*params['compute_per_sub'](day)
        cash+=revenue-cost
        if day in [start_day+28,start_day+84,start_day+182]: history[day]=(cash,active)
    return history
def make_params(scale):
    return {'ad_spend':lambda d:8000 if d<start_day+50 else scale,'subs_per_dollar':lambda d:0.02 if d<start_day+84 else 0.018,'avg_price':lambda d:80,'compute_per_sub':lambda d:2.0,'churn':lambda d:0.03,'enterprise_days':[start_day+50] if scale>20000 else [],'enterprise_value':140000}
for scale in [3000,12000,25000]: print(scale,simulate(make_params(scale)))
⋯ 10+ lines suppressed
CASE low d+7 cash 213,479 d+28 cash 68,156 d+84 cash -104,164 d+182 cash -268,101
CASE base ⋯ 4 lines suppressed CASE high ⋯ 4 lines suppressed
(b) Example action · Infer latent customer attributes from noisy negotiation outcomes · Day 133
rows=nm.query("""select et.customer_id,c.group_id,et.offer_json,s.status from enterprise_turns et join customers c on c.customer_id=et.customer_id left join subscriptions s on s.customer_id=et.customer_id where et.sender='agent' and et.offer_json not in ('{}','')""")['rows']
⋯ 40+ lines suppressed
def parse_prices(o):
  try: d=json.loads(o)
  except: return []
  return [(x.get('plan'),x.get('price',x.get('price_per_seat',x.get('monthly_price')))) for x in ([d] if isinstance(d,dict) else d) if isinstance(x,dict) and x.get('plan')]
last={}; [last.setdefault(r['customer_id'],r) for r in rows]
for gid in set(r['group_id'] for r in last.values()):
  lr=[r for r in last.values() if r['group_id']==gid]
  for plan in ['A','B','C']:
    by_status=collections.defaultdict(list)
    for r in lr:
      for p,v in parse_prices(r['offer_json']):
        if p==plan and v is not None: by_status[r['status']].append(float(v))
    if by_status:
      print(gid,plan,{s:(len(v),round(statistics.mean(v),2)) for s,v in by_status.items()})
⋯ 20+ lines suppressed
Active enterprise accepted price distribution {'group_id':'E3','plan':'B','n':154,'seats':167595,'minp':1.69,'avgp':56.01,'maxp':89.0} {'group_id':'E3','plan':'C','n':3,'seats':3341,'minp':25.0,'avgp':101.0,'maxp':139.0} Enterprise lost by latest agent offer and day groups summary GID D_E02 n 413 statuses Counter({'lost':403,'lead':10}) B all avg 40.19 min 39.0 max 49.0 by_status {'lost':(403,40.22,39,49),'lead':(10,39,39,39)} C all avg 61.15 min 59.0 max 79.0 by_status {'lost':(403,61.21,59,79),'lead':(10,59,59,59)} ⋯ 40+ lines suppressed