mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-03-25 01:14:43 +00:00
Create bracket views with upcomingMatches
This commit is contained in:
@@ -37,10 +37,12 @@ class StaticPagesController < ApplicationController
|
||||
if params[:weight]
|
||||
@weight = Weight.find(params[:weight])
|
||||
@tournament = Tournament.find(@weight.tournament_id)
|
||||
@poolOneWrestlers = Wrestler.where(weight_id: @weight.id, poolNumber: 1)
|
||||
@poolTwoWrestlers = Wrestler.where(weight_id: @weight.id, poolNumber: 2)
|
||||
@poolThreeWrestlers = Wrestler.where(weight_id: @weight.id, poolNumber: 3)
|
||||
@poolFourWrestlers = Wrestler.where(weight_id: @weight.id, poolNumber: 4)
|
||||
@matches = @tournament.upcomingMatches
|
||||
@wrestlers = Wrestler.where(weight_id: @weight.id)
|
||||
@poolOneWrestlers = @wrestlers.select{|w| w.poolNumber == 1}
|
||||
@poolTwoWrestlers = @wrestlers.select{|w| w.poolNumber == 2}
|
||||
@poolThreeWrestlers = @wrestlers.select{|w| w.poolNumber == 3}
|
||||
@poolFourWrestlers = @wrestlers.select{|w| w.poolNumber == 4}
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -1,18 +1,6 @@
|
||||
class Matchup
|
||||
attr_accessor :w1, :w2, :round, :weight_id, :boutNumber, :w1_name, :w2_name
|
||||
|
||||
# def w1
|
||||
# end
|
||||
|
||||
# def w2
|
||||
# end
|
||||
|
||||
# def round
|
||||
# end
|
||||
|
||||
# def weight_id
|
||||
# end
|
||||
|
||||
def weight_max
|
||||
@weight = Weight.find(self.weight_id)
|
||||
return @weight.max
|
||||
|
||||
@@ -10,9 +10,6 @@ class Tournament < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def upcomingMatches
|
||||
# @matches = Match.where(tournament_id: self.id)
|
||||
# @matches.sort_by{|x|[x.boutNumber]}
|
||||
# @matches.sort_by{|x|[x.round,x.weight.max]}
|
||||
@matches = []
|
||||
self.weights.sort_by{|x|[x.max]}.each do |weight|
|
||||
@upcomingMatches = weight.generateMatchups(@matches)
|
||||
@@ -22,16 +19,6 @@ class Tournament < ActiveRecord::Base
|
||||
end
|
||||
|
||||
|
||||
def generateMatches
|
||||
destroyAllMatches
|
||||
self.weights.each do |weight|
|
||||
weight.generatePool
|
||||
end
|
||||
# assignRound
|
||||
assignBouts
|
||||
end
|
||||
handle_asynchronously :generateMatches
|
||||
|
||||
def destroyAllMatches
|
||||
@matches_all = Match.where(tournament_id: self.id)
|
||||
@matches_all.each do |match|
|
||||
|
||||
@@ -4,21 +4,6 @@ class Weight < ActiveRecord::Base
|
||||
|
||||
attr_accessor :pools, :bracket_size, :bracket_type
|
||||
|
||||
def generatePool
|
||||
@wrestlers = Wrestler.where(weight_id: self.id)
|
||||
#@wrestlers.sort_by{|w| [w.original_seed]}
|
||||
if self.pools == 1
|
||||
@pool = Pool.new
|
||||
@pool.onePool(@wrestlers,self.id,self.tournament_id)
|
||||
elsif self.pools == 2
|
||||
@pool = Pool.new
|
||||
@pool.twoPools(@wrestlers,self.id,self.tournament_id)
|
||||
elsif self.pools == 4
|
||||
@pool = Pool.new
|
||||
@pool.fourPools(@wrestlers,self.id,self.tournament_id)
|
||||
end
|
||||
end
|
||||
|
||||
def pools
|
||||
@wrestlers = self.wrestlers
|
||||
if @wrestlers.size <= 6
|
||||
|
||||
@@ -14,8 +14,9 @@ class Wrestler < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
def boutByRound(round)
|
||||
@match = matches_all.select{|m| m.round == round}.first
|
||||
def boutByRound(round,matches)
|
||||
@matches = matches.select{|m| m.w1 == self.id || m.w2 == self.id}
|
||||
@match = @matches.select{|m| m.round == round}.first
|
||||
if @match.blank?
|
||||
return "BYE"
|
||||
else
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
<% @poolOneWrestlers.sort_by{|x|[x.original_seed]}.each do |w| %>
|
||||
<tr>
|
||||
<td><%= w.original_seed %> <%= w.name %> <%= w.season_win %>-<%= w.season_loss %> <%= w.school.name %></td>
|
||||
<td><%= w.boutByRound(1) %><br></td>
|
||||
<td><%= w.boutByRound(2) %></td>
|
||||
<td><%= w.boutByRound(3) %></td>
|
||||
<td><%= w.boutByRound(1,@matches) %><br></td>
|
||||
<td><%= w.boutByRound(2,@matches) %></td>
|
||||
<td><%= w.boutByRound(3,@matches) %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
@@ -35,9 +35,9 @@
|
||||
<% @poolTwoWrestlers.sort_by{|x|[x.original_seed]}.each do |w| %>
|
||||
<tr>
|
||||
<td><%= w.original_seed %> <%= w.name %> <%= w.season_win %>-<%= w.season_loss %> <%= w.school.name %></td>
|
||||
<td><%= w.boutByRound(1) %><br></td>
|
||||
<td><%= w.boutByRound(2) %></td>
|
||||
<td><%= w.boutByRound(3) %></td>
|
||||
<td><%= w.boutByRound(1,@matches) %><br></td>
|
||||
<td><%= w.boutByRound(2,@matches) %></td>
|
||||
<td><%= w.boutByRound(3,@matches) %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
@@ -58,9 +58,9 @@
|
||||
<% @poolThreeWrestlers.sort_by{|x|[x.original_seed]}.each do |w| %>
|
||||
<tr>
|
||||
<td><%= w.original_seed %> <%= w.name %> <%= w.season_win %>-<%= w.season_loss %> <%= w.school.name %></td>
|
||||
<td><%= w.boutByRound(1) %><br></td>
|
||||
<td><%= w.boutByRound(2) %></td>
|
||||
<td><%= w.boutByRound(3) %></td>
|
||||
<td><%= w.boutByRound(1,@matches) %><br></td>
|
||||
<td><%= w.boutByRound(2,@matches) %></td>
|
||||
<td><%= w.boutByRound(3,@matches) %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
@@ -81,9 +81,9 @@
|
||||
<% @poolFourWrestlers.sort_by{|x|[x.original_seed]}.each do |w| %>
|
||||
<tr>
|
||||
<td><%= w.original_seed %> <%= w.name %> <%= w.season_win %>-<%= w.season_loss %> <%= w.school.name %></td>
|
||||
<td><%= w.boutByRound(1) %><br></td>
|
||||
<td><%= w.boutByRound(2) %></td>
|
||||
<td><%= w.boutByRound(3) %></td>
|
||||
<td><%= w.boutByRound(1,@matches) %><br></td>
|
||||
<td><%= w.boutByRound(2,@matches) %></td>
|
||||
<td><%= w.boutByRound(3,@matches) %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
|
||||
@@ -14,11 +14,11 @@
|
||||
<% @poolOneWrestlers.each do |w| %>
|
||||
<tr>
|
||||
<td><%= w.original_seed %> <%= w.name %> <%= w.season_win %>-<%= w.season_loss %> <%= w.school.name %></td>
|
||||
<td><%= w.boutByRound(1) %><br>Result</td>
|
||||
<td><%= w.boutByRound(2) %></td>
|
||||
<td><%= w.boutByRound(3) %></td>
|
||||
<td><%= w.boutByRound(4) %></td>
|
||||
<td><%= w.boutByRound(5) %></td>
|
||||
<td><%= w.boutByRound(1,@matches) %><br>Result</td>
|
||||
<td><%= w.boutByRound(2,@matches) %></td>
|
||||
<td><%= w.boutByRound(3,@matches) %></td>
|
||||
<td><%= w.boutByRound(4,@matches) %></td>
|
||||
<td><%= w.boutByRound(5,@matches) %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
|
||||
@@ -13,10 +13,10 @@
|
||||
<% @poolOneWrestlers.sort_by{|x|[x.original_seed]}.each do |w| %>
|
||||
<tr>
|
||||
<td><%= w.original_seed %> <%= w.name %> <%= w.season_win %>-<%= w.season_loss %> <%= w.school.name %></td>
|
||||
<td><%= w.boutByRound(1) %><br></td>
|
||||
<td><%= w.boutByRound(2) %></td>
|
||||
<td><%= w.boutByRound(3) %></td>
|
||||
<td><%= w.boutByRound(4) %></td>
|
||||
<td><%= w.boutByRound(1,@matches) %><br></td>
|
||||
<td><%= w.boutByRound(2,@matches) %></td>
|
||||
<td><%= w.boutByRound(3,@matches) %></td>
|
||||
<td><%= w.boutByRound(4,@matches) %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
@@ -37,10 +37,10 @@
|
||||
<% @poolTwoWrestlers.sort_by{|x|[x.original_seed]}.each do |w| %>
|
||||
<tr>
|
||||
<td><%= w.original_seed %> <%= w.name %> <%= w.season_win %>-<%= w.season_loss %> <%= w.school.name %></td>
|
||||
<td><%= w.boutByRound(1) %><br></td>
|
||||
<td><%= w.boutByRound(2) %></td>
|
||||
<td><%= w.boutByRound(3) %></td>
|
||||
<td><%= w.boutByRound(4) %></td>
|
||||
<td><%= w.boutByRound(1,@matches) %><br></td>
|
||||
<td><%= w.boutByRound(2,@matches) %></td>
|
||||
<td><%= w.boutByRound(3,@matches) %></td>
|
||||
<td><%= w.boutByRound(4,@matches) %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
|
||||
Reference in New Issue
Block a user