1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-04-07 06:54:16 +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:
2019-01-19 16:18:20 +00:00
parent 30dc645375
commit 4eb75d45d3
3 changed files with 74 additions and 24 deletions

View File

@@ -90,6 +90,26 @@ class Weight < ActiveRecord::Base
end end
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) def pool_rounds(matches)
matchups = matches.select{|m| m.weight_id == self.id} matchups = matches.select{|m| m.weight_id == self.id}
pool_matches = matchups.select{|m| m.bracket_position == "Pool"} pool_matches = matchups.select{|m| m.bracket_position == "Pool"}

View File

@@ -4,6 +4,11 @@ class GeneratePoolNumbers
end end
def savePoolNumbers def savePoolNumbers
@weight.wrestlers.each do |wrestler|
if wrestler.pool and (wrestler.pool) > (@weight.pools)
resetPool
end
end
if @weight.pools == 4 if @weight.pools == 4
saveFourPoolNumbers(@weight.wrestlers_without_pool_assignment) saveFourPoolNumbers(@weight.wrestlers_without_pool_assignment)
elsif @weight.pools == 2 elsif @weight.pools == 2
@@ -13,6 +18,28 @@ class GeneratePoolNumbers
elsif @weight.pools == 8 elsif @weight.pools == 8
saveEightPoolNumbers(@weight.wrestlers_without_pool_assignment) saveEightPoolNumbers(@weight.wrestlers_without_pool_assignment)
end 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 end
def saveOnePoolNumbers(poolWrestlers) def saveOnePoolNumbers(poolWrestlers)
@@ -24,7 +51,6 @@ class GeneratePoolNumbers
def saveTwoPoolNumbers(poolWrestlers) def saveTwoPoolNumbers(poolWrestlers)
pool = 1
poolWrestlers.sort_by{|x| x.bracket_line }.reverse.each do |w| poolWrestlers.sort_by{|x| x.bracket_line }.reverse.each do |w|
if w.bracket_line == 1 if w.bracket_line == 1
w.pool = 1 w.pool = 1
@@ -34,20 +60,12 @@ class GeneratePoolNumbers
w.pool = 2 w.pool = 2
elsif w.bracket_line == 4 elsif w.bracket_line == 4
w.pool = 1 w.pool = 1
else
w.pool = pool
end
if pool < 2
pool = pool + 1
else
pool = 1
end end
w.save w.save
end end
end end
def saveFourPoolNumbers(poolWrestlers) def saveFourPoolNumbers(poolWrestlers)
pool = 1
poolWrestlers.sort_by{|x| x.bracket_line }.reverse.each do |w| poolWrestlers.sort_by{|x| x.bracket_line }.reverse.each do |w|
if w.bracket_line == 1 if w.bracket_line == 1
w.pool = 1 w.pool = 1
@@ -65,20 +83,12 @@ class GeneratePoolNumbers
w.pool = 3 w.pool = 3
elsif w.bracket_line == 5 elsif w.bracket_line == 5
w.pool = 4 w.pool = 4
else
w.pool = pool
end
if pool < 4
pool = pool + 1
else
pool = 1
end end
w.save w.save
end end
end end
def saveEightPoolNumbers(poolWrestlers) def saveEightPoolNumbers(poolWrestlers)
pool = 1
poolWrestlers.sort_by{|x| x.bracket_line }.reverse.each do |w| poolWrestlers.sort_by{|x| x.bracket_line }.reverse.each do |w|
if w.bracket_line == 1 if w.bracket_line == 1
w.pool = 1 w.pool = 1
@@ -96,13 +106,6 @@ class GeneratePoolNumbers
w.pool = 7 w.pool = 7
elsif w.bracket_line == 8 elsif w.bracket_line == 8
w.pool = 8 w.pool = 8
else
w.pool = pool
end
if pool < 8
pool = pool + 1
else
pool = 1
end end
w.save w.save
end end

View File

@@ -0,0 +1,27 @@
require 'test_helper'
class EightPoolToFourPoolChangesTest < ActionDispatch::IntegrationTest
def setup
@tournament = Tournament.find(4)
end
test "All wrestlers get matches after a weight switches from 8 pool to 4 pool" do
GenerateTournamentMatches.new(@tournament).generate
assert @tournament.matches.count == 36
assert @tournament.weights.first.pools == 8
count = 1
@tournament.reload.weights.first.wrestlers.sort_by{|wrestler| wrestler.pool}.each do |wrestler|
if count <= 8
wrestler.destroy
count = count + 1
end
end
GenerateTournamentMatches.new(@tournament.reload).generate
assert @tournament.matches.count == 32
assert @tournament.weights.first.pools == 4
@tournament.reload.weights.first.wrestlers.each do |wrestler|
assert wrestler.pool <= 4
assert wrestler.all_matches.count > 0
end
end
end