1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-03-25 01:14:43 +00:00

Refactored match winner and wrestlers matches and fixed slow tests.

This commit is contained in:
2025-04-25 15:59:35 -04:00
parent 3e4317dbc5
commit 1fcaec876f
20 changed files with 147 additions and 116 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -54,11 +54,11 @@ class TournamentBackupService
end,
matches: @tournament.matches.sort_by(&:bout_number).map do |match|
match.attributes.merge(
w1_name: Wrestler.find_by(id: match.w1)&.name,
w2_name: Wrestler.find_by(id: match.w2)&.name,
winner_name: Wrestler.find_by(id: match.winner_id)&.name,
weight: Weight.find_by(id: match.weight_id)&.attributes,
mat: Mat.find_by(id: match.mat_id)&.attributes
w1_name: match.wrestler1&.name,
w2_name: match.wrestler2&.name,
winner_name: match.winner&.name,
weight: match.weight&.attributes,
mat: match.mat&.attributes
)
end
}

View File

@@ -5,7 +5,7 @@ class CalculateWrestlerTeamScore
end
def totalScore
if @wrestler.extra or @wrestler.matches.count == 0
if @wrestler.extra or @wrestler.all_matches.count == 0
return 0
else
earnedPoints - deductedPoints

View File

@@ -27,10 +27,22 @@ class DoubleEliminationPlacementPoints
end
def bracket_position_size(bracket_position_name)
@wrestler.all_matches.select{|m| m.bracket_position == bracket_position_name}.size
@wrestler.all_matches.select{|m| m.bracket_position == bracket_position_name}.size
end
def won_bracket_position_size(bracket_position_name)
@wrestler.matches_won.select{|m| m.bracket_position == bracket_position_name}.size
end
def bracket_placement_points(bracket_position_name)
if bracket_position_name == "Did not place"
return 0
end
if @wrestler.participating_matches.where(bracket_position: bracket_position_name).count > 0
points = Teampointadjust.find_by(tournament_id: @wrestler.tournament.id, points_for_placement: bracket_position_name)
if points
# ... existing code ...
end
end
end
end