1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-03-25 01:14:43 +00:00

Wrestler pool number is now saved in db. Pool number generation moved to it's own class.

This commit is contained in:
2017-03-02 18:11:21 +00:00
parent 8fa529dc5f
commit 3f72a912b6
12 changed files with 177 additions and 106 deletions

View File

@@ -6,7 +6,7 @@ class PoolAdvance
end
def advanceWrestler
if @wrestler.weight.allPoolMatchesFinished(@wrestler.generatePoolNumber) && @wrestler.finishedBracketMatches.size == 0
if @wrestler.weight.allPoolMatchesFinished(@wrestler.pool) && @wrestler.finishedBracketMatches.size == 0
poolToBracketAdvancment
end
if @wrestler.finishedBracketMatches.size > 0
@@ -15,7 +15,7 @@ class PoolAdvance
end
def poolToBracketAdvancment
pool = @wrestler.generatePoolNumber
pool = @wrestler.pool
if @wrestler.weight.wrestlers.size > 6
poolOrder = @wrestler.weight.poolOrder(pool)
#Take pool order and move winner and runner up to correct match based on w1_name and w2_name

View File

@@ -6,12 +6,13 @@ class PoolGeneration
end
def generatePools
GeneratePoolNumbers.new(@weight).savePoolNumbers
pools = @weight.pools
while @pool <= pools
roundRobin
@pool += 1
end
end
end
def roundRobin
wrestlers = @weight.wrestlersForPool(@pool)

View File

@@ -0,0 +1,77 @@
class GeneratePoolNumbers
def initialize( weight )
@weight = weight
end
def savePoolNumbers
if @weight.pools == 4
saveFourPoolNumbers(@weight.wrestlers)
elsif @weight.pools == 2
saveTwoPoolNumbers(@weight.wrestlers)
elsif @weight.pools == 1
saveOnePoolNumbers(@weight.wrestlers)
end
end
def saveOnePoolNumbers(poolWrestlers)
poolWrestlers.sort_by{|x| x.seed }.each do |w|
w.pool = 1
w.save
end
end
def saveTwoPoolNumbers(poolWrestlers)
pool = 1
poolWrestlers.sort_by{|x| x.seed }.reverse.each do |w|
if w.seed == 1
w.pool = 1
elsif w.seed == 2
w.pool = 2
elsif w.seed == 3
w.pool = 2
elsif w.seed == 4
w.pool = 1
else
w.pool = pool
end
if pool < 2
pool = pool + 1
else
pool = 1
end
w.save
end
end
def saveFourPoolNumbers(poolWrestlers)
pool = 1
poolWrestlers.sort_by{|x| x.seed }.reverse.each do |w|
if w.seed == 1
w.pool = 1
elsif w.seed == 2
w.pool = 2
elsif w.seed == 3
w.pool = 3
elsif w.seed == 4
w.pool = 4
elsif w.seed == 8
w.pool = 1
elsif w.seed == 7
w.pool = 2
elsif w.seed == 6
w.pool = 3
elsif w.seed == 5
w.pool = 4
else
w.pool = pool
end
if pool < 4
pool = pool + 1
else
pool = 1
end
w.save
end
end
end