diff --git a/lib/rewards.js b/lib/rewards.js index dd573a6..43c6882 100644 --- a/lib/rewards.js +++ b/lib/rewards.js @@ -66,6 +66,19 @@ function payable() { } function mark(id, patch) { return store.update('payouts', [], all => { const p = all.find(x => x.id === id); if (p) Object.assign(p, patch); return all; }); } +// the day's pool: committed POL (paid, sent, due, queued; never failed) against the cap, and when it +// resets: the next midnight in Central time, found by bisection on the day key (never a UTC midnight) +function nextResetAt(now) { + const t0 = now || Date.now(); const today = ctDay(t0); + let lo = t0, hi = t0 + 26 * 3600000; + while (hi - lo > 1000) { const mid = Math.floor((lo + hi) / 2); if (ctDay(mid) === today) lo = mid; else hi = mid; } + return hi; +} +function pool() { + const s = settings(); const day = ctDay(); const today = paidToday(day); const cap = Number(s.dailyCapPol); + return { capPol: cap, todayPol: Math.round(today * 10000) / 10000, spent: today >= cap - 1e-9, resetsAt: nextResetAt() }; +} + function ledger(n) { return store.read('payouts', []).filter(p => p.status === 'paid').sort((a, b) => b.paidAt - a.paidAt).slice(0, n || 50); } function mine(memberId) { return store.read('payouts', []).filter(p => p.memberId === Number(memberId)).sort((a, b) => b.at - a.at); } function totals() { @@ -74,4 +87,4 @@ function totals() { return { paid: paid.length, pol: Math.round(paid.reduce((n, p) => n + p.pol, 0) * 10000) / 10000, queued: all.filter(p => p.status === 'queued').length, today: paidToday(ctDay()), hunters: new Set(paid.map(p => p.memberId)).size }; } -module.exports = { settings, setSettings, draw, grant, completed, payable, mark, ledger, mine, totals, paidToday }; +module.exports = { settings, setSettings, draw, grant, completed, payable, mark, ledger, mine, totals, paidToday, pool, nextResetAt }; diff --git a/public/admin.html b/public/admin.html index 92b9329..77f7334 100644 --- a/public/admin.html +++ b/public/admin.html @@ -5,7 +5,7 @@ Admin · PolHunter - +