diff --git a/app/controllers/static_pages_controller.rb b/app/controllers/static_pages_controller.rb index 121f864..1072d0f 100644 --- a/app/controllers/static_pages_controller.rb +++ b/app/controllers/static_pages_controller.rb @@ -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 diff --git a/app/models/matchup.rb b/app/models/matchup.rb index 5d90671..c47e861 100644 --- a/app/models/matchup.rb +++ b/app/models/matchup.rb @@ -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 diff --git a/app/models/tournament.rb b/app/models/tournament.rb index e196260..6dff6ff 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -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| diff --git a/app/models/weight.rb b/app/models/weight.rb index 39617a1..c0f22f3 100644 --- a/app/models/weight.rb +++ b/app/models/weight.rb @@ -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 diff --git a/app/models/wrestler.rb b/app/models/wrestler.rb index 30a29f3..6817630 100644 --- a/app/models/wrestler.rb +++ b/app/models/wrestler.rb @@ -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 diff --git a/app/views/static_pages/_fourPool.html.erb b/app/views/static_pages/_fourPool.html.erb index 3ddd053..5e9ff68 100644 --- a/app/views/static_pages/_fourPool.html.erb +++ b/app/views/static_pages/_fourPool.html.erb @@ -12,9 +12,9 @@ <% @poolOneWrestlers.sort_by{|x|[x.original_seed]}.each do |w| %>