mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-03-25 01:14:43 +00:00
Properly place wrestlers in the correct pool dynamically
This commit is contained in:
@@ -5,111 +5,35 @@ class GeneratePoolNumbers
|
|||||||
|
|
||||||
def savePoolNumbers
|
def savePoolNumbers
|
||||||
@weight.wrestlers.each do |wrestler|
|
@weight.wrestlers.each do |wrestler|
|
||||||
if wrestler.pool and (wrestler.pool) > (@weight.pools)
|
wrestler.pool = get_wrestler_pool_number(@weight.pools, wrestler.bracket_line)
|
||||||
resetPool
|
|
||||||
elsif @weight.one_pool_empty
|
|
||||||
resetPool
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if @weight.pools == 4
|
|
||||||
saveFourPoolNumbers(@weight.wrestlers_without_pool_assignment)
|
|
||||||
elsif @weight.pools == 2
|
|
||||||
saveTwoPoolNumbers(@weight.wrestlers_without_pool_assignment)
|
|
||||||
elsif @weight.pools == 1
|
|
||||||
saveOnePoolNumbers(@weight.wrestlers_without_pool_assignment)
|
|
||||||
elsif @weight.pools == 8
|
|
||||||
saveEightPoolNumbers(@weight.wrestlers_without_pool_assignment)
|
|
||||||
end
|
|
||||||
saveRandomPool(@weight.reload.wrestlers_without_pool_assignment)
|
|
||||||
end
|
|
||||||
|
|
||||||
def resetPool
|
|
||||||
@weight.wrestlers.each do |wrestler|
|
|
||||||
wrestler.pool = nil
|
|
||||||
wrestler.save
|
wrestler.save
|
||||||
@weight.reload
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def saveRandomPool(poolWrestlers)
|
def get_wrestler_pool_number(number_of_pools, wrestler_seed)
|
||||||
pool = 1
|
# Convert seed to zero-based index for easier math
|
||||||
poolWrestlers.sort_by{|x| x.bracket_line }.reverse.each do |wrestler|
|
zero_based = wrestler_seed - 1
|
||||||
wrestler.pool = pool
|
|
||||||
wrestler.save
|
# Determine which "row" we're on (0-based)
|
||||||
if pool < @weight.pools
|
# e.g., with 4 pools:
|
||||||
pool = pool + 1
|
# seeds 1..4 are in row 0,
|
||||||
|
# seeds 5..8 are in row 1,
|
||||||
|
# seeds 9..12 in row 2, etc.
|
||||||
|
row = zero_based / number_of_pools
|
||||||
|
|
||||||
|
# Column within that row (also 0-based)
|
||||||
|
col = zero_based % number_of_pools
|
||||||
|
|
||||||
|
if row.even?
|
||||||
|
# Row is even => left-to-right
|
||||||
|
# col=0 => pool 1, col=1 => pool 2, etc.
|
||||||
|
pool = col + 1
|
||||||
else
|
else
|
||||||
pool = 1
|
# Row is odd => right-to-left
|
||||||
end
|
# col=0 => pool number_of_pools, col=1 => pool number_of_pools-1, etc.
|
||||||
end
|
pool = number_of_pools - col
|
||||||
end
|
end
|
||||||
|
|
||||||
def saveOnePoolNumbers(poolWrestlers)
|
pool
|
||||||
poolWrestlers.sort_by{|x| x.bracket_line }.each do |w|
|
|
||||||
w.pool = 1
|
|
||||||
w.save
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
def saveTwoPoolNumbers(poolWrestlers)
|
|
||||||
poolWrestlers.sort_by{|x| x.bracket_line }.reverse.each do |w|
|
|
||||||
if w.bracket_line == 1
|
|
||||||
w.pool = 1
|
|
||||||
elsif w.bracket_line == 2
|
|
||||||
w.pool = 2
|
|
||||||
elsif w.bracket_line == 3
|
|
||||||
w.pool = 2
|
|
||||||
elsif w.bracket_line == 4
|
|
||||||
w.pool = 1
|
|
||||||
end
|
|
||||||
w.save
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def saveFourPoolNumbers(poolWrestlers)
|
|
||||||
poolWrestlers.sort_by{|x| x.bracket_line }.reverse.each do |w|
|
|
||||||
if w.bracket_line == 1
|
|
||||||
w.pool = 1
|
|
||||||
elsif w.bracket_line == 2
|
|
||||||
w.pool = 2
|
|
||||||
elsif w.bracket_line == 3
|
|
||||||
w.pool = 3
|
|
||||||
elsif w.bracket_line == 4
|
|
||||||
w.pool = 4
|
|
||||||
elsif w.bracket_line == 8
|
|
||||||
w.pool = 1
|
|
||||||
elsif w.bracket_line == 7
|
|
||||||
w.pool = 2
|
|
||||||
elsif w.bracket_line == 6
|
|
||||||
w.pool = 3
|
|
||||||
elsif w.bracket_line == 5
|
|
||||||
w.pool = 4
|
|
||||||
end
|
|
||||||
w.save
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def saveEightPoolNumbers(poolWrestlers)
|
|
||||||
poolWrestlers.sort_by{|x| x.bracket_line }.reverse.each do |w|
|
|
||||||
if w.bracket_line == 1
|
|
||||||
w.pool = 1
|
|
||||||
elsif w.bracket_line == 2
|
|
||||||
w.pool = 2
|
|
||||||
elsif w.bracket_line == 3
|
|
||||||
w.pool = 3
|
|
||||||
elsif w.bracket_line == 4
|
|
||||||
w.pool = 4
|
|
||||||
elsif w.bracket_line == 5
|
|
||||||
w.pool = 5
|
|
||||||
elsif w.bracket_line == 6
|
|
||||||
w.pool = 6
|
|
||||||
elsif w.bracket_line == 7
|
|
||||||
w.pool = 7
|
|
||||||
elsif w.bracket_line == 8
|
|
||||||
w.pool = 8
|
|
||||||
end
|
|
||||||
w.save
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Reference in New Issue
Block a user