From b61431930feb633b8fa8bfc2b4265ff288d32f56 Mon Sep 17 00:00:00 2001 From: Jacob Cody Wimer Date: Tue, 21 Apr 2015 21:15:44 -0400 Subject: [PATCH] Now naming loser of boutNumber in boutgen. Boutgen only run once now. --- app/models/boutgen.rb | 61 +++++++++++++++++++++++++++++++++++++-- app/models/poolbracket.rb | 47 +++++++----------------------- app/models/tournament.rb | 2 +- 3 files changed, 69 insertions(+), 41 deletions(-) diff --git a/app/models/boutgen.rb b/app/models/boutgen.rb index 942ac6c..f6a8be1 100644 --- a/app/models/boutgen.rb +++ b/app/models/boutgen.rb @@ -7,19 +7,74 @@ class Boutgen def giveBout(matches) @matches = matches.sort_by{|x|[x.weight_max]} @matches.each_with_index do |m, i| - bout = m.round * 1000 + i - m.boutNumber = bout + @bout = m.round * 1000 + i + m.boutNumber = @bout end return @matches end - def assignBouts(matches) + def assignBouts(matches,weights) @round = 1 until matchesByRound(@round, matches).blank? do @matches = matchesByRound(@round, matches) giveBout(@matches) @round += 1 end + assignLoserNames(matches,weights) return matches end + + def assignLoserNames(matches,weights) + weights.each do |w| + @matches = matches.select{|m| m.weight_id == w.id} + if w.pool_bracket_type == "twoPoolsToSemi" + twoPoolsToSemiLoser(@matches) + elsif w.pool_bracket_type == "fourPoolsToQuarter" + fourPoolsToQuarterLoser(@matches) + elsif w.pool_bracket_type == "fourPoolsToSemi" + fourPoolsToSemiLoser(@matches) + end + end + end + + def twoPoolsToSemiLoser(matches) + @match1 = matches.select{|m| m.w1_name == "Winner Pool 1"}.first + @match2 = matches.select{|m| m.w1_name == "Winner Pool 2"}.first + @matchChange = matches.select{|m| m.bracket_position == "3/4"}.first + @matchChange.w1_name = "Loser of #{@match1.boutNumber}" + @matchChange.w2_name = "Loser of #{@match2.boutNumber}" + end + + def fourPoolsToQuarterLoser(matches) + @quarters = matches.select{|m| m.bracket_position == "Quarter"} + @consoSemis = matches.select{|m| m.bracket_position == "Conso Semis"} + @semis = matches.select{|m| m.bracket_position == "Semis"} + @thirdFourth = matches.select{|m| m.bracket_position == "3/4"}.first + @seventhEighth = matches.select{|m| m.bracket_position == "7/8"}.first + @consoSemis.each do |match| + if match.bracket_position_number == 1 + match.w1_name = "Loser of #{@quarters.select{|m| m.bracket_position_number == 1}.first.boutNumber}" + match.w2_name = "Loser of #{@quarters.select{|m| m.bracket_position_number == 2}.first.boutNumber}" + elsif match.bracket_position_number == 2 + match.w1_name = "Loser of #{@quarters.select{|m| m.bracket_position_number == 3}.first.boutNumber}" + match.w2_name = "Loser of #{@quarters.select{|m| m.bracket_position_number == 4}.first.boutNumber}" + end + end + @thirdFourth.w1_name = "Loser of #{@semis.select{|m| m.bracket_position_number == 1}.first.boutNumber}" + @thirdFourth.w2_name = "Loser of #{@semis.select{|m| m.bracket_position_number == 2}.first.boutNumber}" + @consoSemis = matches.select{|m| m.bracket_position == "Conso Semis"} + @seventhEighth.w1_name = "Loser of #{@consoSemis.select{|m| m.bracket_position_number == 1}.first.boutNumber}" + @seventhEighth.w2_name = "Loser of #{@consoSemis.select{|m| m.bracket_position_number == 2}.first.boutNumber}" + end + + def fourPoolsToSemiLoser(matches) + @semis = matches.select{|m| m.bracket_position == "Semis"} + @thirdFourth = matches.select{|m| m.bracket_position == "3/4"}.first + @consoSemis = matches.select{|m| m.bracket_position == "Conso Semis"} + @seventhEighth = matches.select{|m| m.bracket_position == "7/8"}.first + @thirdFourth.w1_name = "Loser of #{@semis.select{|m| m.bracket_position_number == 1}.first.boutNumber}" + @thirdFourth.w2_name = "Loser of #{@semis.select{|m| m.bracket_position_number == 2}.first.boutNumber}" + @seventhEighth.w1_name = "Loser of #{@consoSemis.select{|m| m.bracket_position_number == 1}.first.boutNumber}" + @seventhEighth.w2_name = "Loser of #{@consoSemis.select{|m| m.bracket_position_number == 2}.first.boutNumber}" + end end \ No newline at end of file diff --git a/app/models/poolbracket.rb b/app/models/poolbracket.rb index 28d671a..a8edf76 100644 --- a/app/models/poolbracket.rb +++ b/app/models/poolbracket.rb @@ -17,13 +17,11 @@ class Poolbracket @round = round + 1 matches = createMatchup(matches,weight,@round,"Winner Pool 1","Runner Up Pool 2","Semis",1) matches = createMatchup(matches,weight,@round,"Winner Pool 2","Runner Up Pool 1","Semis",2) - matches = assignBouts(matches) @round = @round + 1 @matches = matches.select{|m| m.weight_id == weight.id} - @match1 = @matches.select{|m| m.w1_name == "Winner Pool 1"}.first - @match2 = @matches.select{|m| m.w1_name == "Winner Pool 2"}.first matches = createMatchup(matches,weight,@round,"","","1/2",1) - matches = createMatchup(matches,weight,@round,"Loser of #{@match1.boutNumber}","Loser of #{@match2.boutNumber}","3/4",1) + matches = createMatchup(matches,weight,@round,"","","3/4",1) + return matches end def twoPoolsToFinal(matches,weight,round) @@ -38,32 +36,17 @@ class Poolbracket matches = createMatchup(matches,weight,@round,"Winner Pool 4","Runner Up Pool 3","Quarter",2) matches = createMatchup(matches,weight,@round,"Winner Pool 2","Runner Up Pool 1","Quarter",3) matches = createMatchup(matches,weight,@round,"Winner Pool 3","Runner Up Pool 4","Quarter",4) - matches = assignBouts(matches) - @matches = matches.select{|m| m.weight_id == weight.id} - @match1 = @matches.select{|m| m.bracket_position_number == 1}.first - @match2 = @matches.select{|m| m.bracket_position_number == 2}.first - @match3 = @matches.select{|m| m.bracket_position_number == 3}.first - @match4 = @matches.select{|m| m.bracket_position_number == 4}.first @round = @round + 1 matches = createMatchup(matches,weight,@round,"","","Semis",1) matches = createMatchup(matches,weight,@round,"","","Semis",2) - matches = createMatchup(matches,weight,@round,"Loser of #{@match1.boutNumber}","Loser of #{@match2.boutNumber}","Conso Semis",1) - matches = createMatchup(matches,weight,@round,"Loser of #{@match3.boutNumber}","Loser of #{@match4.boutNumber}","Conso Semis",2) - matches = assignBouts(matches) - @matches = matches.select{|m| m.weight_id == weight.id} + matches = createMatchup(matches,weight,@round,"","","Conso Semis",1) + matches = createMatchup(matches,weight,@round,"","","Conso Semis",2) @round = @round + 1 - @match = @matches.select{|m| m.bracket_position == "Semis"} - @match1 = @match.select{|m|m.bracket_position_number == 1}.first - @match = @matches.select{|m| m.bracket_position == "Semis"} - @match2 = @match.select{|m|m.bracket_position_number == 2}.first matches = createMatchup(matches,weight,@round,"","","1/2",1) - matches = createMatchup(matches,weight,@round,"Loser of #{@match1.boutNumber}","Loser of #{@match2.boutNumber}","3/4",1) - @match = @matches.select{|m| m.bracket_position == "Conso Semis"} - @match1 = @match.select{|m|m.bracket_position_number == 1}.first - @match = @matches.select{|m| m.bracket_position == "Conso Semis"} - @match2 = @match.select{|m|m.bracket_position_number == 2}.first + matches = createMatchup(matches,weight,@round,"","","3/4",1) matches = createMatchup(matches,weight,@round,"","","5/6",1) - matches = createMatchup(matches,weight,@round,"Loser of #{@match1.boutNumber}","Loser of #{@match2.boutNumber}","7/8",1) + matches = createMatchup(matches,weight,@round,"","","7/8",1) + return matches end def fourPoolsToSemi(matches,weight,round) @@ -72,17 +55,11 @@ class Poolbracket matches = createMatchup(matches,weight,@round,"Winner Pool 2","Winner Pool 3","Semis",2) matches = createMatchup(matches,weight,@round,"Runner Up Pool 1","Runner Up Pool 4","Conso Semis",1) matches = createMatchup(matches,weight,@round,"Runner Up Pool 2","Runner Up Pool 3","Conso Semis",2) - matches = assignBouts(matches) @round = @round + 1 - @matches = matches.select{|m| m.weight_id == weight.id} matches = createMatchup(matches,weight,@round,"","","1/2",1) - @match1 = @matches.select{|m| m.w1_name == "Winner Pool 1"}.first - @match2 = @matches.select{|m| m.w1_name == "Winner Pool 2"}.first - matches = createMatchup(matches,weight,@round,"Loser of #{@match1.boutNumber}","Loser of #{@match2.boutNumber}","3/4",1) + matches = createMatchup(matches,weight,@round,"","","3/4",1) matches = createMatchup(matches,weight,@round,"","","5/6",1) - @match1 = @matches.select{|m| m.w1_name == "Runner Up Pool 1"}.first - @match2 = @matches.select{|m| m.w1_name == "Runner Up Pool 2"}.first - matches = createMatchup(matches,weight,@round,"Loser of #{@match1.boutNumber}","Loser of #{@match2.boutNumber}","7/8",1) + matches = createMatchup(matches,weight,@round,"","","7/8",1) return matches end @@ -99,9 +76,5 @@ class Poolbracket return matches end - def assignBouts(matches) - @bouts = Boutgen.new - @matches = @bouts.assignBouts(matches) - return @matches - end + end \ No newline at end of file diff --git a/app/models/tournament.rb b/app/models/tournament.rb index 027bc1e..46c436c 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -29,7 +29,7 @@ class Tournament < ActiveRecord::Base def assignBouts(matches) @bouts = Boutgen.new - @matches = @bouts.assignBouts(matches) + @matches = @bouts.assignBouts(matches,self.weights) return @matches end