Files
lokiloto/lib/lokilab-feed.ts
T
Nazim KriandClaude Sonnet 5 c36b621d39 Add per-lottery stats page: number frequency, draw timeline, Loki's performance over time
New /loterie/[id] page, linked from each lottery's name in the results
panel. Three visualizations, all derived client-side from LokiLab's
extended army-feed (recentDraws + pickHistory) with no new math on
LokiLab's side:
- NumberFrequencyChart: bar chart of each number's appearances across
  the last ~30 draws
- PerformanceChart: Loki's cumulative win rate over time, line chart
- DrawTimeline: scannable list of recent draws with Loki's pick and
  hit highlighting where available

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-30 09:10:26 -04:00

45 lines
1.2 KiB
TypeScript

import 'server-only'
/**
* The one contract between LokiLab and LokiLoto: results, Loki's picks,
* lifetime win record, and army size. LokiLoto never talks to LokiLab's
* database or stats engine directly — only this feed.
*/
export interface ArmyFeed {
army: {
total: number
byCountry: Record<string, number>
}
lotteries: LotteryFeedEntry[]
}
export interface LotteryFeedEntry {
id: string
name: string
country: string
lifetime: {
picksTracked: number
wins: number
winRate: number
}
lastDraw: {
date: string
result: number[]
pick: number[] | null
matched: number | null
won: boolean | null
} | null
/** Last ~30 official draws (date + result only), newest first. */
recentDraws: { date: string; result: number[]; pick: number[] | null }[]
/** Loki's resolved picks over time (date + won), oldest first. */
pickHistory: { date: string; won: boolean }[]
}
const LOKILAB_FEED_URL = process.env.LOKILAB_FEED_URL ?? 'https://goldd.devyouz.net/api/public/army-feed'
export async function getArmyFeed(): Promise<ArmyFeed> {
const res = await fetch(LOKILAB_FEED_URL, { next: { revalidate: 300 } })
if (!res.ok) throw new Error(`LokiLab feed returned ${res.status}`)
return res.json()
}