Implement comprehensive per-player statistics tracking across arcade games: - Database schema: player_stats table with per-player metrics - Migration: 0013_add_player_stats.sql for schema deployment - Type system: Universal GameResult types supporting all game modes (competitive, cooperative, solo, head-to-head) - API endpoints: - POST /api/player-stats/record-game - Record game results - GET /api/player-stats - Fetch all user's players' stats - GET /api/player-stats/[playerId] - Fetch specific player stats - React hooks: - useRecordGameResult() - Mutation hook with cache invalidation - usePlayerStats() - Query hooks for fetching stats - Game integration: Matching game now records stats on completion - UI updates: /games page displays per-player stats in player cards Stats tracked: games played, wins, losses, best time, accuracy, per-game breakdowns (JSON), favorite game type, last played date. Supports cooperative games via metadata.isTeamVictory flag where all players share win/loss outcome. Documentation added: - GAME_STATS_COMPARISON.md - Cross-game analysis - PER_PLAYER_STATS_ARCHITECTURE.md - System design - MATCHING_GAME_STATS_INTEGRATION.md - Integration guide 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
18 lines
600 B
SQL
18 lines
600 B
SQL
-- Migration: Add player_stats table
|
|
-- Per-player game statistics tracking
|
|
|
|
CREATE TABLE `player_stats` (
|
|
`player_id` text PRIMARY KEY NOT NULL,
|
|
`games_played` integer DEFAULT 0 NOT NULL,
|
|
`total_wins` integer DEFAULT 0 NOT NULL,
|
|
`total_losses` integer DEFAULT 0 NOT NULL,
|
|
`best_time` integer,
|
|
`highest_accuracy` real DEFAULT 0 NOT NULL,
|
|
`favorite_game_type` text,
|
|
`game_stats` text DEFAULT '{}' NOT NULL,
|
|
`last_played_at` integer,
|
|
`created_at` integer NOT NULL,
|
|
`updated_at` integer NOT NULL,
|
|
FOREIGN KEY (`player_id`) REFERENCES `players`(`id`) ON UPDATE no action ON DELETE cascade
|
|
);
|