From c36b621d391a0500a475fe31a38a1b4c75f672ab Mon Sep 17 00:00:00 2001 From: Nazim Kri Date: Fri, 30 Oct 2026 09:10:26 -0400 Subject: [PATCH] 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 --- app/loterie/[id]/page.tsx | 86 +++++++++++++++++++++++++++ components/draw-timeline.tsx | 27 +++++++++ components/lottery-mobile-card.tsx | 5 +- components/lottery-row.tsx | 9 ++- components/number-frequency-chart.tsx | 27 +++++++++ components/performance-chart.tsx | 32 ++++++++++ lib/chart-data.ts | 32 ++++++++++ lib/lokilab-feed.ts | 4 ++ 8 files changed, 219 insertions(+), 3 deletions(-) create mode 100644 app/loterie/[id]/page.tsx create mode 100644 components/draw-timeline.tsx create mode 100644 components/number-frequency-chart.tsx create mode 100644 components/performance-chart.tsx create mode 100644 lib/chart-data.ts diff --git a/app/loterie/[id]/page.tsx b/app/loterie/[id]/page.tsx new file mode 100644 index 0000000..732ba2d --- /dev/null +++ b/app/loterie/[id]/page.tsx @@ -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 { + 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 ( +
+ +
+
+

{entry.name}

+ + {theme.flagEmoji} {theme.name} + +
+

+ {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."} +

+ +
+

Fréquence des numéros

+

+ Sur les {entry.recentDraws.length} derniers tirages — statistique descriptive seulement. +

+ {frequency.length > 0 ? ( + + ) : ( +

Pas encore assez de données.

+ )} +
+ +
+

Performance de Loki dans le temps

+

Taux de réussite cumulé, grille après grille.

+ {performance.length > 1 ? ( + + ) : ( +

Pas encore assez de grilles résolues.

+ )} +
+ +
+

Historique des tirages

+ {entry.recentDraws.length > 0 ? ( + + ) : ( +

Aucun tirage disponible.

+ )} +
+ +

+ Données fournies par LokiLab. Statistiques descriptives seulement — aucune garantie de + gain. +

+
+
+ ) +} diff --git a/components/draw-timeline.tsx b/components/draw-timeline.tsx new file mode 100644 index 0000000..bcf080b --- /dev/null +++ b/components/draw-timeline.tsx @@ -0,0 +1,27 @@ +import { NumberSequence } from "@/components/number-sequence" +import type { LotteryFeedEntry } from "@/lib/lokilab-feed" + +export function DrawTimeline({ entry }: { entry: LotteryFeedEntry }) { + return ( +
+ {entry.recentDraws.map((draw) => { + const resultSet = new Set(draw.result) + return ( +
+ {draw.date} + + {draw.pick && ( + + Choix: + + + )} +
+ ) + })} +
+ ) +} diff --git a/components/lottery-mobile-card.tsx b/components/lottery-mobile-card.tsx index c4f2ede..8615ed0 100644 --- a/components/lottery-mobile-card.tsx +++ b/components/lottery-mobile-card.tsx @@ -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} + + {entry.name} +

{lifetime.picksTracked > 0 ? (

diff --git a/components/lottery-row.tsx b/components/lottery-row.tsx index f75d1ae..2e31843 100644 --- a/components/lottery-row.tsx +++ b/components/lottery-row.tsx @@ -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({

-

+ {entry.name} -

+ {lastDraw && (

{formatDate(lastDraw.date)}

)} diff --git a/components/number-frequency-chart.tsx b/components/number-frequency-chart.tsx new file mode 100644 index 0000000..245af47 --- /dev/null +++ b/components/number-frequency-chart.tsx @@ -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 ( + + + + + + `Numéro ${v}`} + /> + + + + ) +} diff --git a/components/performance-chart.tsx b/components/performance-chart.tsx new file mode 100644 index 0000000..ed48234 --- /dev/null +++ b/components/performance-chart.tsx @@ -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 ( + + + + + + [`${v}%`, "Taux de réussite cumulé"]} + /> + + + + ) +} diff --git a/lib/chart-data.ts b/lib/chart-data.ts new file mode 100644 index 0000000..ada3e47 --- /dev/null +++ b/lib/chart-data.ts @@ -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() + 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 } + }) +} diff --git a/lib/lokilab-feed.ts b/lib/lokilab-feed.ts index a680053..967586f 100644 --- a/lib/lokilab-feed.ts +++ b/lib/lokilab-feed.ts @@ -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'