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

Dealing with double byes

This commit is contained in:
2020-01-24 10:30:50 -05:00
parent bae349a2c9
commit 80841e15ae
2 changed files with 30 additions and 2 deletions

View File

@@ -147,7 +147,7 @@ class Match < ActiveRecord::Base
def w1_bracket_name_round_one
if self.w1 != nil
return "#{wrestler1.original_seed} #{w1_name} - #{wrestler1.school.name}"
return "#{wrestler1.original_seed} #{w1_name} - #{wrestler1.school.abbreviation}"
else
"#{w1_name}"
end
@@ -155,7 +155,7 @@ class Match < ActiveRecord::Base
def w2_bracket_name_round_one
if self.w2 != nil
return "#{wrestler2.original_seed} #{w2_name} - #{wrestler2.school.name}"
return "#{wrestler2.original_seed} #{w2_name} - #{wrestler2.school.abbreviation}"
else
"#{w2_name}"
end

View File

@@ -12,6 +12,7 @@ class DoubleEliminationAdvance
if @last_match.winner_id != @wrestler.id
loser_advance
end
advance_double_byes
end
def winner_advance
@@ -104,4 +105,31 @@ class DoubleEliminationAdvance
end
end
end
def advance_double_byes
weight = @wrestler.weight
weight.matches.select{|m| m.loser1_name == "BYE" and m.loser2_name == "BYE"}.each do |match|
match.finished = 1
match.win_type = "BYE"
next_match_position_number = (match.bracket_position_number / 2.0).ceil
after_matches = weight.matches.select{|m| m.round > match.round and m.is_consolation_match == match.is_consolation_match }.sort_by{|m| m.round}
next_matches = weight.matches.select{|m| m.round == after_matches.first.round and m.is_consolation_match == match.is_consolation_match }
this_round_matches = weight.matches.select{|m| m.round == match.round and m.is_consolation_match == match.is_consolation_match }
if next_matches.size == this_round_matches.size
next_match = next_matches.select{|m| m.bracket_position_number == match.bracket_position_number}.first
next_match.loser2_name = "BYE"
next_match.save
elsif next_matches.size < this_round_matches.size and next_matches.size > 0
next_match = next_matches.select{|m| m.bracket_position_number == next_match_position_number}.first
if next_match.bracket_position_number == next_match_position_number
next_match.loser2_name = "BYE"
else
next_match.loser1_name = "BYE"
end
end
next_match.save
match.save
end
end
end