mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-04-06 14:36:59 +00:00
Refactored match winner and wrestlers matches and fixed slow tests.
This commit is contained in:
@@ -7,17 +7,22 @@ class DoubleEliminationAdvance
|
||||
end
|
||||
|
||||
def bracket_advancement
|
||||
if @last_match.winner_id == @wrestler.id
|
||||
winner_advance
|
||||
end
|
||||
if @last_match.winner_id != @wrestler.id
|
||||
loser_advance
|
||||
end
|
||||
advance_wrestler
|
||||
advance_double_byes
|
||||
set_bye_for_placement
|
||||
end
|
||||
|
||||
def winner_advance
|
||||
def advance_wrestler
|
||||
# Advance winner
|
||||
if @last_match.winner == @wrestler
|
||||
winners_bracket_advancement
|
||||
# Advance loser
|
||||
elsif @last_match.winner != @wrestler
|
||||
losers_bracket_advancement
|
||||
end
|
||||
end
|
||||
|
||||
def winners_bracket_advancement
|
||||
if (@last_match.loser1_name == "BYE" or @last_match.loser2_name == "BYE") and @last_match.is_championship_match
|
||||
update_consolation_bye
|
||||
end
|
||||
@@ -77,7 +82,7 @@ class DoubleEliminationAdvance
|
||||
end
|
||||
end
|
||||
|
||||
def loser_advance
|
||||
def losers_bracket_advancement
|
||||
bout = @last_match.bout_number
|
||||
next_match = Match.where("(loser1_name = ? OR loser2_name = ?) AND weight_id = ?", "Loser of #{bout}", "Loser of #{bout}", @wrestler.weight_id).first
|
||||
|
||||
|
||||
@@ -7,17 +7,20 @@ class ModifiedDoubleEliminationAdvance
|
||||
end
|
||||
|
||||
def bracket_advancement
|
||||
if @last_match.winner_id == @wrestler.id
|
||||
winner_advance
|
||||
end
|
||||
if @last_match.winner_id != @wrestler.id
|
||||
loser_advance
|
||||
end
|
||||
advance_wrestler
|
||||
advance_double_byes
|
||||
set_bye_for_placement
|
||||
end
|
||||
|
||||
def winner_advance
|
||||
def advance_wrestler
|
||||
if @last_match.winner == @wrestler
|
||||
winners_bracket_advancement
|
||||
elsif @last_match.winner != @wrestler
|
||||
losers_bracket_advancement
|
||||
end
|
||||
end
|
||||
|
||||
def winners_bracket_advancement
|
||||
if (@last_match.loser1_name == "BYE" or @last_match.loser2_name == "BYE") and @last_match.is_championship_match
|
||||
update_consolation_bye
|
||||
end
|
||||
@@ -69,7 +72,7 @@ class ModifiedDoubleEliminationAdvance
|
||||
end
|
||||
end
|
||||
|
||||
def loser_advance
|
||||
def losers_bracket_advancement
|
||||
bout = @last_match.bout_number
|
||||
next_match = Match.where("(loser1_name = ? OR loser2_name = ?) AND weight_id = ?", "Loser of #{bout}", "Loser of #{bout}", @wrestler.weight_id).first
|
||||
|
||||
|
||||
@@ -30,15 +30,20 @@ class PoolAdvance
|
||||
end
|
||||
|
||||
def bracketAdvancment
|
||||
if @last_match.winner_id == @wrestler.id
|
||||
winnerAdvance
|
||||
end
|
||||
if @last_match.winner_id != @wrestler.id
|
||||
loserAdvance
|
||||
end
|
||||
advance_wrestlers
|
||||
end
|
||||
|
||||
def winnerAdvance
|
||||
def advance_wrestlers
|
||||
# Advance winner
|
||||
if @last_match.winner == @wrestler
|
||||
winner_advance
|
||||
# Advance loser
|
||||
elsif @last_match.winner != @wrestler
|
||||
loser_advance
|
||||
end
|
||||
end
|
||||
|
||||
def winner_advance
|
||||
if @wrestler.last_match.bracket_position == "Quarter"
|
||||
new_match = Match.where("bracket_position = ? AND bracket_position_number = ? AND weight_id = ?","Semis",@wrestler.next_match_position_number.ceil,@wrestler.weight_id).first
|
||||
updateNewMatch(new_match)
|
||||
@@ -65,7 +70,7 @@ class PoolAdvance
|
||||
end
|
||||
end
|
||||
|
||||
def loserAdvance
|
||||
def loser_advance
|
||||
bout = @wrestler.last_match.bout_number
|
||||
next_match = Match.where("(loser1_name = ? OR loser2_name = ?) AND weight_id = ?","Loser of #{bout}","Loser of #{bout}",@wrestler.weight_id)
|
||||
if next_match.size > 0
|
||||
|
||||
@@ -29,7 +29,7 @@ class PoolOrder
|
||||
|
||||
def setOriginalPoints
|
||||
@wrestlers.each do |w|
|
||||
matches = w.matches.reload
|
||||
matches = w.reload.all_matches
|
||||
w.pool_placement_tiebreaker = nil
|
||||
w.pool_placement = nil
|
||||
w.poolAdvancePoints = w.pool_wins.size
|
||||
@@ -80,10 +80,13 @@ class PoolOrder
|
||||
def headToHead(wrestlers_with_same_points)
|
||||
wrestlers_with_same_points.each do |wr|
|
||||
otherWrestler = wrestlers_with_same_points.select{|w| w.id != wr.id}.first
|
||||
if otherWrestler and wr.match_against(otherWrestler).select{|match| match.bracket_position == "Pool"}.first.winner_id == wr.id
|
||||
addPointsToWrestlersAhead(wr)
|
||||
wr.pool_placement_tiebreaker = "Head to Head"
|
||||
if otherWrestler
|
||||
matches = wr.match_against(otherWrestler).select { |match| match.bracket_position == "Pool" }
|
||||
if matches.any? && matches.first.winner == wr
|
||||
addPointsToWrestlersAhead(wr)
|
||||
wr.pool_placement_tiebreaker = "Head to Head"
|
||||
addPoints(wr)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user