Plan lab: honest licence booking, licence levels kept after the replay, unsponsored joins under the top position, sponsor leg obeys the gap toggle, pool-only members no longer count as paid

- Licence value now books the money each leg actually moved for it (its own share of the level), not the full level price; labelled "licence value funded" with a note on what a licence-granted level costs the system
- gStartRun: after replaying an org, money counters reset but members keep every level they hold, licence-won ones included, and keep what they actually paid in
- Joins with no recruiter go to the top position (spread placement) instead of the earliest member with one recruit, which qualified members who never brought a second
- Sponsor-leg licences respect the gap toggle (skip vs fund), like the depth leg
- "Paid" counts cash or entry share only; pool-only members are reported apart
- The climb and the drawn tree are labelled as simplified depth-only illustrations; headline numbers come from the month-by-month run
- Cache tag bumped

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-10-15 17:09:40 -05:00
parent be268beb66
commit 0db7c94728
2 changed files with 44 additions and 38 deletions
+35 -29
View File
@@ -597,11 +597,11 @@
c.depth++; c.nodes = next;
}
}
// an entry: placed breadth-first under the recruiter (or assigned to a member short of a direct), paid, split
// an entry: placed under the recruiter by the placement rule (no recruiter: under the top position), paid, split
function gJoin(recruiter, month, unsponsored){
if (!recruiter) { // assigned: earliest member with one recruit, else earliest with none (never you)
recruiter = G.members.find(x => x !== G.you && x.directs === 1) || G.members.find(x => x !== G.you && x.directs === 0) || G.you;
}
// no recruiter: the top position (the company, in the InstantAdPay view) recruits them, placed by the spread rule.
// FIXED 15 Oct: they used to go to the earliest member with one recruit, which qualified members who never recruited a second.
if (!recruiter) recruiter = G.you;
const parent = gSlot(recruiter);
const m = gAdd(parent, recruiter, month); m.unsponsored = !!unsponsored;
recruiter.directs++; recruiter.mDirects++;
@@ -629,7 +629,7 @@
let cur = from.recruiter;
while (cur) {
if (cur.level >= L) { if (gCashOk(cur, origin, L)) return { to: cur, kind: 'cash' }; }
else if (!rem) { const licOk = cur.directs >= 2 || PLAN.unq === 'licence'; if (licOk) return { to: cur, kind: 'lic' }; }
else if (!rem) { const behindOk = PLAN.gap === 'fund' || cur.level >= L - 1, licOk = cur.directs >= 2 || PLAN.unq === 'licence'; if (behindOk && licOk) return { to: cur, kind: 'lic' }; } // FIXED 15 Oct: the gap toggle applies to this leg too
cur = cur.recruiter;
}
return { to: null };
@@ -640,9 +640,9 @@
if (!r.to) { G.aud.above += amt; G.aud.received += amt; G.mon.above += amt; return; }
if (r.kind === 'cash') { r.to.cash += amt; r.to.sp += amt; G.mon.sp += amt; G.aud.received += amt; return; }
// each leg funds licences at its own share of the price: this leg's licence costs the sponsor share of level n,
// and that cost climbs the sponsor line. A licence is still a full level (licV records its full value).
// and that cost climbs the sponsor line. The holder gets the full level; licV records only the money that moved for it.
const n = r.to.level + 1, cost = net(n) * PLAN.sponsor;
r.to.level = n; r.to.lic++; r.to.licV += net(n); G.mon.lics++; G.mon.licV += net(n);
r.to.level = n; r.to.lic++; r.to.licV += cost; G.mon.lics++; G.mon.licV += cost; // FIXED 15 Oct: book what this leg moved for it, not the full level
gPayS(r.to, n, cost, origin, false);
if (amt - cost > 0.005) gPayS(r.to, L, amt - cost, origin, true);
}
@@ -663,7 +663,7 @@
if (!r.to) { G.aud.above += amt; G.aud.received += amt; G.mon.above += amt; return; }
if (r.kind === 'cash') { r.to.cash += amt; r.to.dc += amt; G.mon.dc += amt; G.aud.received += amt; return; }
const n = r.to.level + 1, cost = net(n) * (1 - PLAN.sponsor); // the depth leg's share of level n; with the sponsor leg off this is the whole price, as before
r.to.level = n; r.to.lic++; r.to.licV += net(n); G.mon.lics++; G.mon.licV += net(n);
r.to.level = n; r.to.lic++; r.to.licV += cost; G.mon.lics++; G.mon.licV += cost; // FIXED 15 Oct: book what this leg moved for it, not the full level
gPay(r.to, n, cost, n - 2, origin, false);
if (amt - cost > 0.005) gPay(r.to, L, amt - cost, 0, origin, true);
}
@@ -700,22 +700,28 @@
for (const r of rows) { const rec = map.get(r[1]); const m = gJoin(rec && rec !== G.you ? rec : (r[1] === SEED.apex ? G.you : null), 0, !rec); map.set(r[0], m); m.seedLevel = r[2]; }
for (let L = 2; L <= PLAN.maxL; L++) for (const m of G.members.slice().sort((a, b) => a.depth - b.depth || a.id - b.id)) if (m !== G.you && (m.seedLevel || 1) >= L && m.level < L) gBuy(m, L);
}
// Start over means start over (Marty, 28 Sep): the replay above only builds the org. Its money is reported once,
// in the story head, then every counter goes back to zero and members keep only the levels they actually bought.
G.replay = { in: G.aud.spent, admin: G.aud.admin + G.aud.entryFee, you: G.you.cash + G.you.entry, youLevel: G.you.level };
for (const m of G.members) { m.cash = 0; m.entry = 0; m.pool = 0; m.spent = 0; m.dc = 0; m.lic = 0; m.licV = 0; m.level = m === G.you ? 1 : (m.seedLevel || 1); if (m !== G.you) for (let L = 1; L <= m.level; L++) m.spent += price(L); } // what their bought levels cost at these prices
// Your levels bought up front (Marty, 28 Sep): start the run holding them, paid with your own money before month 1.
const preSel = document.getElementById('gYouLevels'); G.youPre = Math.min(PLAN.maxL, Math.max(1, Number(preSel && preSel.value) || 1));
G.you.level = G.youPre; G.you.spent = 0; for (let L = 1; L <= G.youPre; L++) G.you.spent += price(L);
G.aud = { spent: 0, received: 0, admin: 0, entryFee: 0, above: 0, pool: 0 }; G.poolCarry = 0; gNewMonth();
G.rows.push(gSnap(0));
const ol = document.getElementById('gStory'); if (ol) ol.innerHTML = '<li class="head">' + (seed === 'iap' ? 'Start: the InstantAdPay org today, placed 4-wide under each member\u2019s real recruiter: <b>' + cnt(G.members.length - 1) + ' members</b>, ' + cnt(G.members.filter(x => x.level >= 2).length) + ' of them past level 1 (the levels they actually bought), ' + cnt(G.members.filter(x => x.directs >= 2).length) + ' qualified. Every counter starts at zero and counts only what happens from month 1. For reference, had these rules been running all along, their past purchases would have moved <b>' + $$(G.replay.in) + '</b>, put <b>' + $$(G.replay.admin) + '</b> in the admin wallet and <b>' + $$(G.replay.you) + '</b> to you, funding you to level ' + G.replay.youLevel + '.' + (G.youPre > 1 ? ' <b>You start at level ' + G.youPre + '</b>, bought up front for ' + $$(G.you.spent) + '.' : '') : 'Start: just you at level ' + G.youPre + (G.youPre > 1 ? ' (bought up front for ' + $$(G.you.spent) + ')' : '') + ', nobody under you yet. In month 1 you recruit two people yourself (everyone needs two to receive cash at full reach); after that the org grows the way InstantAdPay’s did.') + ' Now run a month.</li>';
gStartRun();
const ol = document.getElementById('gStory'); if (ol) ol.innerHTML = '<li class="head">' + (seed === 'iap' ? 'Start: the InstantAdPay org today, placed 4-wide under each member\u2019s real recruiter: <b>' + cnt(G.members.length - 1) + ' members</b>, ' + cnt(G.members.filter(x => x.level >= 2).length) + ' of them past level 1 (the levels they hold: bought, or funded by licences when the past purchases were replayed), ' + cnt(G.members.filter(x => x.directs >= 2).length) + ' qualified. Every counter starts at zero and counts only what happens from month 1. For reference, had these rules been running all along, their past purchases would have moved <b>' + $$(G.replay.in) + '</b>, put <b>' + $$(G.replay.admin) + '</b> in the admin wallet and <b>' + $$(G.replay.you) + '</b> to you, funding you to level ' + G.replay.youLevel + '.' + (G.youPre > 1 ? ' <b>You start at level ' + G.youPre + '</b>, bought up front for ' + $$(G.you.spent) + '.' : '') : 'Start: just you at level ' + G.youPre + (G.youPre > 1 ? ' (bought up front for ' + $$(G.you.spent) + ')' : '') + ', nobody under you yet. In month 1 you recruit two people yourself (everyone needs two to receive cash at full reach); after that the org grows the way InstantAdPay’s did.') + ' Now run a month.</li>';
gRender();
window.growAudit = () => ({ spent: Math.round(G.aud.spent), received: Math.round(G.aud.received), ok: Math.abs(G.aud.spent - G.aud.received) <= 0.01 + 1e-9 * G.aud.spent });
}
// Start over means start over (Marty, 28 Sep): the replay only builds the org. Its money is reported once, in the
// story head, then every money counter goes back to zero. FIXED 15 Oct: members KEEP the levels they hold, including
// levels their team funded with licences during the replay (those were discarded before), and `spent` keeps what each
// actually paid in during the replay (entry + the levels they bought, never the licence-won ones).
function gStartRun(){
G.replay = { in: G.aud.spent, admin: G.aud.admin + G.aud.entryFee, you: G.you.cash + G.you.entry, youLevel: G.you.level };
for (const m of G.members) { m.cash = 0; m.entry = 0; m.pool = 0; m.dc = 0; m.sp = 0; m.lic = 0; m.licV = 0; }
// Your levels bought up front (Marty, 28 Sep): start the run holding them, paid with your own money before month 1.
const preSel = document.getElementById('gYouLevels'); G.youPre = Math.min(PLAN.maxL, Math.max(1, Number(preSel && preSel.value) || 1));
const won = G.you.level; G.you.level = Math.max(won, G.youPre); G.you.spent = price(1); for (let L = Math.max(2, won + 1); L <= G.youPre; L++) G.you.spent += price(L);
G.aud = { spent: 0, received: 0, admin: 0, entryFee: 0, above: 0, pool: 0 }; G.poolCarry = 0; gNewMonth();
G.rows = [gSnap(0)];
}
const earned = x => x.cash + x.entry; // paid by the plan itself; the pool is reported apart (FIXED 15 Oct)
function gSnap(month){
const ms = G.members.filter(x => x !== G.you);
const grp = f => { const g = ms.filter(f), v = g.map(x => inc(x)).sort((a, b) => b - a); const total = v.reduce((a, b) => a + b, 0); return { n: g.length, paid: g.filter(x => inc(x) > 0).length, total, avg: g.length ? total / g.length : 0, median: v.length ? v[Math.floor(v.length / 2)] : 0, top: v[0] || 0, lic: g.reduce((a, x) => a + x.lic, 0), pool: g.reduce((a, x) => a + x.pool, 0), spent: g.reduce((a, x) => a + x.spent, 0), poolPaid: g.filter(x => x.pool > 0).length }; };
const grp = f => { const g = ms.filter(f), v = g.map(x => inc(x)).sort((a, b) => b - a); const total = v.reduce((a, b) => a + b, 0); return { n: g.length, paid: g.filter(x => earned(x) > 0).length, poolOnly: g.filter(x => earned(x) <= 0 && x.pool > 0).length, total, avg: g.length ? total / g.length : 0, median: v.length ? v[Math.floor(v.length / 2)] : 0, top: v[0] || 0, lic: g.reduce((a, x) => a + x.lic, 0), pool: g.reduce((a, x) => a + x.pool, 0), spent: g.reduce((a, x) => a + x.spent, 0), poolPaid: g.filter(x => x.pool > 0).length }; };
let topB = null; for (const x of ms) if (!topB || x.mDirects > topB.mDirects) topB = x;
const b20 = ms.filter(x => x.mDirects >= 20);
const extra = { sp: G.mon.sp, pool: G.mon.pool, poolPaid: G.mon.poolPaid, poolN: G.mon.poolN, poolNew: G.mon.poolNew, poolNewAvg: G.mon.poolNewAvg, dc: G.mon.dc, en: G.mon.en, licV: G.mon.licV, heavy: grp(x => x.directs >= 10), light: grp(x => x.directs >= 1 && x.directs < 10), passive: grp(x => x.directs === 0),
@@ -723,7 +729,7 @@
b20: { n: b20.length, avg: b20.length ? b20.reduce((a, x) => a + inc(x) - x.m0, 0) / b20.length : 0 } };
return { ...extra, month, joins: G.mon.joins, assigned: G.mon.assigned, buys: G.mon.buys, lics: G.mon.lics, members: ms.length, in: G.mon.in, admin: G.mon.admin, above: G.mon.above,
toMembers: ms.reduce((a, x) => a + inc(x), 0), toYou: G.you.cash + G.you.entry, youLevel: G.you.level, youLic: G.you.lic,
paid: ms.filter(x => inc(x) > 0).length, l2: ms.filter(x => x.level >= 2).length, qualified: ms.filter(x => x.directs >= 2).length };
paid: ms.filter(x => earned(x) > 0).length, poolOnly: ms.filter(x => earned(x) <= 0 && x.pool > 0).length, l2: ms.filter(x => x.level >= 2).length, qualified: ms.filter(x => x.directs >= 2).length };
}
function gMonth(){
G.month++; gNewMonth();
@@ -752,7 +758,7 @@
const s = gSnap(G.month); G.rows.push(s);
const prev = G.rows[G.rows.length - 2];
const dYou = s.toYou - prev.toYou;
storyG('<b>Month ' + G.month + '.</b> ' + cnt(s.joins) + ' joined' + (s.assigned ? ', ' + cnt(s.assigned) + ' of them with no recruiter, assigned to members short of a direct' : '') + '. ' + cnt(s.buys) + ' bought a level with their own money and ' + cnt(s.lics) + ' licences were funded by pass-ups. Money in <b>' + $$(s.in) + '</b>: company <b>' + $$(s.admin) + '</b>, pool <b>' + $$(s.pool) + '</b>, the rest to members' + (s.above ? ' (' + $$(s.above) + ' climbed past you to the company)' : '') + '. You: <b>' + (dYou >= 0 ? '+' : '') + $$(dYou) + '</b>' + (s.youLevel > prev.youLevel ? ', and your team moved you to <span class="chip lic">level ' + s.youLevel + '</span>' : '') + '. ' + cnt(s.paid) + ' of ' + cnt(s.members) + ' members have been paid something; ' + cnt(s.l2) + ' are past level 1.' + (s.top ? ' <b>Heaviest builder this month:</b> #' + s.top.id + ' brought ' + cnt(s.top.n) + ' and made <b>' + $$(s.top.m) + '</b> this month (' + $$(s.top.total) + ' so far, level ' + s.top.level + ', ' + cnt(s.top.directs) + ' recruits in all).' : '') + (s.b20.n ? ' Builders who brought 20+ this month: ' + cnt(s.b20.n) + ', averaging <b>' + $$(s.b20.avg) + '</b> this month.' : '') + (s.sp ? ' Sponsor leg paid ' + $$(s.sp) + ' this month.' : '') + (s.poolPaid ? ' <b>Pool:</b> ' + $$(s.poolPaid) + ' split among ' + cnt(s.poolN) + ' active members, ' + $$(s.poolPaid / s.poolN) + ' each on average' + (s.poolNew ? '; ' + cnt(s.poolNew) + ' new members who finished training got about ' + $$(s.poolNewAvg) + ' each' : '') + '.' : ''), s.youLevel > prev.youLevel ? 'lic' : 'cash');
storyG('<b>Month ' + G.month + '.</b> ' + cnt(s.joins) + ' joined' + (s.assigned ? ', ' + cnt(s.assigned) + ' of them with no recruiter, placed under the top position (the company)' : '') + '. ' + cnt(s.buys) + ' bought a level with their own money and ' + cnt(s.lics) + ' licences were funded by pass-ups. Money in <b>' + $$(s.in) + '</b>: company <b>' + $$(s.admin) + '</b>, pool <b>' + $$(s.pool) + '</b>, the rest to members' + (s.above ? ' (' + $$(s.above) + ' climbed past you to the company)' : '') + '. You: <b>' + (dYou >= 0 ? '+' : '') + $$(dYou) + '</b>' + (s.youLevel > prev.youLevel ? ', and your team moved you to <span class="chip lic">level ' + s.youLevel + '</span>' : '') + '. ' + cnt(s.paid) + ' of ' + cnt(s.members) + ' members have been paid something; ' + cnt(s.l2) + ' are past level 1.' + (s.top ? ' <b>Heaviest builder this month:</b> #' + s.top.id + ' brought ' + cnt(s.top.n) + ' and made <b>' + $$(s.top.m) + '</b> this month (' + $$(s.top.total) + ' so far, level ' + s.top.level + ', ' + cnt(s.top.directs) + ' recruits in all).' : '') + (s.b20.n ? ' Builders who brought 20+ this month: ' + cnt(s.b20.n) + ', averaging <b>' + $$(s.b20.avg) + '</b> this month.' : '') + (s.sp ? ' Sponsor leg paid ' + $$(s.sp) + ' this month.' : '') + (s.poolPaid ? ' <b>Pool:</b> ' + $$(s.poolPaid) + ' split among ' + cnt(s.poolN) + ' active members, ' + $$(s.poolPaid / s.poolN) + ' each on average' + (s.poolNew ? '; ' + cnt(s.poolNew) + ' new members who finished training got about ' + $$(s.poolNewAvg) + ' each' : '') + '.' : ''), s.youLevel > prev.youLevel ? 'lic' : 'cash');
gRender();
}
function gVisuals(s){
@@ -762,27 +768,27 @@
const tot = parts.reduce((a, p) => a + p[1], 0) || 1;
flow.innerHTML = '<div style="display:flex;height:34px;border-radius:8px;overflow:hidden;border:1px solid var(--line)">' + parts.filter(p => p[1] > 0).map(p => '<div title="' + p[0] + ' ' + $$(p[1]) + '" style="width:' + (100 * p[1] / tot).toFixed(2) + '%;background:' + p[2] + '"></div>').join('') + '</div>'
+ '<div style="display:flex;flex-wrap:wrap;gap:8px 16px;margin-top:8px" class="note">' + parts.map(p => '<span><i style="display:inline-block;width:10px;height:10px;border-radius:2px;background:' + p[2] + ';margin-right:6px;vertical-align:middle"></i>' + p[0] + ' <b>' + $$(p[1]) + '</b> (' + Math.round(100 * p[1] / tot) + '%)</span>').join('') + '</div>'
+ '<p class="note" style="margin-top:6px">Money in this month <b>' + $$(s.in) + '</b>. Along the way ' + cnt(s.lics) + ' licences were funded, worth ' + $$(s.licV) + ' of levels nobody had to pay for.</p>';
+ '<p class="note" style="margin-top:6px">Money in this month <b>' + $$(s.in) + '</b>. Along the way ' + cnt(s.lics) + ' licences were granted (each one a full level for its holder); licence value funded: ' + $$(s.licV) + ', the money that actually moved for them. Each leg funds a licence at its own share of the price, so with the sponsor leg at ' + Math.round(PLAN.sponsor * 100) + '% a licence moves only part of a level’s price, and nobody pays the rest: that part of the level costs the system nothing and pays nobody.</p>';
const ms = G.members.filter(x => x !== G.you);
const med = arr => { const v = arr.slice().sort((a, b) => inc(a) - inc(b)); return v.length ? v[Math.floor(v.length / 2)] : null; };
let heavy = null; for (const x of ms) if (!heavy || x.directs > heavy.directs) heavy = x;
const light = med(ms.filter(x => x.directs >= 1 && x.directs < 10));
const oldP = ms.filter(x => x.directs === 0 && G.month - x.month >= 3), pas = med(oldP.length ? oldP : ms.filter(x => x.directs === 0));
const card = (title, x, why) => !x ? '' : '<div class="rule"><div class="n">' + title + '</div><h3>#' + x.id + ' \u00b7 level ' + x.level + ' \u00b7 ' + cnt(x.directs) + ' recruit' + (x.directs === 1 ? '' : 's') + '</h3><p>In since month ' + x.month + '. Paid in <b>' + $$(x.spent) + '</b>. Got back <b>' + $$(inc(x)) + '</b>: cash ' + $$(x.cash) + ' (sponsor leg ' + $$(x.sp) + ', depth ' + $$(x.dc) + '), entry shares ' + $$(x.entry) + ', pool ' + $$(x.pool) + '. ' + cnt(x.lic) + ' licence' + (x.lic === 1 ? '' : 's') + ' worth ' + $$(x.licV) + '. <b>Net ' + (inc(x) - x.spent >= 0 ? '+' : '\u2212') + $$(Math.abs(inc(x) - x.spent)) + '</b>' + (x.licV ? ' in cash, ' + (inc(x) + x.licV - x.spent >= 0 ? '+' : '\u2212') + $$(Math.abs(inc(x) + x.licV - x.spent)) + ' counting licences' : '') + '.</p><p class="note">' + why + '</p></div>';
const card = (title, x, why) => !x ? '' : '<div class="rule"><div class="n">' + title + '</div><h3>#' + x.id + ' \u00b7 level ' + x.level + ' \u00b7 ' + cnt(x.directs) + ' recruit' + (x.directs === 1 ? '' : 's') + '</h3><p>In since month ' + x.month + '. Paid in <b>' + $$(x.spent) + '</b>. Got back <b>' + $$(inc(x)) + '</b>: cash ' + $$(x.cash) + ' (sponsor leg ' + $$(x.sp) + ', depth ' + $$(x.dc) + '), entry shares ' + $$(x.entry) + ', pool ' + $$(x.pool) + '. ' + cnt(x.lic) + ' licence' + (x.lic === 1 ? '' : 's') + ', licence value funded ' + $$(x.licV) + '. <b>Net ' + (inc(x) - x.spent >= 0 ? '+' : '\u2212') + $$(Math.abs(inc(x) - x.spent)) + '</b>' + (x.licV ? ' in cash, ' + (inc(x) + x.licV - x.spent >= 0 ? '+' : '\u2212') + $$(Math.abs(inc(x) + x.licV - x.spent)) + ' counting licences' : '') + '.</p><p class="note">' + why + '</p></div>';
document.getElementById('gPeople').innerHTML = card('HEAVIEST BUILDER', heavy, 'The most personal recruits in the org.') + card('TYPICAL LIGHT BUILDER', light, 'The median member with 1 to 9 recruits.') + card('TYPICAL JOIN-AND-PAY MEMBER', pas, oldP.length ? 'The median member with no recruits, in for 3 months or more.' : 'The median member with no recruits.');
const row = (name, g) => '<tr><td style="text-align:left">' + name + '</td><td>' + cnt(g.n) + '</td><td>' + (g.n ? Math.round(100 * g.paid / g.n) : 0) + '%</td><td>' + $$(g.median) + '</td><td>' + $$(g.avg) + '</td><td>' + $$(g.top) + '</td><td>' + $$(g.n ? g.spent / g.n : 0) + '</td><td>' + cnt(g.poolPaid) + '</td><td>' + $$(g.pool) + '</td><td>' + cnt(g.lic) + '</td><td class="bar"><i style="width:' + Math.min(100, Math.round(100 * g.avg / Math.max(1, s.heavy.avg))) + '%"></i></td></tr>';
document.getElementById('gMix').innerHTML = '<table class="tabular"><thead><tr><th style="text-align:left">Group</th><th>Members</th><th>Paid anything</th><th>Median got back</th><th>Average</th><th>Top</th><th>Avg paid in</th><th>Got pool</th><th>Pool total</th><th>Licences</th><th></th></tr></thead><tbody>' + row('Builders, 10+ recruits', s.heavy) + row('Light builders, 1 to 9', s.light) + row('Join-and-pay, no recruits', s.passive) + '</tbody></table>';
document.getElementById('gMix').innerHTML = '<table class="tabular"><thead><tr><th style="text-align:left">Group</th><th>Members</th><th>Paid by the plan</th><th>Median got back</th><th>Average</th><th>Top</th><th>Avg paid in</th><th>Got pool</th><th>Pool total</th><th>Licences</th><th></th></tr></thead><tbody>' + row('Builders, 10+ recruits', s.heavy) + row('Light builders, 1 to 9', s.light) + row('Join-and-pay, no recruits', s.passive) + '</tbody></table>';
}
function storyG(html, cls){ const ol = document.getElementById('gStory'); if (!ol) return; const li = document.createElement('li'); if (cls) li.className = cls; li.innerHTML = html; ol.prepend(li); while (ol.children.length > 40) ol.removeChild(ol.lastChild); }
function gRender(){
const s = G.rows[G.rows.length - 1];
document.getElementById('gMonth').textContent = G.month; document.getElementById('gMembers').textContent = cnt(s.members) + ' members';
document.getElementById('gLevel').textContent = s.youLevel; document.getElementById('gLevelS').textContent = 'reach = depth 1 to ' + s.youLevel + ' \u00b7 ' + s.youLic + ' licence' + (s.youLic === 1 ? '' : 's') + ' funded for you';
document.getElementById('gYou').textContent = $$(s.toYou); document.getElementById('gYouS').textContent = 'cash ' + $$(G.you.cash) + ' + entries ' + $$(G.you.entry) + '; licences worth ' + $$(G.you.licV) + ' apart' + (G.you.spent ? ' \u00b7 paid ' + $$(G.you.spent) + (G.youPre > 1 ? ' up front for levels 1 to ' + G.youPre : ' for your entry') + ', net ' + (s.toYou - G.you.spent >= 0 ? '+' : '\u2212') + $$(Math.abs(s.toYou - G.you.spent)) : '');
document.getElementById('gYou').textContent = $$(s.toYou); document.getElementById('gYouS').textContent = 'cash ' + $$(G.you.cash) + ' + entries ' + $$(G.you.entry) + '; licence value funded ' + $$(G.you.licV) + ', apart' + (() => { const u = G.members.filter(x => x.unsponsored).length; return u ? ' · you are the top position, so the ' + cnt(u) + ' members who arrived with no recruiter are yours (in a launch that is the company’s position, so most of this is company money)' : ''; })() + (G.you.spent ? ' \u00b7 paid ' + $$(G.you.spent) + (G.youPre > 1 ? ' up front for levels 1 to ' + G.youPre : ' for your entry') + ', net ' + (s.toYou - G.you.spent >= 0 ? '+' : '\u2212') + $$(Math.abs(s.toYou - G.you.spent)) : '');
document.getElementById('gAdmin').textContent = $$(G.aud.admin + G.aud.entryFee);
document.getElementById('gPool').textContent = $$(G.members.reduce((a, x) => a + x.pool, 0)); document.getElementById('gPoolS').textContent = s.poolN ? 'this month ' + $$(s.poolPaid) + ' to ' + cnt(s.poolN) + ' active members' : (Math.round(PLAN.pool * 100)) + '% of every dollar, split by activity';
gVisuals(s);
document.getElementById('gPaid').textContent = cnt(s.paid); document.getElementById('gPaidS').textContent = 'of ' + cnt(s.members) + ' (' + (s.members ? Math.round(100 * s.paid / s.members) : 0) + '%) \u00b7 ' + cnt(s.qualified) + ' qualified';
document.getElementById('gPaid').textContent = cnt(s.paid); document.getElementById('gPaidS').textContent = 'of ' + cnt(s.members) + ' (' + (s.members ? Math.round(100 * s.paid / s.members) : 0) + '%) \u00b7 ' + cnt(s.qualified) + ' qualified' + (s.poolOnly ? ' · ' + cnt(s.poolOnly) + ' more got pool money only' : '');
document.getElementById('gIn').textContent = $$(G.aud.spent);
const tb = document.querySelector('#gTable tbody'); if (tb) { tb.innerHTML = ''; for (const r of G.rows) { const tr = document.createElement('tr'); tr.innerHTML = '<td>' + r.month + '</td><td>' + cnt(r.joins) + '</td><td>' + cnt(r.members) + '</td><td>' + cnt(r.buys) + '</td><td>' + $$(r.in) + '</td><td>' + $$(r.admin) + '</td><td>' + $$(r.in - r.admin - r.above) + '</td><td>' + $$(r.toYou) + '</td><td>' + r.youLevel + '</td><td>' + cnt(r.paid) + '</td><td>' + cnt(r.l2) + '</td>'; tb.appendChild(tr); } }
const sp = document.getElementById('gSpread');
@@ -791,13 +797,13 @@
const pct = (p) => ms.length ? ms[Math.min(ms.length - 1, Math.floor(ms.length * p))] : 0;
const top10 = ms.slice(0, Math.max(1, Math.round(ms.length * 0.1))).reduce((a, b) => a + b, 0), all = ms.reduce((a, b) => a + b, 0);
const lv = {}; for (const x of G.members) if (x !== G.you) lv[x.level] = (lv[x.level] || 0) + 1;
const older = G.members.filter(x => x !== G.you && G.month - x.month >= 6), olderPaid = older.filter(x => inc(x) > 0);
const older = G.members.filter(x => x !== G.you && G.month - x.month >= 6), olderPaid = older.filter(x => earned(x) > 0);
const olderVals = older.map(x => inc(x)).sort((a, b) => b - a), olderMed = olderVals.length ? olderVals[Math.floor(olderVals.length / 2)] : 0;
const carried = G.members.filter(x => x !== G.you && x.level >= 2 && !(x.bought || 0)).length, ownBuy = G.members.filter(x => x !== G.you && (x.bought || 0) > 0).length;
sp.innerHTML = 'Top earner in the org: <b>' + $$(ms[0] || 0) + '</b>. Top 10% of members took ' + (all ? Math.round(100 * top10 / all) : 0) + '% of what members received. Median member: <b>' + $$(pct(0.5)) + '</b>. Members with nothing: ' + cnt(ms.filter(v => v <= 0).length) + ' (most of them joined recently).'
sp.innerHTML = 'Top earner in the org: <b>' + $$(ms[0] || 0) + '</b>. Top 10% of members took ' + (all ? Math.round(100 * top10 / all) : 0) + '% of what members received. Median member: <b>' + $$(pct(0.5)) + '</b>. Members paid nothing by the plan (no cash, no entry share): ' + cnt(G.members.filter(x => x !== G.you && earned(x) <= 0).length) + ' (most of them joined recently), of whom ' + cnt(G.members.filter(x => x !== G.you && earned(x) <= 0 && x.pool > 0).length) + ' got pool money only.'
+ '<br><b>Members in for 6 months or more:</b> ' + cnt(older.length) + ', of whom ' + cnt(olderPaid.length) + ' (' + (older.length ? Math.round(100 * olderPaid.length / older.length) : 0) + '%) have been paid; their median is <b>' + $$(olderMed) + '</b>.'
+ '<br><b>Product without paying:</b> ' + cnt(carried) + ' members hold level 2 or higher purely from licences their team funded; ' + cnt(ownBuy) + ' bought at least one level themselves.'
+ (() => { const s0 = G.rows[G.rows.length - 1]; const line = (name, g) => '<br><b>' + name + ':</b> ' + cnt(g.n) + ' members, ' + cnt(g.paid) + ' paid (' + (g.n ? Math.round(100 * g.paid / g.n) : 0) + '%), median <b>' + $$(g.median) + '</b>, top ' + $$(g.top) + ', ' + cnt(g.lic) + ' licences, ' + (all ? Math.round(100 * g.total / all) : 0) + '% of member income'; return '<br><b>The mix.</b>' + line('Builders, 10+ recruits', s0.heavy) + line('Light builders, 1 to 9', s0.light) + line('Join-and-pay members, no recruits', s0.passive); })()
+ (() => { const s0 = G.rows[G.rows.length - 1]; const line = (name, g) => '<br><b>' + name + ':</b> ' + cnt(g.n) + ' members, ' + cnt(g.paid) + ' paid by the plan (' + (g.n ? Math.round(100 * g.paid / g.n) : 0) + '%' + (g.poolOnly ? ', ' + cnt(g.poolOnly) + ' more pool only' : '') + '), median <b>' + $$(g.median) + '</b>, top ' + $$(g.top) + ', ' + cnt(g.lic) + ' licences, ' + (all ? Math.round(100 * g.total / all) : 0) + '% of member income'; return '<br><b>The mix.</b>' + line('Builders, 10+ recruits', s0.heavy) + line('Light builders, 1 to 9', s0.light) + line('Join-and-pay members, no recruits', s0.passive); })()
+ '<br>Levels held: ' + Object.keys(lv).map(Number).sort((a, b) => a - b).map(L => 'L' + L + ' ' + cnt(lv[L])).join(' \u00b7 ') + '.';
}
}