mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-04-01 20:25:26 +00:00
Fixed issue with wrestlers having a pool number higher than possible when bracket types change after deleting wrestlers
This commit is contained in:
@@ -90,6 +90,26 @@ class Weight < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
def pool_full(pool)
|
||||
current_wrestlers = wrestlers_in_pool(pool)
|
||||
if self.pool_bracket_type == "twoPoolsToSemi"
|
||||
max = 4
|
||||
elsif self.pool_bracket_type == "twoPoolsToFinal"
|
||||
max = 5
|
||||
elsif self.pool_bracket_type == "fourPoolsToQuarter"
|
||||
max = 3
|
||||
elsif self.pool_bracket_type == "fourPoolsToSemi"
|
||||
max = 4
|
||||
elsif self.pool_bracket_type == "eightPoolsToQuarter"
|
||||
max = 3
|
||||
end
|
||||
if max == current_wrestlers
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
def pool_rounds(matches)
|
||||
matchups = matches.select{|m| m.weight_id == self.id}
|
||||
pool_matches = matchups.select{|m| m.bracket_position == "Pool"}
|
||||
|
||||
@@ -4,6 +4,11 @@ class GeneratePoolNumbers
|
||||
end
|
||||
|
||||
def savePoolNumbers
|
||||
@weight.wrestlers.each do |wrestler|
|
||||
if wrestler.pool and (wrestler.pool) > (@weight.pools)
|
||||
resetPool
|
||||
end
|
||||
end
|
||||
if @weight.pools == 4
|
||||
saveFourPoolNumbers(@weight.wrestlers_without_pool_assignment)
|
||||
elsif @weight.pools == 2
|
||||
@@ -13,6 +18,28 @@ class GeneratePoolNumbers
|
||||
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)
|
||||
@@ -24,7 +51,6 @@ class GeneratePoolNumbers
|
||||
|
||||
|
||||
def saveTwoPoolNumbers(poolWrestlers)
|
||||
pool = 1
|
||||
poolWrestlers.sort_by{|x| x.bracket_line }.reverse.each do |w|
|
||||
if w.bracket_line == 1
|
||||
w.pool = 1
|
||||
@@ -34,20 +60,12 @@ class GeneratePoolNumbers
|
||||
w.pool = 2
|
||||
elsif w.bracket_line == 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.bracket_line }.reverse.each do |w|
|
||||
if w.bracket_line == 1
|
||||
w.pool = 1
|
||||
@@ -65,20 +83,12 @@ class GeneratePoolNumbers
|
||||
w.pool = 3
|
||||
elsif w.bracket_line == 5
|
||||
w.pool = 4
|
||||
else
|
||||
w.pool = pool
|
||||
end
|
||||
if pool < 4
|
||||
pool = pool + 1
|
||||
else
|
||||
pool = 1
|
||||
end
|
||||
w.save
|
||||
end
|
||||
end
|
||||
|
||||
def saveEightPoolNumbers(poolWrestlers)
|
||||
pool = 1
|
||||
poolWrestlers.sort_by{|x| x.bracket_line }.reverse.each do |w|
|
||||
if w.bracket_line == 1
|
||||
w.pool = 1
|
||||
@@ -96,13 +106,6 @@ class GeneratePoolNumbers
|
||||
w.pool = 7
|
||||
elsif w.bracket_line == 8
|
||||
w.pool = 8
|
||||
else
|
||||
w.pool = pool
|
||||
end
|
||||
if pool < 8
|
||||
pool = pool + 1
|
||||
else
|
||||
pool = 1
|
||||
end
|
||||
w.save
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user