From c855da0e6eb8831b5ab86629610ba80958b5b85b Mon Sep 17 00:00:00 2001 From: RJ Osborne Date: Mon, 25 May 2015 00:07:55 -0400 Subject: [PATCH] Ripped state out of Poolbracket Implicitly added tournament_id to matches generated by Poolbracket Removed explicit tournament assignment at save --- app/models/poolbracket.rb | 136 +++++++++++++++---------------- app/models/tournamentmatchgen.rb | 1 - 2 files changed, 66 insertions(+), 71 deletions(-) diff --git a/app/models/poolbracket.rb b/app/models/poolbracket.rb index 561b793..cf42bc2 100644 --- a/app/models/poolbracket.rb +++ b/app/models/poolbracket.rb @@ -1,80 +1,76 @@ class Poolbracket - def generateBracketMatches(matches,weight,highest_round) + def generateBracketMatches(matches, weight, highest_round) if weight.pool_bracket_type == "twoPoolsToSemi" - matches = twoPoolsToSemi(matches,weight,highest_round) + return twoPoolsToSemi(matches, weight, highest_round) elsif weight.pool_bracket_type == "twoPoolsToFinal" - matches = twoPoolsToFinal(matches,weight,highest_round) + return twoPoolsToFinal(matches, weight, highest_round) elsif weight.pool_bracket_type == "fourPoolsToQuarter" - matches = fourPoolsToQuarter(matches,weight,highest_round) + return fourPoolsToQuarter(matches, weight, highest_round) elsif weight.pool_bracket_type == "fourPoolsToSemi" - matches = fourPoolsToSemi(matches,weight,highest_round) + return fourPoolsToSemi(matches, weight, highest_round) end return matches end - - def twoPoolsToSemi(matches,weight,round) - @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) - @round = @round + 1 - @matches = matches.select{|m| m.weight_id == weight.id} - matches = createMatchup(matches,weight,@round,"","","1/2",1) - matches = createMatchup(matches,weight,@round,"","","3/4",1) - return matches - end - - def twoPoolsToFinal(matches,weight,round) - @round = round + 1 - matches = createMatchup(matches,weight,@round,"Winner Pool 1","Winner Pool 2","1/2",1) - matches = createMatchup(matches,weight,@round,"Runner Up Pool 1","Runner Up Pool 2","3/4",1) - return matches - end - - def fourPoolsToQuarter(matches,weight,round) - @round = round + 1 - matches = createMatchup(matches,weight,@round,"Winner Pool 1","Runner Up Pool 2","Quarter",1) - 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) - @round = @round + 1 - matches = createMatchup(matches,weight,@round,"","","Semis",1) - matches = createMatchup(matches,weight,@round,"","","Semis",2) - matches = createMatchup(matches,weight,@round,"","","Conso Semis",1) - matches = createMatchup(matches,weight,@round,"","","Conso Semis",2) - @round = @round + 1 - matches = createMatchup(matches,weight,@round,"","","1/2",1) - matches = createMatchup(matches,weight,@round,"","","3/4",1) - matches = createMatchup(matches,weight,@round,"","","5/6",1) - matches = createMatchup(matches,weight,@round,"","","7/8",1) - return matches - end - - def fourPoolsToSemi(matches,weight,round) - @round = round + 1 - matches = createMatchup(matches,weight,@round,"Winner Pool 1","Winner Pool 4","Semis",1) - 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) - @round = @round + 1 - matches = createMatchup(matches,weight,@round,"","","1/2",1) - matches = createMatchup(matches,weight,@round,"","","3/4",1) - matches = createMatchup(matches,weight,@round,"","","5/6",1) - matches = createMatchup(matches,weight,@round,"","","7/8",1) - return matches - end - - def createMatchup(matches,weight,round,w1_name,w2_name,bracket_position,bracket_position_number) - @match = Match.new - @match.loser1_name = w1_name - @match.loser2_name = w2_name - @match.weight_id = weight.id - @match.round = round - @match.bracket_position = bracket_position - @match.bracket_position_number = bracket_position_number - matches << @match - return matches - end - -end \ No newline at end of file + def twoPoolsToSemi(matches, weight, 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) + round += 1 + matches = matches.select{|m| m.weight_id == weight.id} + matches = createMatchup(matches, weight, round,"","","1/2",1) + matches = createMatchup(matches, weight, round,"","","3/4",1) + end + + def twoPoolsToFinal(matches,weight,round) + round += 1 + matches = createMatchup(matches, weight, round, "Winner Pool 1", "Winner Pool 2", "1/2", 1) + matches = createMatchup(matches, weight, round, "Runner Up Pool 1", "Runner Up Pool 2", "3/4", 1) + end + + def fourPoolsToQuarter(matches,weight,round) + round += 1 + matches = createMatchup(matches, weight, round, "Winner Pool 1", "Runner Up Pool 2", "Quarter", 1) + 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) + round += 1 + matches = createMatchup(matches, weight, round, "", "", "Semis", 1) + matches = createMatchup(matches, weight, round, "", "", "Semis", 2) + matches = createMatchup(matches, weight, round, "", "", "Conso Semis", 1) + matches = createMatchup(matches, weight, round, "", "", "Conso Semis", 2) + round += 1 + matches = createMatchup(matches, weight, round, "", "", "1/2", 1) + matches = createMatchup(matches, weight, round, "", "", "3/4", 1) + matches = createMatchup(matches, weight, round, "", "", "5/6", 1) + matches = createMatchup(matches, weight, round, "", "", "7/8", 1) + end + + def fourPoolsToSemi(matches,weight,round) + round += 1 + matches = createMatchup(matches, weight, round, "Winner Pool 1", "Winner Pool 4", "Semis", 1) + 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) + round += 1 + matches = createMatchup(matches, weight, round, "", "", "1/2", 1) + matches = createMatchup(matches, weight, round, "", "", "3/4", 1) + matches = createMatchup(matches, weight, round, "", "", "5/6", 1) + matches = createMatchup(matches, weight, round, "", "", "7/8", 1) + end + + def createMatchup(matches, weight, round, w1_name, w2_name, bracket_position, bracket_position_number) + tournament = weight.tournament + match = tournament.matches.create( + loser1_name: w1_name, + loser2_name: w2_name, + weight_id: weight.id, + round: round, + bracket_position: bracket_position, + bracket_position_number: bracket_position_number + ) + matches << match + end + +end diff --git a/app/models/tournamentmatchgen.rb b/app/models/tournamentmatchgen.rb index 8e8b47f..f28b107 100644 --- a/app/models/tournamentmatchgen.rb +++ b/app/models/tournamentmatchgen.rb @@ -44,7 +44,6 @@ class Tournamentmatchgen def saveMatches @tournament.save! @matches.each do |m| - m.tournament_id = @tournament.id m.save end end