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>
This commit is contained in:
Nazim Kri
2026-10-30 09:10:26 -04:00
co-authored by Claude Sonnet 5
parent c3a0a7b765
commit c36b621d39
8 changed files with 219 additions and 3 deletions
+86
View File
@@ -0,0 +1,86 @@
import type { Metadata } from "next"
import { notFound } from "next/navigation"
import { getArmyFeed } from "@/lib/lokilab-feed"
import { numberFrequency, performanceOverTime } from "@/lib/chart-data"
import { countryTheme } from "@/lib/countries"
import { AppHeader } from "@/components/app-header"
import { NumberFrequencyChart } from "@/components/number-frequency-chart"
import { PerformanceChart } from "@/components/performance-chart"
import { DrawTimeline } from "@/components/draw-timeline"
import { Badge } from "@/components/ui/badge"
export const instant = false
export async function generateMetadata({ params }: { params: Promise<{ id: string }> }): Promise<Metadata> {
const { id } = await params
return { title: `${id} — Statistiques LokiLoto` }
}
export default async function LotteryStatsPage({ params }: { params: Promise<{ id: string }> }) {
const { id } = await params
const feed = await getArmyFeed()
const entry = feed.lotteries.find((l) => l.id === id)
if (!entry) notFound()
const theme = countryTheme(entry.country)
const frequency = numberFrequency(entry)
const performance = performanceOverTime(entry)
return (
<main
className="flex flex-1 flex-col"
style={{ "--accent": theme.accent, "--accent-soft": theme.accentSoft } as React.CSSProperties}
>
<AppHeader />
<div className="mx-auto w-full max-w-4xl flex-1 px-4 py-6 sm:px-6">
<div className="flex flex-wrap items-center gap-2">
<h1 className="text-2xl font-bold tracking-tight">{entry.name}</h1>
<Badge variant="secondary">
{theme.flagEmoji} {theme.name}
</Badge>
</div>
<p className="mt-1 text-sm text-muted-foreground">
{entry.lifetime.picksTracked > 0
? `${(entry.lifetime.winRate * 100).toFixed(0)}% de réussite sur ${entry.lifetime.picksTracked} grilles suivies`
: "Pas encore de grilles résolues pour cette loterie."}
</p>
<section className="mt-6 rounded-md border border-border/60 bg-panel p-4">
<h2 className="mb-1 text-sm font-semibold">Fréquence des numéros</h2>
<p className="mb-3 text-xs text-muted-foreground">
Sur les {entry.recentDraws.length} derniers tirages — statistique descriptive seulement.
</p>
{frequency.length > 0 ? (
<NumberFrequencyChart data={frequency} />
) : (
<p className="text-sm text-muted-foreground">Pas encore assez de données.</p>
)}
</section>
<section className="mt-4 rounded-md border border-border/60 bg-panel p-4">
<h2 className="mb-1 text-sm font-semibold">Performance de Loki dans le temps</h2>
<p className="mb-3 text-xs text-muted-foreground">Taux de réussite cumulé, grille après grille.</p>
{performance.length > 1 ? (
<PerformanceChart data={performance} />
) : (
<p className="text-sm text-muted-foreground">Pas encore assez de grilles résolues.</p>
)}
</section>
<section className="mt-4">
<h2 className="mb-2 text-sm font-semibold">Historique des tirages</h2>
{entry.recentDraws.length > 0 ? (
<DrawTimeline entry={entry} />
) : (
<p className="text-sm text-muted-foreground">Aucun tirage disponible.</p>
)}
</section>
<p className="mt-6 text-[11px] text-muted-foreground">
Données fournies par LokiLab. Statistiques descriptives seulement — aucune garantie de
gain.
</p>
</div>
</main>
)
}
+27
View File
@@ -0,0 +1,27 @@
import { NumberSequence } from "@/components/number-sequence"
import type { LotteryFeedEntry } from "@/lib/lokilab-feed"
export function DrawTimeline({ entry }: { entry: LotteryFeedEntry }) {
return (
<div className="space-y-2">
{entry.recentDraws.map((draw) => {
const resultSet = new Set(draw.result)
return (
<div
key={draw.date}
className="flex flex-wrap items-center gap-3 rounded-md border border-border/60 bg-panel px-3 py-2"
>
<span className="w-20 shrink-0 text-xs text-muted-foreground tabular-nums">{draw.date}</span>
<NumberSequence numbers={draw.result} />
{draw.pick && (
<span className="flex items-center gap-1.5 text-xs text-muted-foreground">
Choix:
<NumberSequence numbers={draw.pick} hitSet={resultSet} />
</span>
)}
</div>
)
})}
</div>
)
}
+4 -1
View File
@@ -1,3 +1,4 @@
import Link from "next/link"
import { NumberSequence } from "@/components/number-sequence"
import { FollowButton } from "@/components/follow-button"
import type { LotteryFeedEntry } from "@/lib/lokilab-feed"
@@ -29,7 +30,9 @@ export function LotteryMobileCard({
isAuthenticated={isAuthenticated}
/>
)}
{entry.name}
<Link href={`/loterie/${entry.id}`} className="hover:text-accent hover:underline">
{entry.name}
</Link>
</p>
{lifetime.picksTracked > 0 ? (
<p className="text-xs text-muted-foreground">
+7 -2
View File
@@ -1,3 +1,4 @@
import Link from "next/link"
import { NumberSequence } from "@/components/number-sequence"
import { FollowButton } from "@/components/follow-button"
import type { LotteryFeedEntry } from "@/lib/lokilab-feed"
@@ -31,9 +32,13 @@ export function LotteryRow({
</div>
<div className="min-w-0">
<p className="truncate font-semibold leading-tight" title={entry.name}>
<Link
href={`/loterie/${entry.id}`}
className="block truncate font-semibold leading-tight hover:text-accent hover:underline"
title={entry.name}
>
{entry.name}
</p>
</Link>
{lastDraw && (
<p className="text-xs text-muted-foreground">{formatDate(lastDraw.date)}</p>
)}
+27
View File
@@ -0,0 +1,27 @@
"use client"
import { Bar, BarChart, CartesianGrid, ResponsiveContainer, Tooltip, XAxis, YAxis } from "recharts"
import type { FrequencyPoint } from "@/lib/chart-data"
export function NumberFrequencyChart({ data }: { data: FrequencyPoint[] }) {
return (
<ResponsiveContainer width="100%" height={220}>
<BarChart data={data} margin={{ left: 0, right: 8, top: 8, bottom: 0 }}>
<CartesianGrid strokeDasharray="3 3" stroke="var(--border)" vertical={false} />
<XAxis dataKey="number" tick={{ fill: "var(--muted-foreground)", fontSize: 11 }} />
<YAxis tick={{ fill: "var(--muted-foreground)", fontSize: 11 }} allowDecimals={false} />
<Tooltip
contentStyle={{
background: "var(--panel)",
border: "1px solid var(--border)",
borderRadius: 6,
fontSize: 12,
}}
cursor={{ fill: "var(--panel-hover)" }}
labelFormatter={(v) => `Numéro ${v}`}
/>
<Bar dataKey="count" name="Apparitions" fill="var(--accent)" radius={[3, 3, 0, 0]} />
</BarChart>
</ResponsiveContainer>
)
}
+32
View File
@@ -0,0 +1,32 @@
"use client"
import { CartesianGrid, Line, LineChart, ResponsiveContainer, Tooltip, XAxis, YAxis } from "recharts"
import type { PerformancePoint } from "@/lib/chart-data"
export function PerformanceChart({ data }: { data: PerformancePoint[] }) {
const chartData = data.map((p) => ({ ...p, pct: Math.round(p.cumulativeWinRate * 100) }))
return (
<ResponsiveContainer width="100%" height={220}>
<LineChart data={chartData} margin={{ left: 0, right: 8, top: 8, bottom: 0 }}>
<CartesianGrid strokeDasharray="3 3" stroke="var(--border)" vertical={false} />
<XAxis dataKey="date" tick={{ fill: "var(--muted-foreground)", fontSize: 11 }} minTickGap={24} />
<YAxis
domain={[0, 100]}
unit="%"
tick={{ fill: "var(--muted-foreground)", fontSize: 11 }}
/>
<Tooltip
contentStyle={{
background: "var(--panel)",
border: "1px solid var(--border)",
borderRadius: 6,
fontSize: 12,
}}
formatter={(v) => [`${v}%`, "Taux de réussite cumulé"]}
/>
<Line type="monotone" dataKey="pct" stroke="var(--accent)" strokeWidth={2} dot={false} />
</LineChart>
</ResponsiveContainer>
)
}
+32
View File
@@ -0,0 +1,32 @@
import type { LotteryFeedEntry } from "./lokilab-feed"
export interface FrequencyPoint {
number: number
count: number
}
/** Frequency of each distinct number across recentDraws' results, sorted ascending by number. */
export function numberFrequency(entry: LotteryFeedEntry): FrequencyPoint[] {
const counts = new Map<number, number>()
for (const draw of entry.recentDraws) {
for (const n of draw.result) counts.set(n, (counts.get(n) ?? 0) + 1)
}
return [...counts.entries()].sort((a, b) => a[0] - b[0]).map(([number, count]) => ({ number, count }))
}
export interface PerformancePoint {
date: string
cumulativeWinRate: number
resolved: number
}
/** Running win-rate of Loki's picks over time, for a trend line. */
export function performanceOverTime(entry: LotteryFeedEntry): PerformancePoint[] {
let wins = 0
let resolved = 0
return entry.pickHistory.map((p) => {
resolved++
if (p.won) wins++
return { date: p.date, cumulativeWinRate: wins / resolved, resolved }
})
}
+4
View File
@@ -29,6 +29,10 @@ export interface LotteryFeedEntry {
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'