diff --git a/app/models/matchup.rb b/app/models/matchup.rb index 69d23e7..5d90671 100644 --- a/app/models/matchup.rb +++ b/app/models/matchup.rb @@ -1,5 +1,5 @@ class Matchup - attr_accessor :w1, :w2, :round, :weight_id, :boutNumber + attr_accessor :w1, :w2, :round, :weight_id, :boutNumber, :w1_name, :w2_name # def w1 # end @@ -14,13 +14,8 @@ class Matchup # end def weight_max - @wrestler = Wrestler.find(self.w1) - @weight = Weight.find(@wrestler.weight_id) + @weight = Weight.find(self.weight_id) return @weight.max end - def w_name(id) - @wrestler = Wrestler.find(id) - return @wrestler.name - end end \ No newline at end of file diff --git a/app/models/pool.rb b/app/models/pool.rb index af6b1c7..43a3b6e 100644 --- a/app/models/pool.rb +++ b/app/models/pool.rb @@ -1,27 +1,23 @@ class Pool - def onePool(wrestlers,weight_id,tournament,matches) + def onePool(wrestlers,weight,tournament,matches) wrestlers.sort_by{|x|[x.original_seed]}.each do |w| w.poolNumber = 1 - w.save end - matches = roundRobin(1,tournament,weight_id,matches) + matches = roundRobin(1,tournament,weight,matches,wrestlers) return matches end - def twoPools(wrestlers,weight_id,tournament,matches) + def twoPools(wrestlers,weight,tournament,matches) pool = 1 wrestlers.sort_by{|x|[x.original_seed]}.reverse.each do |w| if w.original_seed == 3 w.poolNumber = 2 - w.save elsif w.original_seed == 4 w.poolNumber = 1 - w.save else w.poolNumber = pool - w.save end if pool < 2 pool = pool + 1 @@ -29,30 +25,25 @@ class Pool pool =1 end end - matches = roundRobin(1,tournament,weight_id,matches) - matches = roundRobin(2,tournament,weight_id,matches) + matches = roundRobin(1,tournament,weight,matches,wrestlers) + matches = roundRobin(2,tournament,weight,matches,wrestlers) return matches end - def fourPools(wrestlers,weight_id,tournament,matches) + def fourPools(wrestlers,weight,tournament,matches) @pool = 1 wrestlers.sort_by{|x|[x.original_seed]}.reverse.each do |w| if w.original_seed == 3 w.poolNumber = 3 - w.save elsif w.original_seed == 4 w.poolNumber = 4 - w.save elsif w.original_seed == 1 w.poolNumber = 1 - w.save elsif w.original_seed == 2 w.poolNumber = 2 - w.save else w.poolNumber = @pool - w.save end if @pool < 4 @pool = @pool + 1 @@ -60,15 +51,15 @@ class Pool @pool =1 end end - matches = roundRobin(1,tournament,weight_id,matches) - matches = roundRobin(2,tournament,weight_id,matches) - matches = roundRobin(3,tournament,weight_id,matches) - matches = roundRobin(4,tournament,weight_id,matches) + matches = roundRobin(1,tournament,weight,matches,wrestlers) + matches = roundRobin(2,tournament,weight,matches,wrestlers) + matches = roundRobin(3,tournament,weight,matches,wrestlers) + matches = roundRobin(4,tournament,weight,matches,wrestlers) return matches end - def roundRobin(pool,tournament_id,weight_id,matches) - @wrestlers = Wrestler.where(weight_id: weight_id, poolNumber: pool).to_a + def roundRobin(pool,tournament_id,weight,matches,wrestlers) + @wrestlers = wrestlers.to_a @poolMatches = RoundRobinTournament.schedule(@wrestlers).reverse @poolMatches.each_with_index do |b,index| @bout = b.map @@ -76,9 +67,11 @@ class Pool if b[0] != nil and b[1] != nil @match = Matchup.new @match.w1 = b[0].id + @match.w1_name = b[0].name @match.w2 = b[1].id + @match.w2_name = b[1].name + @match.weight_id = weight.id @match.round = index + 1 - matches << @match end end diff --git a/app/models/weight.rb b/app/models/weight.rb index 2c106ae..39617a1 100644 --- a/app/models/weight.rb +++ b/app/models/weight.rb @@ -20,7 +20,7 @@ class Weight < ActiveRecord::Base end def pools - @wrestlers = Wrestler.where(weight_id: self.id) + @wrestlers = self.wrestlers if @wrestlers.size <= 6 self.pools = 1 elsif (@wrestlers.size > 6) && (@wrestlers.size <= 10) @@ -49,17 +49,17 @@ class Weight < ActiveRecord::Base end def generateMatchups(matches) - @wrestlers = Wrestler.where(weight_id: self.id) + @wrestlers = self.wrestlers #@wrestlers.sort_by{|w| [w.original_seed]} if self.pools == 1 @pool = Pool.new - @matches = @pool.onePool(@wrestlers,self.id,self.tournament_id,matches) + @matches = @pool.onePool(@wrestlers,self,self.tournament_id,matches) elsif self.pools == 2 @pool = Pool.new - @matches = @pool.twoPools(@wrestlers,self.id,self.tournament_id,matches) + @matches = @pool.twoPools(@wrestlers,self,self.tournament_id,matches) elsif self.pools == 4 @pool = Pool.new - @matches = @pool.fourPools(@wrestlers,self.id,self.tournament_id,matches) + @matches = @pool.fourPools(@wrestlers,self,self.tournament_id,matches) end return @matches end diff --git a/app/views/static_pages/up_matches.html.erb b/app/views/static_pages/up_matches.html.erb index 52a5dff..14614db 100644 --- a/app/views/static_pages/up_matches.html.erb +++ b/app/views/static_pages/up_matches.html.erb @@ -20,7 +20,7 @@