1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-04-17 05:15:36 +00:00

Poolbracket does not keep a matches collection

This commit is contained in:
RJ Osborne
2015-05-25 00:45:31 -04:00
parent c855da0e6e
commit 20ef048f48
2 changed files with 73 additions and 67 deletions

View File

@@ -1,76 +1,80 @@
class Poolbracket class Poolbracket
def generateBracketMatches(matches, weight, highest_round) def initialize(weight, highest_round)
if weight.pool_bracket_type == "twoPoolsToSemi" @weight = weight
return twoPoolsToSemi(matches, weight, highest_round) @tournament = @weight.tournament
elsif weight.pool_bracket_type == "twoPoolsToFinal" @pool_bracket_type = @weight.pool_bracket_type
return twoPoolsToFinal(matches, weight, highest_round) @round = highest_round + 1
elsif weight.pool_bracket_type == "fourPoolsToQuarter" end
return fourPoolsToQuarter(matches, weight, highest_round)
elsif weight.pool_bracket_type == "fourPoolsToSemi"
return fourPoolsToSemi(matches, weight, highest_round)
end
return matches
end
def twoPoolsToSemi(matches, weight, round) def next_round
round += 1 @round += 1
matches = createMatchup(matches, weight, round, "Winner Pool 1", "Runner Up Pool 2", "Semis", 1) end
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) def generateBracketMatches()
round += 1 if @pool_bracket_type == "twoPoolsToSemi"
matches = createMatchup(matches, weight, round, "Winner Pool 1", "Winner Pool 2", "1/2", 1) return twoPoolsToSemi()
matches = createMatchup(matches, weight, round, "Runner Up Pool 1", "Runner Up Pool 2", "3/4", 1) elsif @pool_bracket_type == "twoPoolsToFinal"
return twoPoolsToFinal()
elsif @pool_bracket_type == "fourPoolsToQuarter"
return fourPoolsToQuarter()
elsif @pool_bracket_type == "fourPoolsToSemi"
return fourPoolsToSemi()
end end
return []
end
def fourPoolsToQuarter(matches,weight,round) def twoPoolsToSemi()
round += 1 createMatchup("Winner Pool 1", "Runner Up Pool 2", "Semis", 1)
matches = createMatchup(matches, weight, round, "Winner Pool 1", "Runner Up Pool 2", "Quarter", 1) createMatchup("Winner Pool 2", "Runner Up Pool 1", "Semis", 2)
matches = createMatchup(matches, weight, round, "Winner Pool 4", "Runner Up Pool 3", "Quarter", 2) next_round
matches = createMatchup(matches, weight, round, "Winner Pool 2", "Runner Up Pool 1", "Quarter", 3) createMatchup("","","1/2",1)
matches = createMatchup(matches, weight, round, "Winner Pool 3", "Runner Up Pool 4", "Quarter", 4) createMatchup("","","3/4",1)
round += 1 end
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) def twoPoolsToFinal()
round += 1 createMatchup("Winner Pool 1", "Winner Pool 2", "1/2", 1)
matches = createMatchup(matches, weight, round, "Winner Pool 1", "Winner Pool 4", "Semis", 1) createMatchup("Runner Up Pool 1", "Runner Up Pool 2", "3/4", 1)
matches = createMatchup(matches, weight, round, "Winner Pool 2", "Winner Pool 3", "Semis", 2) end
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) def fourPoolsToQuarter()
tournament = weight.tournament createMatchup("Winner Pool 1", "Runner Up Pool 2", "Quarter", 1)
match = tournament.matches.create( createMatchup("Winner Pool 4", "Runner Up Pool 3", "Quarter", 2)
loser1_name: w1_name, createMatchup("Winner Pool 2", "Runner Up Pool 1", "Quarter", 3)
loser2_name: w2_name, createMatchup("Winner Pool 3", "Runner Up Pool 4", "Quarter", 4)
weight_id: weight.id, next_round
round: round, createMatchup("", "", "Semis", 1)
bracket_position: bracket_position, createMatchup("", "", "Semis", 2)
bracket_position_number: bracket_position_number createMatchup("", "", "Conso Semis", 1)
) createMatchup("", "", "Conso Semis", 2)
matches << match next_round
end createMatchup("", "", "1/2", 1)
createMatchup("", "", "3/4", 1)
createMatchup("", "", "5/6", 1)
createMatchup("", "", "7/8", 1)
end
def fourPoolsToSemi()
createMatchup("Winner Pool 1", "Winner Pool 4", "Semis", 1)
createMatchup("Winner Pool 2", "Winner Pool 3", "Semis", 2)
createMatchup("Runner Up Pool 1", "Runner Up Pool 4", "Conso Semis", 1)
createMatchup("Runner Up Pool 2", "Runner Up Pool 3", "Conso Semis", 2)
next_round
createMatchup("", "", "1/2", 1)
createMatchup("", "", "3/4", 1)
createMatchup("", "", "5/6", 1)
createMatchup("", "", "7/8", 1)
end
def createMatchup(w1_name, w2_name, bracket_position, bracket_position_number)
@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
)
end
end end

View File

@@ -30,8 +30,10 @@ class Tournamentmatchgen
matches = Pool.new(weight).generatePools() matches = Pool.new(weight).generatePools()
last_match = matches.sort_by{|m| m.round}.last last_match = matches.sort_by{|m| m.round}.last
highest_round = last_match.round highest_round = last_match.round
@matches += Poolbracket.new.generateBracketMatches(matches, weight, highest_round) Poolbracket.new(weight, highest_round).generateBracketMatches()
end end
@tournament.save!
@matches = @tournament.matches
end end
def generateMatches def generateMatches