feat(players): add player profile and schedule views
Implement player-facing views for profile analytics and tournament scheduling. Changes: - Add player profile page with partnership statistics - Add player schedule page with upcoming matches - Update rankings page to link to player profiles - Add partnership tracking display in profile - Include recent games timeline in profile Note: Schedule view shows upcoming matches and tournament participation
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module EuchreCamp
|
||||
module Actions
|
||||
module Players
|
||||
class Profile < EuchreCamp::Action
|
||||
include Deps[players_repo: 'repositories.players']
|
||||
|
||||
def handle(request, response)
|
||||
player_id = request.params[:id]
|
||||
player = players_repo.by_id(player_id)
|
||||
|
||||
# Get partnership statistics
|
||||
partnerships = EuchreCamp::Services::PartnershipTracker.get_player_partnerships(player_id)
|
||||
|
||||
# Get recent games (last 10)
|
||||
recent_games = get_recent_games(player_id)
|
||||
|
||||
response.render(view,
|
||||
player: player,
|
||||
partnerships: partnerships,
|
||||
recent_games: recent_games
|
||||
)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_recent_games(player_id)
|
||||
rom = EuchreCamp::App["persistence.rom"]
|
||||
|
||||
# Get matches where this player participated
|
||||
matches = rom.relations[:matches]
|
||||
.where(
|
||||
Sequel.|(
|
||||
{ team_1_p1_id: player_id },
|
||||
{ team_1_p2_id: player_id },
|
||||
{ team_2_p1_id: player_id },
|
||||
{ team_2_p2_id: player_id }
|
||||
)
|
||||
)
|
||||
.order(Sequel.desc(:played_at))
|
||||
.limit(10)
|
||||
.to_a
|
||||
|
||||
# Get player names for display
|
||||
all_players = rom.relations[:players].to_a.to_h { |p| [p[:id], p] }
|
||||
|
||||
matches.map do |match|
|
||||
team_1_players = [
|
||||
all_players[match[:team_1_p1_id]],
|
||||
all_players[match[:team_1_p2_id]]
|
||||
]
|
||||
team_2_players = [
|
||||
all_players[match[:team_2_p1_id]],
|
||||
all_players[match[:team_2_p2_id]]
|
||||
]
|
||||
|
||||
# Determine if this player won
|
||||
player_on_team_1 = match[:team_1_p1_id] == player_id || match[:team_1_p2_id] == player_id
|
||||
won = player_on_team_1 ? (match[:team_1_score] > match[:team_2_score]) : (match[:team_2_score] > match[:team_1_score])
|
||||
|
||||
{
|
||||
date: match[:played_at] || match[:created_at],
|
||||
team_1: team_1_players,
|
||||
team_2: team_2_players,
|
||||
score: "#{match[:team_1_score]}-#{match[:team_2_score]}",
|
||||
won: won,
|
||||
player_partner: player_on_team_1 ? team_1_players.find { |p| p[:id] != player_id } : team_2_players.find { |p| p[:id] != player_id }
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user