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

Moved poolNumber generation to weight.

This commit is contained in:
2015-03-17 09:06:21 -04:00
parent d6a9abffac
commit c86f678fd1
7 changed files with 98 additions and 71 deletions

View File

@@ -1,69 +1,16 @@
class Pool
def onePool(wrestlers,weight,tournament,matches)
wrestlers.sort_by{|x|[x.original_seed]}.each do |w|
w.poolNumber = 1
end
matches = roundRobin(1,tournament,weight,matches,wrestlers)
return matches
end
def twoPools(wrestlers,weight,tournament,matches)
pool = 1
wrestlers.sort_by{|x|[x.original_seed]}.reverse.each do |w|
if w.original_seed == 1
w.poolNumber = 1
elsif w.original_seed == 2
w.poolNumber = 2
elsif w.original_seed == 3
w.poolNumber = 2
elsif w.original_seed == 4
w.poolNumber = 1
else
w.poolNumber = pool
end
if pool < 2
pool = pool + 1
else
pool =1
end
end
matches = roundRobin(1,tournament,weight,matches,wrestlers)
matches = roundRobin(2,tournament,weight,matches,wrestlers)
return matches
end
def fourPools(wrestlers,weight,tournament,matches)
def generatePools(pools,wrestlers,weight,tournament,matches)
@pools = pools
@pool = 1
wrestlers.sort_by{|x|[x.original_seed]}.reverse.each do |w|
if w.original_seed == 3
w.poolNumber = 3
elsif w.original_seed == 4
w.poolNumber = 4
elsif w.original_seed == 1
w.poolNumber = 1
elsif w.original_seed == 2
w.poolNumber = 2
else
w.poolNumber = @pool
end
if @pool < 4
@pool = @pool + 1
else
@pool =1
end
while @pool <= @pools
matches = roundRobin(@pool,wrestlers,weight,tournament,matches)
@pool = @pool +1
end
matches = roundRobin(1,tournament,weight,matches,wrestlers)
matches = roundRobin(2,tournament,weight,matches,wrestlers)
matches = roundRobin(3,tournament,weight,matches,wrestlers)
matches = roundRobin(4,tournament,weight,matches,wrestlers)
return matches
end
def roundRobin(pool,tournament_id,weight,matches,wrestlers)
@wrestlers = wrestlers.select{|w| w.poolNumber == pool}.to_a
def roundRobin(pool,wrestlers,weight,tournament,matches)
@wrestlers = wrestlers.select{|w| w.generatePoolNumber == pool}.to_a
@poolMatches = RoundRobinTournament.schedule(@wrestlers).reverse
@poolMatches.each_with_index do |b,index|
@bout = b.map

View File

@@ -15,6 +15,73 @@ class Weight < ActiveRecord::Base
end
end
def returnPoolNumber(wrestler)
if self.pools == 4
@wrestlers = fourPoolNumbers(self.wrestlers)
elsif self.pools == 2
@wrestlers = twoPoolNumbers(self.wrestlers)
elsif self.pools == 1
@wrestlers = onePoolNumbers(self.wrestlers)
end
@wrestler = @wrestlers.select{|w| w.id == wrestler.id}.first
return @wrestler.poolNumber
end
def fourPoolNumbers(wrestlers)
@pool = 1
wrestlers.sort_by{|x|[x.original_seed]}.reverse.each do |w|
if w.original_seed == 3
w.poolNumber = 3
elsif w.original_seed == 4
w.poolNumber = 4
elsif w.original_seed == 1
w.poolNumber = 1
elsif w.original_seed == 2
w.poolNumber = 2
else
w.poolNumber = @pool
end
if @pool < 4
@pool = @pool + 1
else
@pool =1
end
end
return wrestlers
end
def onePoolNumbers(wrestlers)
wrestlers.sort_by{|x|[x.original_seed]}.each do |w|
w.poolNumber = 1
end
return wrestlers
end
def twoPoolNumbers(wrestlers)
pool = 1
wrestlers.sort_by{|x|[x.original_seed]}.reverse.each do |w|
if w.original_seed == 1
w.poolNumber = 1
elsif w.original_seed == 2
w.poolNumber = 2
elsif w.original_seed == 3
w.poolNumber = 2
elsif w.original_seed == 4
w.poolNumber = 1
else
w.poolNumber = pool
end
if pool < 2
pool = pool + 1
else
pool =1
end
end
return wrestlers
end
def bracket_size
@wrestlers = Wrestler.where(weight_id: self.id)
return @wrestlers.size
@@ -35,16 +102,15 @@ class Weight < ActiveRecord::Base
def generateMatchups(matches)
@wrestlers = self.wrestlers
#@wrestlers.sort_by{|w| [w.original_seed]}
if self.pools == 1
@pool = Pool.new
@matches = @pool.onePool(@wrestlers,self,self.tournament_id,matches)
@matches = @pool.generatePools(1,@wrestlers,self,self.tournament_id,matches)
elsif self.pools == 2
@pool = Pool.new
@matches = @pool.twoPools(@wrestlers,self,self.tournament_id,matches)
@matches = @pool.generatePools(2,@wrestlers,self,self.tournament_id,matches)
elsif self.pools == 4
@pool = Pool.new
@matches = @pool.fourPools(@wrestlers,self,self.tournament_id,matches)
@matches = @pool.generatePools(4,@wrestlers,self,self.tournament_id,matches)
end
return @matches
end

View File

@@ -1,7 +1,7 @@
class Wrestler < ActiveRecord::Base
belongs_to :school
belongs_to :weight
attr_accessor :matches_all, :isWrestlingThisRound, :boutByRound, :seasonWinPercentage
attr_accessor :matches_all, :isWrestlingThisRound, :boutByRound, :seasonWinPercentage, :poolNumber
def isWrestlingThisRound(matchRound)
@gMatches = Match.where(g_id: self.id, round: matchRound)
@@ -14,6 +14,11 @@ class Wrestler < ActiveRecord::Base
end
end
def generatePoolNumber
@pool = self.weight.returnPoolNumber(self)
return @pool
end
def boutByRound(round,matches)
@matches = matches.select{|m| m.w1 == self.id || m.w2 == self.id}
@match = @matches.select{|m| m.round == round}.first