Skip to content

Commit 3a66b8d

Browse files
committed
feat: populate seasons page with match history and player stats
1 parent 0177bf5 commit 3a66b8d

2 files changed

Lines changed: 150 additions & 5 deletions

File tree

app/controllers/seasons_controller.rb

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
class SeasonsController < ApplicationController
22
def index
33
set_meta_tags(title: "Temporadas — Kings Lendas")
4-
@seasons = SEASONS_DATA.map do |slug, data|
5-
{ slug: slug, **data }
6-
end
4+
@seasons = SEASONS_DATA.map { |slug, data| { slug: slug, **data } }
75
end
86

97
def show
@@ -16,6 +14,7 @@ def show
1614
set_meta_tags(title: "#{@season_data[:label]} — Kings Lendas")
1715

1816
tournament = @season_data[:leaguepedia_name]
17+
1918
@standings = CacheService.fetch("standings:#{@slug}", :standings) do
2019
leaguepedia.standings(tournament)
2120
end
@@ -24,8 +23,45 @@ def show
2423
leaguepedia.schedule(tournament)
2524
end
2625

26+
# Fallback: compute standings from schedule when TournamentResults is empty
27+
if @standings.blank? && @schedule.any?
28+
@standings = leaguepedia.standings_from_schedule(@schedule)
29+
end
30+
2731
@champion_stats = CacheService.fetch("champion_stats:#{@slug}", :champion_stats) do
2832
leaguepedia.champion_stats(tournament)
2933
end.first(10)
34+
35+
@players = CacheService.fetch("players:#{@slug}", :player_stats) do
36+
raw = leaguepedia.scoreboard_players(tournament)
37+
aggregate_season_players(raw)
38+
end.first(10)
39+
40+
@matches_by_phase = @schedule
41+
.group_by { |m| m["Phase"].presence || "Fase de Grupos" }
42+
end
43+
44+
private
45+
46+
def aggregate_season_players(raw)
47+
return [] if raw.blank?
48+
raw.group_by { |p| p["Link"] }.map do |player, games|
49+
kills = games.sum { |g| g["Kills"].to_i }
50+
deaths = games.sum { |g| g["Deaths"].to_i }
51+
assists = games.sum { |g| g["Assists"].to_i }
52+
kda = deaths.zero? ? (kills + assists).to_f : (kills + assists).to_f / deaths
53+
{
54+
"player" => player,
55+
"team" => games.last["Team"],
56+
"role" => games.last["Role"],
57+
"games" => games.length,
58+
"kills" => kills,
59+
"deaths" => deaths,
60+
"assists" => assists,
61+
"kda" => kda.round(2),
62+
"avg_cs" => (games.sum { |g| g["CS"].to_i }.to_f / games.length).round(1),
63+
"champions" => games.map { |g| g["Champion"] }.tally.sort_by { |_, v| -v }.first(3).map(&:first)
64+
}
65+
end.sort_by { |p| -p["kda"] }
3066
end
3167
end

app/views/seasons/show.html.erb

Lines changed: 111 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,118 @@
5858
<% end %>
5959
</div>
6060

61-
<!-- Top champions -->
61+
<!-- Top Players -->
62+
<% if @players.any? %>
63+
<div style="margin-bottom:24px">
64+
<%= retro_panel(title: "Top Jogadores", category: "// ESTATÍSTICAS", footer: @season_data[:name]) do %>
65+
<table style="width:100%;border-collapse:collapse">
66+
<thead>
67+
<tr style="border-bottom:1px solid var(--retro-gold-dim)">
68+
<th class="retro-table-head" style="text-align:left">Jogador</th>
69+
<th class="retro-table-head" style="text-align:left">Time</th>
70+
<th class="retro-table-head" style="text-align:center">GS</th>
71+
<th class="retro-table-head" style="text-align:center">KDA</th>
72+
<th class="retro-table-head" style="text-align:center">K</th>
73+
<th class="retro-table-head" style="text-align:center">D</th>
74+
<th class="retro-table-head" style="text-align:center">A</th>
75+
<th class="retro-table-head" style="text-align:center">CS/j</th>
76+
<th class="retro-table-head" style="text-align:left">Campeões</th>
77+
</tr>
78+
</thead>
79+
<tbody>
80+
<% @players.each do |p| %>
81+
<tr class="retro-table-row" style="border-bottom:1px solid rgba(200,155,60,0.08)">
82+
<td style="padding:9px 8px 9px 0">
83+
<span style="font-size:12px;font-weight:bold;color:rgba(255,255,255,0.85);font-family:var(--retro-font)"><%= p["player"] %></span>
84+
</td>
85+
<td style="padding:9px 8px">
86+
<div style="display:flex;align-items:center;gap:5px">
87+
<%= team_logo(p["team"], size: 18) %>
88+
<span style="font-size:11px;color:rgba(255,255,255,0.4);font-family:var(--retro-font)"><%= team_abbr(p["team"]) %></span>
89+
</div>
90+
</td>
91+
<td style="padding:9px 8px;text-align:center">
92+
<span style="font-size:12px;color:rgba(255,255,255,0.5);font-family:var(--retro-font)"><%= p["games"] %></span>
93+
</td>
94+
<td style="padding:9px 8px;text-align:center">
95+
<span style="font-size:13px;font-weight:bold;font-family:var(--retro-font);color:<%= p["kda"] >= 5 ? '#ecc94b' : (p["kda"] >= 3 ? 'var(--color-kl-win)' : 'rgba(255,255,255,0.7)') %>"><%= p["kda"] %></span>
96+
</td>
97+
<td style="padding:9px 8px;text-align:center"><span style="font-size:12px;color:var(--color-kl-win);font-family:var(--retro-font)"><%= p["kills"] %></span></td>
98+
<td style="padding:9px 8px;text-align:center"><span style="font-size:12px;color:var(--color-kl-loss);font-family:var(--retro-font)"><%= p["deaths"] %></span></td>
99+
<td style="padding:9px 8px;text-align:center"><span style="font-size:12px;color:rgba(255,255,255,0.6);font-family:var(--retro-font)"><%= p["assists"] %></span></td>
100+
<td style="padding:9px 8px;text-align:center"><span style="font-size:12px;color:rgba(255,255,255,0.5);font-family:var(--retro-font)"><%= p["avg_cs"] %></span></td>
101+
<td style="padding:9px 8px">
102+
<div style="display:flex;gap:2px">
103+
<% p["champions"].each do |champ| %>
104+
<%= champion_icon(champ, size: 24) %>
105+
<% end %>
106+
</div>
107+
</td>
108+
</tr>
109+
<% end %>
110+
</tbody>
111+
</table>
112+
<% end %>
113+
</div>
114+
<% end %>
115+
116+
<!-- Match Results -->
117+
<% if @matches_by_phase.any? %>
118+
<div style="margin-bottom:24px">
119+
<%= retro_panel(title: "Partidas", category: "// HISTÓRICO", footer: @season_data[:name]) do %>
120+
<% @matches_by_phase.each do |phase, matches| %>
121+
<div style="margin-bottom:20px">
122+
<div class="retro-sep" style="margin-bottom:12px">
123+
<div class="retro-sep-line"></div>
124+
<span class="retro-sep-label"><%= phase_label(phase) %></span>
125+
<div class="retro-sep-line-r"></div>
126+
</div>
127+
128+
<div style="display:grid;gap:6px">
129+
<% matches.each do |match| %>
130+
<% t1 = match["Team1"]; t2 = match["Team2"] %>
131+
<% winner = match["Winner"]; played = winner.present? %>
132+
<% t1s = match["Team1Score"].to_i; t2s = match["Team2Score"].to_i %>
133+
134+
<div style="border:1px solid <%= played ? 'rgba(200,155,60,0.15)' : 'rgba(5,150,170,0.12)' %>;background:rgba(15,24,35,0.6);padding:10px 14px;display:flex;align-items:center;gap:10px">
135+
<div style="flex:1;display:flex;align-items:center;gap:6px;min-width:0;opacity:<%= played && winner != t1 ? '0.4' : '1' %>">
136+
<%= team_logo(t1, size: 22) %>
137+
<span style="font-size:12px;font-weight:bold;color:rgba(255,255,255,0.85);font-family:var(--retro-font);overflow:hidden;text-overflow:ellipsis;white-space:nowrap"><%= team_abbr(t1) %></span>
138+
</div>
139+
140+
<div style="flex-shrink:0;text-align:center;min-width:56px">
141+
<% if played %>
142+
<div style="display:flex;align-items:center;justify-content:center;gap:4px">
143+
<span style="font-size:18px;font-weight:900;font-family:var(--retro-font);color:<%= winner == t1 ? 'var(--color-kl-win)' : 'rgba(255,255,255,0.2)' %>"><%= t1s %></span>
144+
<span style="color:rgba(255,255,255,0.15);font-size:13px">:</span>
145+
<span style="font-size:18px;font-weight:900;font-family:var(--retro-font);color:<%= winner == t2 ? 'var(--color-kl-win)' : 'rgba(255,255,255,0.2)' %>"><%= t2s %></span>
146+
</div>
147+
<div style="font-size:9px;color:var(--retro-gold-dim);font-family:var(--retro-font);letter-spacing:0.08em;margin-top:1px">Bo<%= match["BestOf"].to_i > 0 ? match["BestOf"] : 1 %></div>
148+
<% else %>
149+
<span style="font-size:14px;font-weight:bold;color:rgba(255,255,255,0.15);font-family:var(--retro-font)">VS</span>
150+
<% end %>
151+
</div>
152+
153+
<div style="flex:1;display:flex;align-items:center;justify-content:flex-end;gap:6px;min-width:0;opacity:<%= played && winner != t2 ? '0.4' : '1' %>">
154+
<span style="font-size:12px;font-weight:bold;color:rgba(255,255,255,0.85);font-family:var(--retro-font);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;text-align:right"><%= team_abbr(t2) %></span>
155+
<%= team_logo(t2, size: 22) %>
156+
</div>
157+
158+
<div style="flex-shrink:0;min-width:54px;text-align:right">
159+
<span style="font-size:10px;color:rgba(255,255,255,0.25);font-family:var(--retro-font)"><%= format_datetime_brt(match["DateTime_UTC"]) %></span>
160+
</div>
161+
</div>
162+
<% end %>
163+
</div>
164+
</div>
165+
<% end %>
166+
<% end %>
167+
</div>
168+
<% end %>
169+
170+
<!-- Top Champions -->
62171
<% if @champion_stats.any? %>
63-
<%= retro_panel(title: "Top Campeões", category: "// ESTATÍSTICAS", footer: @season_data[:name]) do %>
172+
<%= retro_panel(title: "Top Campeões", category: "// PICKS", footer: @season_data[:name]) do %>
64173
<div style="display:flex;flex-wrap:wrap;gap:12px;padding:4px 0 8px">
65174
<% @champion_stats.each do |champ| %>
66175
<div style="text-align:center;width:58px">

0 commit comments

Comments
 (0)