diff --git a/app/services/wrestler_services/calculate_wrestler_team_score.rb b/app/services/wrestler_services/calculate_wrestler_team_score.rb
index 48e0070..87ce236 100644
--- a/app/services/wrestler_services/calculate_wrestler_team_score.rb
+++ b/app/services/wrestler_services/calculate_wrestler_team_score.rb
@@ -54,29 +54,20 @@ class CalculateWrestlerTeamScore
def byePoints
points = 0
if @tournament.tournament_type == "Pool to bracket"
- if @wrestler.pool_wins.size >= 1 and @wrestler.has_a_pool_bye == true
+ if pool_bye_points_eligible?
points += 2
end
end
- if @tournament.tournament_type.include? "Regular Double Elimination"
- if @wrestler.championship_advancement_wins.size > 0 or @wrestler.matches_won.select{|m| m.bracket_position == "1/2" and m.win_type != "BYE"}.size > 0
- # if they have a win in the championship round or if they got a bye all the way to finals and won the finals
- points += @wrestler.championship_byes.size * 2
+ if @tournament.tournament_type.include? "Double Elimination"
+ if @wrestler.championship_advancement_wins.any? &&
+ @wrestler.championship_byes.any? &&
+ any_bye_round_had_wrestled_match?(@wrestler.championship_byes)
+ points += 2
end
- if @wrestler.consolation_advancement_wins.size > 0 or @wrestler.matches_won.select{|m| m.bracket_position == "3/4" and m.win_type != "BYE"}.size > 0
- # if they have a win in the consolation round or if they got a bye all the way to 3rd/4th match and won
- points += @wrestler.consolation_byes.size * 1
- end
- end
- if @tournament.tournament_type.include? "Modified 16 Man Double Elimination"
- if @wrestler.championship_advancement_wins.size > 0 or @wrestler.matches_won.select{|m| m.bracket_position == "1/2" and m.win_type != "BYE"}.size > 0
- # if they have a win in the championship round or if they got a bye all the way to finals and won the finals
- points += @wrestler.championship_byes.size * 2
- end
- if @wrestler.consolation_advancement_wins.size > 0 or @wrestler.matches_won.select{|m| m.bracket_position == "5/6" and m.win_type != "BYE"}.size > 0
- # if they have a win in the consolation round or if they got a bye all the way to 5th/6th match and won
- # since the consolation bracket goes to 5/6 in a modified tournament
- points += @wrestler.consolation_byes.size * 1
+ if @wrestler.consolation_advancement_wins.any? &&
+ @wrestler.consolation_byes.any? &&
+ any_bye_round_had_wrestled_match?(@wrestler.consolation_byes)
+ points += 1
end
end
return points
@@ -86,4 +77,30 @@ class CalculateWrestlerTeamScore
(@wrestler.pin_wins.size * 2) + (@wrestler.tech_wins.size * 1.5) + (@wrestler.major_wins.size * 1)
end
+ private
+
+ def pool_bye_points_eligible?
+ return false unless @wrestler.pool_wins.size >= 1
+ return false unless @wrestler.weight.pools.to_i > 1
+
+ wrestler_pool_size = @wrestler.weight.wrestlers_in_pool(@wrestler.pool).size
+ largest_pool_size = (1..@wrestler.weight.pools).map { |pool_number| @wrestler.weight.wrestlers_in_pool(pool_number).size }.max
+
+ wrestler_pool_size < largest_pool_size
+ end
+
+ def any_bye_round_had_wrestled_match?(bye_matches)
+ bye_matches.any? do |bye_match|
+ next false if bye_match.round.nil?
+
+ @wrestler.weight.matches.any? do |match|
+ next false if match.id == bye_match.id
+ next false if match.round != bye_match.round
+ next false if match.is_consolation_match != bye_match.is_consolation_match
+
+ match.finished == 1 && match.win_type.present? && match.win_type != "BYE"
+ end
+ end
+ end
+
end
diff --git a/app/views/static_pages/about.html.erb b/app/views/static_pages/about.html.erb
index fbeba65..03318cf 100644
--- a/app/views/static_pages/about.html.erb
+++ b/app/views/static_pages/about.html.erb
@@ -48,7 +48,7 @@
Win by major: 1pt extra
Win by tech fall: 1.5pt extra
Win by fall, default, dq: 2pt extra
- BYE points: 2pt (if you win at least 1 match in a pool with a BYE)
+ BYE points: 2pt (if you win at least 1 match in a pool with a BYE). - This only applies if your pool has more BYEs than other pools in your bracket. This does not apply to weight classes with 1 pool.
See placement points below (based on the largest bracket of the tournament)
Pool Types
@@ -71,7 +71,7 @@
Win by major: 1pt extra
Win by tech: 1.5pt extra
Win by fall, default, dq, etc: 2pt extra
- BYE points: 2pts if you have a bye in the championship bracket and win the next match. 1pt if you have a bye in the consolation bracket and win the next match.
+ BYE points: 2pts if you have a bye in the championship bracket and win the next match. 1pt if you have a bye in the consolation bracket and win the next match. - This only applies if you received a bye in a round with at least 1 match in your backet.
Modified 16 Man Double Elimination Information
@@ -142,7 +142,7 @@
Future Plans
-Future development plans to support 32 and 64 man regulard double elimination, modified (5 per day match rule) 32 man double elimination, and true second double elimination brackets are underway.
+Future development plans are underway to make the application more flexible, make changes after weigh ins easier, and to add functionality for a live scoreboard.
Contact
diff --git a/test/integration/double_elimination_wrestler_score_test.rb b/test/integration/double_elimination_wrestler_score_test.rb
index 711e275..e1000c7 100644
--- a/test/integration/double_elimination_wrestler_score_test.rb
+++ b/test/integration/double_elimination_wrestler_score_test.rb
@@ -30,6 +30,15 @@ class DoubleEliminationWrestlerScore < ActionDispatch::IntegrationTest
return wrestler
end
+ def wrestle_other_match_in_round(reference_match, conso: false)
+ match = @tournament.matches.reload
+ .select { |m| m.round == reference_match.round && m.id != reference_match.id && m.is_consolation_match == conso }
+ .first
+ return if match.nil?
+
+ winner_by_name("Test2", match)
+ end
+
test "Wrestlers get points for byes in the championship rounds" do
matches = @tournament.matches.reload
round1 = matches.select{|m| m.bracket_position == "Bracket Round of 16"}.first
@@ -37,9 +46,10 @@ class DoubleEliminationWrestlerScore < ActionDispatch::IntegrationTest
semi = matches.select{|m| m.bracket_position == "Semis"}.first
winner_by_name_by_bye("Test1", round1)
winner_by_name_by_bye("Test1", quarter)
+ wrestle_other_match_in_round(round1, conso: false)
winner_by_name("Test1", semi)
wrestler_points_calc = CalculateWrestlerTeamScore.new(get_wretler_by_name("Test1"))
- assert wrestler_points_calc.byePoints == 4
+ assert wrestler_points_calc.byePoints == 2
end
test "Wrestlers get points for byes in the consolation rounds" do
@@ -49,9 +59,10 @@ class DoubleEliminationWrestlerScore < ActionDispatch::IntegrationTest
semi = matches.select{|m| m.bracket_position == "Conso Semis"}.first
winner_by_name_by_bye("Test1", conso_r8_1)
winner_by_name_by_bye("Test1", quarter)
+ wrestle_other_match_in_round(conso_r8_1, conso: true)
winner_by_name("Test1", semi)
wrestler_points_calc = CalculateWrestlerTeamScore.new(get_wretler_by_name("Test1"))
- assert wrestler_points_calc.byePoints == 2
+ assert wrestler_points_calc.byePoints == 1
end
test "Wrestlers do not get bye points if they get byes to 1st/2nd and win by bye" do
@@ -93,7 +104,19 @@ class DoubleEliminationWrestlerScore < ActionDispatch::IntegrationTest
winner_by_name_by_bye("Test1", semi)
winner_by_name("Test1", final)
wrestler_points_calc = CalculateWrestlerTeamScore.new(get_wretler_by_name("Test1"))
- assert wrestler_points_calc.byePoints == 6
+ assert wrestler_points_calc.byePoints == 0
+ end
+
+ test "Wrestlers do not get championship bye points when no championship match is wrestled in those bye rounds" do
+ matches = @tournament.matches.reload
+ round1 = matches.select{|m| m.bracket_position == "Bracket Round of 16"}.first
+ quarter = matches.select{|m| m.bracket_position == "Quarter"}.first
+ semi = matches.select{|m| m.bracket_position == "Semis"}.first
+ winner_by_name_by_bye("Test1", round1)
+ winner_by_name_by_bye("Test1", quarter)
+ winner_by_name("Test1", semi)
+ wrestler_points_calc = CalculateWrestlerTeamScore.new(get_wretler_by_name("Test1"))
+ assert wrestler_points_calc.byePoints == 0
end
test "Wrestlers do not get bye points if they get byes to 3rd/4th and win by decision" do
@@ -107,6 +130,20 @@ class DoubleEliminationWrestlerScore < ActionDispatch::IntegrationTest
winner_by_name_by_bye("Test1", semi)
winner_by_name("Test1", final)
wrestler_points_calc = CalculateWrestlerTeamScore.new(get_wretler_by_name("Test1"))
- assert wrestler_points_calc.byePoints == 3
+ assert wrestler_points_calc.byePoints == 0
end
-end
\ No newline at end of file
+
+ test "Wrestlers do not get conso bye points when no conso match is wrestled in those rounds" do
+ matches = @tournament.matches.reload
+ conso_r8_1 = matches.select{|m| m.bracket_position == "Conso Round of 8.1"}.first
+ quarter = matches.select{|m| m.bracket_position == "Conso Quarter"}.first
+ semi = matches.select{|m| m.bracket_position == "Conso Semis"}.first
+ final = matches.select{|m| m.bracket_position == "3/4"}.first
+ winner_by_name_by_bye("Test1", conso_r8_1)
+ winner_by_name_by_bye("Test1", quarter)
+ winner_by_name_by_bye("Test1", semi)
+ winner_by_name("Test1", final)
+ wrestler_points_calc = CalculateWrestlerTeamScore.new(get_wretler_by_name("Test1"))
+ assert wrestler_points_calc.byePoints == 0
+ end
+end
diff --git a/test/integration/modified_double_elimination_wrestler_score_test.rb b/test/integration/modified_double_elimination_wrestler_score_test.rb
index 9b7c87d..277a6d1 100644
--- a/test/integration/modified_double_elimination_wrestler_score_test.rb
+++ b/test/integration/modified_double_elimination_wrestler_score_test.rb
@@ -30,6 +30,15 @@ class ModifiedDoubleEliminationWrestlerScore < ActionDispatch::IntegrationTest
return wrestler
end
+ def wrestle_other_match_in_round(reference_match, conso: false)
+ match = @tournament.matches.reload
+ .select { |m| m.round == reference_match.round && m.id != reference_match.id && m.is_consolation_match == conso }
+ .first
+ return if match.nil?
+
+ winner_by_name("Test2", match)
+ end
+
test "Wrestlers get points for byes in the championship rounds" do
matches = @tournament.matches.reload
round1 = matches.select{|m| m.round == 1}.first
@@ -37,9 +46,10 @@ class ModifiedDoubleEliminationWrestlerScore < ActionDispatch::IntegrationTest
semi = matches.select{|m| m.bracket_position == "Semis"}.first
winner_by_name_by_bye("Test1", round1)
winner_by_name_by_bye("Test1", quarter)
+ wrestle_other_match_in_round(round1, conso: false)
winner_by_name("Test1", semi)
wrestler_points_calc = CalculateWrestlerTeamScore.new(get_wretler_by_name("Test1"))
- assert wrestler_points_calc.byePoints == 4
+ assert wrestler_points_calc.byePoints == 2
end
test "Wrestlers get points for byes in the consolation rounds" do
@@ -49,9 +59,10 @@ class ModifiedDoubleEliminationWrestlerScore < ActionDispatch::IntegrationTest
semi = matches.select{|m| m.bracket_position == "Conso Semis"}.first
winner_by_name_by_bye("Test1", round2)
winner_by_name_by_bye("Test1", quarter)
+ wrestle_other_match_in_round(round2, conso: true)
winner_by_name("Test1", semi)
wrestler_points_calc = CalculateWrestlerTeamScore.new(get_wretler_by_name("Test1"))
- assert wrestler_points_calc.byePoints == 2
+ assert wrestler_points_calc.byePoints == 1
end
test "Wrestlers do not get bye points if they get byes to 1st/2nd and win by bye" do
@@ -93,7 +104,19 @@ class ModifiedDoubleEliminationWrestlerScore < ActionDispatch::IntegrationTest
winner_by_name_by_bye("Test1", semi)
winner_by_name("Test1", final)
wrestler_points_calc = CalculateWrestlerTeamScore.new(get_wretler_by_name("Test1"))
- assert wrestler_points_calc.byePoints == 6
+ assert wrestler_points_calc.byePoints == 0
+ end
+
+ test "Wrestlers do not get championship bye points when no championship match is wrestled in those bye rounds" do
+ matches = @tournament.matches.reload
+ round1 = matches.select{|m| m.round == 1}.first
+ quarter = matches.select{|m| m.bracket_position == "Quarter"}.first
+ semi = matches.select{|m| m.bracket_position == "Semis"}.first
+ winner_by_name_by_bye("Test1", round1)
+ winner_by_name_by_bye("Test1", quarter)
+ winner_by_name("Test1", semi)
+ wrestler_points_calc = CalculateWrestlerTeamScore.new(get_wretler_by_name("Test1"))
+ assert wrestler_points_calc.byePoints == 0
end
test "Wrestlers do not get bye points if they get byes to 5th/6th and win by decision" do
@@ -107,6 +130,20 @@ class ModifiedDoubleEliminationWrestlerScore < ActionDispatch::IntegrationTest
winner_by_name_by_bye("Test1", semi)
winner_by_name("Test1", final)
wrestler_points_calc = CalculateWrestlerTeamScore.new(get_wretler_by_name("Test1"))
- assert wrestler_points_calc.byePoints == 3
+ assert wrestler_points_calc.byePoints == 0
end
-end
\ No newline at end of file
+
+ test "Wrestlers do not get conso bye points when no conso match is wrestled in those rounds" do
+ matches = @tournament.matches.reload
+ round2 = matches.select{|m| m.bracket_position == "Conso Round of 8"}.first
+ quarter = matches.select{|m| m.bracket_position == "Conso Quarter"}.first
+ semi = matches.select{|m| m.bracket_position == "Conso Semis"}.first
+ final = matches.select{|m| m.bracket_position == "5/6"}.first
+ winner_by_name_by_bye("Test1", round2)
+ winner_by_name_by_bye("Test1", quarter)
+ winner_by_name_by_bye("Test1", semi)
+ winner_by_name("Test1", final)
+ wrestler_points_calc = CalculateWrestlerTeamScore.new(get_wretler_by_name("Test1"))
+ assert wrestler_points_calc.byePoints == 0
+ end
+end
diff --git a/test/integration/pool_bye_points_rules_test.rb b/test/integration/pool_bye_points_rules_test.rb
new file mode 100644
index 0000000..a8891d3
--- /dev/null
+++ b/test/integration/pool_bye_points_rules_test.rb
@@ -0,0 +1,46 @@
+require 'test_helper'
+
+class PoolByePointsRulesTest < ActionDispatch::IntegrationTest
+ def finish_pool_match_for_wrestler(wrestler)
+ match = wrestler.pool_matches.select { |m| m.finished != 1 }.first
+ return if match.nil?
+
+ match.w1 = wrestler.id
+ match.winner_id = wrestler.id
+ match.finished = 1
+ match.win_type = "Decision"
+ match.score = "1-0"
+ match.save!
+ end
+
+ test "single pool wrestlers do not get pool bye points" do
+ create_pool_tournament_single_weight(6)
+ wrestler = @tournament.weights.first.wrestlers.first
+ finish_pool_match_for_wrestler(wrestler)
+
+ wrestler_points_calc = CalculateWrestlerTeamScore.new(wrestler)
+ assert_equal 0, wrestler_points_calc.byePoints
+ end
+
+ test "pool bye points are not awarded when pools are even" do
+ create_pool_tournament_single_weight(8)
+ wrestler = @tournament.weights.first.wrestlers.first
+ finish_pool_match_for_wrestler(wrestler)
+
+ wrestler_points_calc = CalculateWrestlerTeamScore.new(wrestler)
+ assert_equal 0, wrestler_points_calc.byePoints
+ end
+
+ test "pool bye points are awarded once when wrestler is in a smaller pool" do
+ create_pool_tournament_single_weight(9)
+ weight = @tournament.weights.first
+ smallest_pool = (1..weight.pools).min_by { |pool_number| weight.wrestlers_in_pool(pool_number).size }
+ wrestler = weight.wrestlers_in_pool(smallest_pool).first
+
+ finish_pool_match_for_wrestler(wrestler)
+ finish_pool_match_for_wrestler(wrestler)
+
+ wrestler_points_calc = CalculateWrestlerTeamScore.new(wrestler)
+ assert_equal 2, wrestler_points_calc.byePoints
+ end
+end