code wiki / _hdl_build / nx_batt_planner.nx

nx_batt_planner.nx source

↩ module page · 84 lines · 3595 B

1// nx_batt_planner.nx -- R4 PROFIT/RISK PLANNING TOOL. Operator: "id be curious about the profit risk etc thats why 2// i want planning tools." Compares candidate business models so the NUMBERS (not opinion) inform the model choice. 3// Each model = a DATA-DRIVEN ModelScenario (#11 -- every input is data, no magic). The engine computes, per model: 4// PROFIT: monthly revenue, net monthly profit, margin (per-mille), break-even months (ceil; -1 = never). 5// RISK: a weighted composite score (0..100, fire-safety weighted highest = the operator's #1 priority) + flags 6// NET-NEGATIVE / HIGH-FIRE / CAPITAL-HEAVY / SLOW-BREAKEVEN. 7// NO-FLOAT by construction (exact i64 cents -- the nx_money discipline; floats are WRONG for money). Mirrors the 8// nx_fin_finance risk-flag + rank pattern (DRY #15). HONEST: the ENGINE is the deliverable; the input numbers are 9// ESTIMATES until R1 intake / R2 recondition / R3 facility ground real prices, COGS, throughput, and capital. 10// Read-only, never-brick #26. license_tier: ORIGINAL 11 12struct ModelScenario { 13 id: i64, 14 monthly_jobs: i64, 15 avg_price_c: i64, 16 avg_cogs_c: i64, 17 monthly_labor_c: i64, 18 monthly_fixed_c: i64, 19 upfront_c: i64, 20 fire: i64, // 0..100 inherent fire-safety exposure 21 capital: i64, // 0..100 capital intensity 22 regulatory: i64, // 0..100 regulatory burden 23 demand: i64, // 0..100 demand uncertainty 24 labor_dep: i64, // 0..100 labor dependency 25} 26 27struct RiskCfg { 28 w_fire: i64, // weights sum to 100 29 w_capital: i64, 30 w_reg: i64, 31 w_demand: i64, 32 w_labor: i64, 33 fire_high_line: i64, // >= this -> HIGH-FIRE 34 capital_line: i64, // >= this -> CAPITAL-HEAVY 35 slow_breakeven_months: i64, // > this (or never) -> SLOW-BREAKEVEN 36} 37 38struct PlanResult { 39 revenue_c: i64, 40 net_monthly_c: i64, 41 margin_permille: i64, 42 breakeven_months: i64, // -1 = never (net <= 0) 43 risk_score: i64, // 0..100 44 flag_net_neg: i64, 45 flag_high_fire: i64, 46 flag_capital_heavy: i64, 47 flag_slow_breakeven: i64, 48} 49 50func nx_plan_risk_score(ms: *ModelScenario, rc: *RiskCfg) -> i64 { 51 let num: i64 = ms.fire*rc.w_fire + ms.capital*rc.w_capital + ms.regulatory*rc.w_reg + ms.demand*rc.w_demand + ms.labor_dep*rc.w_labor 52 return num / 100 53} 54 55func nx_plan_eval(ms: *ModelScenario, rc: *RiskCfg, out: *PlanResult) -> i64 { 56 let revenue: i64 = ms.monthly_jobs * ms.avg_price_c 57 let gross: i64 = ms.monthly_jobs * (ms.avg_price_c - ms.avg_cogs_c) 58 let net: i64 = gross - ms.monthly_labor_c - ms.monthly_fixed_c 59 out.revenue_c = revenue 60 out.net_monthly_c = net 61 if revenue > 0 { out.margin_permille = (net * 1000) / revenue } else { out.margin_permille = 0 } 62 63 if net > 0 { 64 out.breakeven_months = (ms.upfront_c + net - 1) / net 65 } else { 66 out.breakeven_months = -1 67 } 68 69 out.risk_score = nx_plan_risk_score(ms, rc) 70 71 out.flag_net_neg = 0 72 if net <= 0 { out.flag_net_neg = 1 } 73 out.flag_high_fire = 0 74 if ms.fire >= rc.fire_high_line { out.flag_high_fire = 1 } 75 out.flag_capital_heavy = 0 76 if ms.capital >= rc.capital_line { out.flag_capital_heavy = 1 } 77 out.flag_slow_breakeven = 0 78 if out.breakeven_months < 0 { 79 out.flag_slow_breakeven = 1 80 } else { 81 if out.breakeven_months > rc.slow_breakeven_months { out.flag_slow_breakeven = 1 } 82 } 83 return net 84}