mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-03-25 01:14:43 +00:00
Re-generating one weight classes matches - NEED TO REFACTOR and NEED TO WRITE TESTS
Code is repeated in the following classes: GenerateTournamentMatches PoolToBracketMatchGeneration PoolToBracketGenerateLoserNames WipeTournamentMatches
This commit is contained in:
@@ -2,6 +2,19 @@ class GenerateTournamentMatches
|
||||
def initialize( tournament )
|
||||
@tournament = tournament
|
||||
end
|
||||
|
||||
def generateWeight(weight)
|
||||
WipeTournamentMatches.new(@tournament).wipeWeightMatches(weight)
|
||||
@tournament.curently_generating_matches = 1
|
||||
@tournament.save
|
||||
unAssignBouts
|
||||
PoolToBracketMatchGeneration.new(@tournament).generatePoolToBracketMatchesWeight(weight) if @tournament.tournament_type == "Pool to bracket"
|
||||
postMatchCreationActions
|
||||
PoolToBracketGenerateLoserNames.new(@tournament).assignLoserNamesWeight(weight) if @tournament.tournament_type == "Pool to bracket"
|
||||
end
|
||||
if Rails.env.production?
|
||||
handle_asynchronously :generateWeight
|
||||
end
|
||||
|
||||
def generate
|
||||
standardStartingActions
|
||||
@@ -57,7 +70,13 @@ class GenerateTournamentMatches
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def unAssignBouts
|
||||
bout_counts = Hash.new(0)
|
||||
@tournament.matches.each do |m|
|
||||
m.bout_number = nil
|
||||
m.save!
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -3,6 +3,18 @@ class PoolToBracketGenerateLoserNames
|
||||
@tournament = tournament
|
||||
end
|
||||
|
||||
def assignLoserNamesWeight(weight)
|
||||
matches_by_weight = @tournament.matches.where(weight_id: weight.id)
|
||||
if weight.pool_bracket_type == "twoPoolsToSemi"
|
||||
twoPoolsToSemiLoser(matches_by_weight)
|
||||
elsif weight.pool_bracket_type == "fourPoolsToQuarter"
|
||||
fourPoolsToQuarterLoser(matches_by_weight)
|
||||
elsif weight.pool_bracket_type == "fourPoolsToSemi"
|
||||
fourPoolsToSemiLoser(matches_by_weight)
|
||||
end
|
||||
saveMatches(matches_by_weight)
|
||||
end
|
||||
|
||||
def assignLoserNames
|
||||
matches_by_weight = nil
|
||||
@tournament.weights.each do |w|
|
||||
|
||||
@@ -3,7 +3,13 @@ class PoolToBracketMatchGeneration
|
||||
@tournament = tournament
|
||||
end
|
||||
|
||||
|
||||
def generatePoolToBracketMatchesWeight(weight)
|
||||
PoolGeneration.new(weight).generatePools()
|
||||
last_match = @tournament.matches.where(weight: weight).order(round: :desc).limit(1).first
|
||||
highest_round = last_match.round
|
||||
PoolBracketGeneration.new(weight, highest_round).generateBracketMatches()
|
||||
setOriginalSeedsToWrestleLastPoolRound(weight)
|
||||
end
|
||||
|
||||
def generatePoolToBracketMatches
|
||||
@tournament.weights.order(:max).each do |weight|
|
||||
|
||||
@@ -9,6 +9,10 @@ class WipeTournamentMatches
|
||||
resetSchoolScores
|
||||
end
|
||||
|
||||
def wipeWeightMatches(weight)
|
||||
weight.matches.destroy_all
|
||||
end
|
||||
|
||||
def wipeMatches
|
||||
@tournament.matches.destroy_all
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user