Download src/engine/settlement.js from ismizo/bet: direct link, hf CLI and curl.
- Browser
- Download file 3.24 kB
-
https://huggingface.co/spaces/ismizo/bet/resolve/main/src/engine/settlement.js
- Command line
-
hf download hf://spaces/ismizo/bet/src/engine/settlement.js
-
curl -L -o settlement.js https://huggingface.co/spaces/ismizo/bet/resolve/main/src/engine/settlement.js
3.24 kB
| /** | |
| * Deterministic Over/Under half-goal settlement grader & tier calibration tracker. | |
| * Zero LLM calls required for half-goal totals. | |
| */ | |
| export function parseOverUnderPick(pickText) { | |
| if (!pickText) return null; | |
| const s = String(pickText).trim(); | |
| const m = s.match(/\b(over|under)\s+(\d+(?:\.5)?)\b/i); | |
| if (!m) return null; | |
| const side = m[1].toLowerCase(); | |
| const line = Number(m[2]); | |
| if (!Number.isFinite(line)) return null; | |
| return { side, line }; | |
| } | |
| /** | |
| * Grade a single Over/Under leg deterministically from 90-minute regular-time scores. | |
| */ | |
| export function gradeOverUnderLeg(pickText, homeScore, awayScore, isPostponed = false) { | |
| if (isPostponed) { | |
| return { status: 'void', totalGoals: null, explanation: 'Match postponed or abandoned (void).' }; | |
| } | |
| const parsed = parseOverUnderPick(pickText); | |
| if (!parsed) return null; | |
| const h = Number(homeScore); | |
| const a = Number(awayScore); | |
| if (!Number.isFinite(h) || !Number.isFinite(a)) return null; | |
| const totalGoals = h + a; | |
| let status = 'void'; | |
| if (parsed.side === 'over') { | |
| if (totalGoals > parsed.line) status = 'won'; | |
| else if (totalGoals < parsed.line) status = 'lost'; | |
| } else { | |
| if (totalGoals < parsed.line) status = 'won'; | |
| else if (totalGoals > parsed.line) status = 'lost'; | |
| } | |
| return { | |
| status, | |
| totalGoals, | |
| explanation: `Final ${h}-${a} (${totalGoals} goals) vs ${parsed.side === 'over' ? 'Over' : 'Under'} ${parsed.line} -> ${status.toUpperCase()}.`, | |
| }; | |
| } | |
| /** | |
| * Compute overall accumulator slip status from individual leg statuses. | |
| */ | |
| export function computeSlipStatusFromLegs(legStatuses = []) { | |
| if (!legStatuses.length) return 'pending'; | |
| if (legStatuses.includes('lost')) return 'lost'; | |
| if (legStatuses.includes('pending')) return 'pending'; | |
| if (legStatuses.includes('won')) return 'won'; | |
| return 'void'; | |
| } | |
| /** | |
| * Aggregate settled calibration metrics across CLEAN, CAUTION, and VETOED scouted legs. | |
| */ | |
| export function computeTierCalibration(scoutRuns = []) { | |
| const buckets = { | |
| CLEAN: { total: 0, won: 0, lost: 0, void: 0, staked: 0, returned: 0 }, | |
| CAUTION: { total: 0, won: 0, lost: 0, void: 0, staked: 0, returned: 0 }, | |
| VETOED: { total: 0, won: 0, lost: 0, void: 0, staked: 0, returned: 0 }, | |
| }; | |
| for (const run of scoutRuns) { | |
| for (const leg of run.evaluatedLegs || []) { | |
| const bucket = buckets[leg.riskStatus]; | |
| if (!bucket) continue; | |
| if (!['won', 'lost', 'void'].includes(leg.settlementStatus)) continue; | |
| bucket.total += 1; | |
| if (leg.settlementStatus === 'won') { | |
| bucket.won += 1; | |
| bucket.staked += 1; | |
| bucket.returned += Number(leg.odds) || 1; | |
| } else if (leg.settlementStatus === 'lost') { | |
| bucket.lost += 1; | |
| bucket.staked += 1; | |
| } else { | |
| bucket.void += 1; | |
| } | |
| } | |
| } | |
| const out = {}; | |
| for (const [tier, b] of Object.entries(buckets)) { | |
| const decided = b.won + b.lost; | |
| out[tier] = { | |
| decided, | |
| won: b.won, | |
| lost: b.lost, | |
| void: b.void, | |
| hitRatePct: decided > 0 ? +((b.won / decided) * 100).toFixed(1) : null, | |
| flatRoiPct: b.staked > 0 ? +(((b.returned - b.staked) / b.staked) * 100).toFixed(1) : null, | |
| }; | |
| } | |
| return out; | |
| } | |