1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-03-25 01:14:43 +00:00
Files
wrestlingdev.com/app/models/generates_tournament_matches.rb
2015-12-30 16:21:56 +00:00

51 lines
1.2 KiB
Ruby

module GeneratesTournamentMatches
def generateMatchups
resetSchoolScores
setSeedsAndRandomSeedingWrestlersWithoutSeeds
poolToBracket() if tournament_type == "Pool to bracket"
matches
end
if Rails.env.production?
handle_asynchronously :generateMatchups
end
def poolToBracket
destroyAllMatches
buildTournamentWeights
generateMatches
end
def buildTournamentWeights
weights.order(:max).each do |weight|
Pool.new(weight).generatePools()
last_match = matches.where(weight: weight).order(round: :desc).limit(1).first
highest_round = last_match.round
PoolBracket.new(weight, highest_round).generateBracketMatches()
end
end
def generateMatches
moveFinalsMatchesToLastRound
assignBouts
assignLoserNames
assignFirstMatchesToMats
end
def moveFinalsMatchesToLastRound
finalsRound = self.totalRounds
finalsMatches = self.matches.select{|m| m.bracket_position == "1/2" || m.bracket_position == "3/4" || m.bracket_position == "5/6" || m.bracket_position == "7/8"}
finalsMatches. each do |m|
m.round = finalsRound
m.save
end
end
def setSeedsAndRandomSeedingWrestlersWithoutSeeds
weights.each do |w|
w.setSeeds
end
end
end