feat(tournaments): add partnership tracking and tournament management

Implement comprehensive partnership tracking system and tournament
management features including round-robin, single/double elimination,
and Swiss system pairings.

Changes:
- Add partnership_games and partnership_stats tables
- Implement PartnershipTracker service for recording partnership data
- Add tournament generator with multiple formats
- Create tournament management actions and views
- Add acceptance tests for partnership tracking
- Fix PartnershipTracker to use single snapshot per player per match
- Fix round-robin test to query by round_number instead of hardcoded ID

Note: All 8 acceptance tests now passing
This commit is contained in:
2026-03-27 12:25:34 -07:00
parent cb47b9da99
commit ac858f1e6d
55 changed files with 2591 additions and 0 deletions
+51
View File
@@ -0,0 +1,51 @@
# frozen_string_literal: true
require 'rom-repository'
module EuchreCamp
module Repositories
class PartnershipStats < ::EuchreCamp::Repository[:partnership_stats]
commands :create, update: :by_pk
def find_or_create(player_1_id, player_2_id)
# Ensure consistent ordering (lower ID first)
p1_id = [player_1_id, player_2_id].min
p2_id = [player_1_id, player_2_id].max
stats = partnership_stats.where(player_1_id: p1_id, player_2_id: p2_id).one
return stats if stats
create(
player_1_id: p1_id,
player_2_id: p2_id,
games_played: 0,
wins: 0,
losses: 0,
total_elo_change: 0
)
end
def by_player(player_id)
partnership_stats.where(
Sequel.|({ player_1_id: player_id }, { player_2_id: player_id })
).to_a
end
def update_stats(player_1_id, player_2_id, won: false, elo_change: 0)
stats = find_or_create(player_1_id, player_2_id)
update_params = {
games_played: stats.games_played + 1,
wins: stats.wins + (won ? 1 : 0),
losses: stats.losses + (won ? 0 : 1),
total_elo_change: stats.total_elo_change + elo_change,
last_played: Time.now,
updated_at: Time.now
}
update(stats.id, update_params)
end
end
end
end