Add stats screen with backend endpoint and frontend page

Implements a dedicated /stats page showing cross-run aggregate statistics:
run overview with win rate, runs by game bar chart, encounter breakdowns,
top caught/encountered pokemon rankings, mortality analysis with death
causes, and type distribution. Backend endpoint uses aggregate SQL queries
to avoid N+1 fetching.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-07 20:46:36 +01:00
parent 78d31f2856
commit fb90410055
12 changed files with 700 additions and 13 deletions

View File

@@ -1,3 +1,4 @@
export * from './admin'
export * from './game'
export * from './rules'
export * from './stats'

View File

@@ -0,0 +1,51 @@
export interface GameRunCount {
gameId: number
gameName: string
gameColor: string | null
count: number
}
export interface PokemonRanking {
pokemonId: number
name: string
spriteUrl: string | null
count: number
}
export interface DeathCause {
cause: string
count: number
}
export interface TypeCount {
type: string
count: number
}
export interface StatsResponse {
totalRuns: number
activeRuns: number
completedRuns: number
failedRuns: number
winRate: number | null
avgDurationDays: number | null
runsByGame: GameRunCount[]
totalEncounters: number
caughtCount: number
faintedCount: number
missedCount: number
catchRate: number | null
avgEncountersPerRun: number | null
topCaughtPokemon: PokemonRanking[]
topEncounteredPokemon: PokemonRanking[]
totalDeaths: number
mortalityRate: number | null
topDeathCauses: DeathCause[]
avgCatchLevel: number | null
avgFaintLevel: number | null
typeDistribution: TypeCount[]
}