1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-04-06 14:36:59 +00:00

Moved match generation to a class and added tournament_type to tournaments.

This commit is contained in:
2015-04-27 13:54:57 -04:00
parent 61d1240f0b
commit 37470d9602
12 changed files with 69 additions and 42 deletions

View File

@@ -28,6 +28,7 @@ class Poolbracket
@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)

View File

@@ -5,48 +5,31 @@ class Tournament < ActiveRecord::Base
has_many :wrestlers, through: :weights
def tournament_types
["Pool to bracket"]
end
def matches
@matches = Match.where(tournament_id: self.id)
end
def upcomingMatches
if matches.nil?
return matches
else
@matches = generateMatchups
saveMatchups(@matches)
return @matches
generateMatchups
return matches
end
end
def generateMatchups
destroyAllMatches
@matches = []
self.weights.map.sort_by{|x|[x.max]}.each do |weight|
@matches = weight.generateMatchups(@matches)
end
@matches = assignBouts(@matches)
@matches = Losernamegen.new.assignLoserNames(@matches,self.weights)
return @matches
end
def assignBouts(matches)
@bouts = Boutgen.new
@matches = @bouts.assignBouts(matches,self.weights)
return @matches
end
def saveMatchups(matches)
matches.each do |m|
m.tournament_id = self.id
m.save
end
@matches = Tournamentmatchgen.new.genMatches(self)
end
def destroyAllMatches
matches.each do |m|
m.destroy
end
matches.destroy_all
end
end

View File

@@ -0,0 +1,33 @@
class Tournamentmatchgen
def genMatches(tournament)
if tournament.tournament_type == "Pool to bracket"
@matches = poolToBracket(tournament)
end
return @matches
end
def poolToBracket(tournament)
tournament.destroyAllMatches
@matches = []
tournament.weights.sort_by{|x|[x.max]}.each do |w|
@wrestlers = w.wrestlers
@matches = Pool.new.generatePools(w.pools,@wrestlers,w,tournament.id,@matches)
@weight_matches = @matches.select{|m|m.weight_id == w.id}
@last_match = @weight_matches.sort_by{|m| m.round}.last
@highest_round = @last_match.round
@matches = Poolbracket.new.generateBracketMatches(@matches,w,@highest_round)
end
@matches = Boutgen.new.assignBouts(@matches,tournament.weights)
@matches = Losernamegen.new.assignLoserNames(@matches,tournament.weights)
saveMatches(tournament,@matches)
return @matches
end
def saveMatches(tournament,matches)
matches.each do |m|
m.tournament_id = tournament.id
m.save
end
end
end

View File

@@ -101,18 +101,6 @@ class Weight < ActiveRecord::Base
return "fourPoolsToSemi"
end
end
def generateMatchups(matches)
@wrestlers = self.wrestlers
@pool = Pool.new
@matches = @pool.generatePools(self.pools,@wrestlers,self,self.tournament_id,matches)
@weight_matches = @matches.select{|m|m.weight_id == self.id}
@last_match = @weight_matches.sort_by{|m| m.round}.last
@highest_round = @last_match.round
@bracket = Poolbracket.new
@matches = @bracket.generateBracketMatches(@matches,self,@highest_round)
return @matches
end
def poolRounds(matches)
@matchups = matches.select{|m| m.weight_id == self.id}