mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-03-25 01:14:43 +00:00
Fixed bug with pool to bracket advancement. This bug was conceived due to the removing of tests and logic when making pool and pool_placement database fields.
This commit is contained in:
@@ -20,6 +20,7 @@ class Match < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
BRACKET_POSITIONS = ["Pool","1/2","3/4","5/6","7/8","Quarter","Semis","Conso Semis"]
|
||||||
WIN_TYPES = ["Decision", "Major", "Tech Fall", "Pin", "Forfeit", "Injury Default", "Default", "DQ"]
|
WIN_TYPES = ["Decision", "Major", "Tech Fall", "Pin", "Forfeit", "Injury Default", "Default", "DQ"]
|
||||||
|
|
||||||
def calculate_school_points
|
def calculate_school_points
|
||||||
@@ -29,6 +30,13 @@ class Match < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def wrestler_in_match(wrestler)
|
||||||
|
if self.w1 == wrestler.id or self.w2 == wrestler.id
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def mat_assigned
|
def mat_assigned
|
||||||
if self.mat
|
if self.mat
|
||||||
|
|||||||
@@ -48,8 +48,8 @@ class Weight < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def all_pool_matches_finished(pool)
|
def all_pool_matches_finished(pool)
|
||||||
@wrestlers = wrestlers_in_pool(pool)
|
wrestlers = wrestlers_in_pool(pool)
|
||||||
@wrestlers.each do |w|
|
wrestlers.each do |w|
|
||||||
if w.pool_matches.size != w.finished_pool_matches.size
|
if w.pool_matches.size != w.finished_pool_matches.size
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
@@ -58,14 +58,14 @@ class Weight < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def pools
|
def pools
|
||||||
@wrestlers = self.wrestlers
|
wrestlers = self.wrestlers
|
||||||
if @wrestlers.size <= 6
|
if wrestlers.size <= 6
|
||||||
self.pools = 1
|
self.pools = 1
|
||||||
elsif (@wrestlers.size > 6) && (@wrestlers.size <= 10)
|
elsif (wrestlers.size > 6) && (wrestlers.size <= 10)
|
||||||
self.pools = 2
|
self.pools = 2
|
||||||
elsif (@wrestlers.size > 10) && (@wrestlers.size <= 16)
|
elsif (wrestlers.size > 10) && (wrestlers.size <= 16)
|
||||||
self.pools = 4
|
self.pools = 4
|
||||||
elsif (@wrestlers.size > 16) && (@wrestlers.size <= 24)
|
elsif (wrestlers.size > 16) && (wrestlers.size <= 24)
|
||||||
self.pools = 8
|
self.pools = 8
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -17,12 +17,10 @@ class AdvanceWrestler
|
|||||||
end
|
end
|
||||||
|
|
||||||
def pool_to_bracket_advancement
|
def pool_to_bracket_advancement
|
||||||
if @wrestler.weight.all_pool_matches_finished(@wrestler.pool) and (@wrestler.finished_bracket_matches.size == 0 or @wrestler.weight.pools == 1)
|
if @wrestler.weight.all_pool_matches_finished(@wrestler.pool) and (@wrestler.finished_bracket_matches.size < 1)
|
||||||
PoolOrder.new(@wrestler.weight.wrestlers_in_pool(@wrestler.pool)).getPoolOrder
|
PoolOrder.new(@wrestler.weight.wrestlers_in_pool(@wrestler.pool)).getPoolOrder
|
||||||
end
|
end
|
||||||
if @wrestler.weight.all_pool_matches_finished(@wrestler.pool)
|
PoolAdvance.new(@wrestler).advanceWrestler
|
||||||
PoolAdvance.new(@wrestler,@wrestler.last_match).advanceWrestler
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
class PoolAdvance
|
class PoolAdvance
|
||||||
|
|
||||||
def initialize(wrestler,previousMatch)
|
def initialize(wrestler)
|
||||||
@wrestler = wrestler
|
@wrestler = wrestler
|
||||||
@previousMatch = previousMatch
|
@last_match = @wrestler.last_match
|
||||||
end
|
end
|
||||||
|
|
||||||
def advanceWrestler
|
def advanceWrestler
|
||||||
if @wrestler.pool_placement and @wrestler.weight.pools > 1
|
if @wrestler.weight.pools > 1 and @wrestler.finished_bracket_matches.size < 1
|
||||||
poolToBracketAdvancment
|
poolToBracketAdvancment
|
||||||
end
|
end
|
||||||
if @wrestler.finished_bracket_matches.size > 0
|
if @wrestler.finished_bracket_matches.size > 0
|
||||||
@@ -15,19 +15,25 @@ class PoolAdvance
|
|||||||
end
|
end
|
||||||
|
|
||||||
def poolToBracketAdvancment
|
def poolToBracketAdvancment
|
||||||
if @wrestler.pool_placement == 2
|
pool = @wrestler.pool
|
||||||
runnerUpMatch.replace_loser_name_with_wrestler(runnerUp,"Runner Up Pool #{pool}")
|
# This has to always run because the last match in a pool might not be a pool winner or runner up
|
||||||
|
winner = Wrestler.where("weight_id = ? and pool_placement = 1 and pool = ?",@wrestler.weight.id, pool).first
|
||||||
|
runner_up = Wrestler.where("weight_id = ? and pool_placement = 2 and pool = ?",@wrestler.weight.id, pool).first
|
||||||
|
if runner_up
|
||||||
|
runner_up_match = Match.where("weight_id = ? and (loser1_name = ? or loser2_name = ?)",@wrestler.weight.id, "Runner Up Pool #{pool}", "Runner Up Pool #{pool}").first
|
||||||
|
runner_up_match.replace_loser_name_with_wrestler(runner_up,"Runner Up Pool #{pool}")
|
||||||
end
|
end
|
||||||
if @wrestler.pool_placement == 1
|
if winner
|
||||||
winnerMatch.replace_loser_name_with_wrestler(winner,"Winner Pool #{pool}")
|
winner_match = Match.where("weight_id = ? and (loser1_name = ? or loser2_name = ?)",@wrestler.weight.id, "Winner Pool #{pool}", "Winner Pool #{pool}").first
|
||||||
|
winner_match.replace_loser_name_with_wrestler(winner,"Winner Pool #{pool}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def bracketAdvancment
|
def bracketAdvancment
|
||||||
if @previousMatch.winner_id == @wrestler.id
|
if @last_match.winner_id == @wrestler.id
|
||||||
winnerAdvance
|
winnerAdvance
|
||||||
end
|
end
|
||||||
if @previousMatch.winner_id != @wrestler.id
|
if @last_match.winner_id != @wrestler.id
|
||||||
loserAdvance
|
loserAdvance
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
37
test/integration/pool_to_bracket_advancement_test.rb
Normal file
37
test/integration/pool_to_bracket_advancement_test.rb
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class PoolToBracketAdvancementTest < ActionDispatch::IntegrationTest
|
||||||
|
|
||||||
|
def setup
|
||||||
|
@tournament = create_pool_tournament_single_weight(10)
|
||||||
|
@weight = Weight.where("tournament_id = ? and max = 106", @tournament.id).first
|
||||||
|
end
|
||||||
|
|
||||||
|
def end_all_pool_matches
|
||||||
|
matches = Match.where("weight_id = ? and bracket_position = 'Pool'",@weight.id)
|
||||||
|
matches.each do |match|
|
||||||
|
if match.wrestler1.bracket_line < match.wrestler2.bracket_line
|
||||||
|
match.winner_id = match.w1
|
||||||
|
else
|
||||||
|
match.winner_id = match.w2
|
||||||
|
end
|
||||||
|
match.finished = 1
|
||||||
|
match.score = "2-1"
|
||||||
|
match.save
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test "Pool winners are wrestling for first and pool losers are wrestling for third in two pools to finals pool bracket" do
|
||||||
|
end_all_pool_matches
|
||||||
|
pool_winner_1 = Wrestler.where("weight_id = ? and pool = 1 and pool_placement = 1",@weight.id).first
|
||||||
|
pool_runnerup_1 = Wrestler.where("weight_id = ? and pool = 1 and pool_placement = 2",@weight.id).first
|
||||||
|
pool_winner_2 = Wrestler.where("weight_id = ? and pool = 2 and pool_placement = 1",@weight.id).first
|
||||||
|
pool_runnerup_2 = Wrestler.where("weight_id = ? and pool = 2 and pool_placement = 2",@weight.id).first
|
||||||
|
match_1_2 = Match.where("weight_id = ? and bracket_position = '1/2'", @weight.id).first
|
||||||
|
match_3_4 = Match.where("weight_id = ? and bracket_position = '3/4'", @weight.id).first
|
||||||
|
assert match_1_2.wrestler_in_match(pool_winner_1) == true
|
||||||
|
assert match_1_2.wrestler_in_match(pool_winner_2) == true
|
||||||
|
assert match_3_4.wrestler_in_match(pool_runnerup_1) == true
|
||||||
|
assert match_3_4.wrestler_in_match(pool_runnerup_2) == true
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -32,6 +32,7 @@ class ActiveSupport::TestCase
|
|||||||
@weight.save
|
@weight.save
|
||||||
create_wrestlers_for_weight(@weight, @school, number_of_wrestlers, 1)
|
create_wrestlers_for_weight(@weight, @school, number_of_wrestlers, 1)
|
||||||
GenerateTournamentMatches.new(@tournament).generate
|
GenerateTournamentMatches.new(@tournament).generate
|
||||||
|
return @tournament
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_pool_tournament
|
def create_pool_tournament
|
||||||
|
|||||||
Reference in New Issue
Block a user