1
0
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:
2025-02-10 13:26:25 -05:00
parent 63b91f7ddd
commit 934b34d0b7

View File

@@ -5,111 +5,35 @@ class GeneratePoolNumbers
def savePoolNumbers
@weight.wrestlers.each do |wrestler|
if wrestler.pool and (wrestler.pool) > (@weight.pools)
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
@weight.reload
end
end
def saveRandomPool(poolWrestlers)
pool = 1
poolWrestlers.sort_by{|x| x.bracket_line }.reverse.each do |wrestler|
wrestler.pool = pool
wrestler.save
if pool < @weight.pools
pool = pool + 1
else
pool = 1
end
end
end
def saveOnePoolNumbers(poolWrestlers)
poolWrestlers.sort_by{|x| x.bracket_line }.each do |w|
w.pool = 1
w.save
wrestler.pool = get_wrestler_pool_number(@weight.pools, wrestler.bracket_line)
wrestler.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
def get_wrestler_pool_number(number_of_pools, wrestler_seed)
# Convert seed to zero-based index for easier math
zero_based = wrestler_seed - 1
# Determine which "row" we're on (0-based)
# e.g., with 4 pools:
# 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
# Row is odd => right-to-left
# col=0 => pool number_of_pools, col=1 => pool number_of_pools-1, etc.
pool = number_of_pools - col
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
pool
end
end