diff --git a/app/models/wrestler.rb b/app/models/wrestler.rb index 506a6ab..982a1e6 100644 --- a/app/models/wrestler.rb +++ b/app/models/wrestler.rb @@ -145,6 +145,14 @@ class Wrestler < ActiveRecord::Base matches_won.select{|m| (m.bracket_position == "Conso Semis" or m.bracket_position == "Conso" or m.bracket_position == "Conso Quarter") and m.win_type != "BYE"} end + def championship_byes + matches_won.select{|m| (m.bracket_position == "Quarter" or m.bracket_position == "Semis" or m.bracket_position == "Bracket") and m.win_type == "BYE"} + end + + def consolation_byes + matches_won.select{|m| (m.bracket_position == "Conso Semis" or m.bracket_position == "Conso" or m.bracket_position == "Conso Quarter") and m.win_type == "BYE"} + end + def finished_matches all_matches.select{|m| m.finished == 1} end diff --git a/app/services/wrestler_services/calculate_wrestler_team_score.rb b/app/services/wrestler_services/calculate_wrestler_team_score.rb index 1762184..755cab6 100644 --- a/app/services/wrestler_services/calculate_wrestler_team_score.rb +++ b/app/services/wrestler_services/calculate_wrestler_team_score.rb @@ -44,15 +44,34 @@ class CalculateWrestlerTeamScore end def byePoints + points = 0 if @tournament.tournament_type == "Pool to bracket" if @wrestler.pool_wins.size >= 1 and @wrestler.has_a_pool_bye == true - 2 - else - 0 + points += 2 end - else - 0 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"}.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 == "3/4"}.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"}.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"}.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 + end + end + return points end def bonusWinPoints diff --git a/test/integration/double_elimination_wrestler_score_test.rb b/test/integration/double_elimination_wrestler_score_test.rb new file mode 100644 index 0000000..10743fe --- /dev/null +++ b/test/integration/double_elimination_wrestler_score_test.rb @@ -0,0 +1,56 @@ +require 'test_helper' + +class DoubleEliminationWrestlerScore < ActionDispatch::IntegrationTest + def setup + create_double_elim_tournament_single_weight(14, "Regular Double Elimination 1-8") + end + + def winner_by_name(winner_name,match) + wrestler = @tournament.weights.first.wrestlers.select{|w| w.name == winner_name}.first + match.w1 = wrestler.id + match.winner_id = wrestler.id + match.finished = 1 + match.win_type = "Decision" + match.score = "0-0" + match.save + end + + def winner_by_name_by_bye(winner_name,match) + wrestler = @tournament.weights.first.wrestlers.select{|w| w.name == winner_name}.first + match.w1 = wrestler.id + match.winner_id = wrestler.id + match.finished = 1 + match.win_type = "BYE" + match.score = "" + match.save + end + + def get_wretler_by_name(name) + wrestler = @tournament.weights.first.wrestlers.select{|w| w.name == name}.first + return wrestler + end + + test "Wrestlers get points for byes in the championship 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 == 4 + end + + test "Wrestlers get points for byes in the consolation rounds" do + matches = @tournament.matches.reload + round2 = matches.select{|m| m.round == 2 and m.bracket_position == "Conso"}.first + quarter = matches.select{|m| m.bracket_position == "Conso Quarter"}.first + semi = matches.select{|m| m.bracket_position == "Conso Semis"}.first + winner_by_name_by_bye("Test1", round2) + 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 == 2 + end +end \ No newline at end of file diff --git a/test/integration/modified_double_elimination_wrestler_score_test.rb b/test/integration/modified_double_elimination_wrestler_score_test.rb new file mode 100644 index 0000000..a72533b --- /dev/null +++ b/test/integration/modified_double_elimination_wrestler_score_test.rb @@ -0,0 +1,56 @@ +require 'test_helper' + +class ModifiedDoubleEliminationWrestlerScore < ActionDispatch::IntegrationTest + def setup + create_double_elim_tournament_single_weight(14, "Modified 16 Man Double Elimination 1-8") + end + + def winner_by_name(winner_name,match) + wrestler = @tournament.weights.first.wrestlers.select{|w| w.name == winner_name}.first + match.w1 = wrestler.id + match.winner_id = wrestler.id + match.finished = 1 + match.win_type = "Decision" + match.score = "0-0" + match.save + end + + def winner_by_name_by_bye(winner_name,match) + wrestler = @tournament.weights.first.wrestlers.select{|w| w.name == winner_name}.first + match.w1 = wrestler.id + match.winner_id = wrestler.id + match.finished = 1 + match.win_type = "BYE" + match.score = "" + match.save + end + + def get_wretler_by_name(name) + wrestler = @tournament.weights.first.wrestlers.select{|w| w.name == name}.first + return wrestler + end + + test "Wrestlers get points for byes in the championship 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 == 4 + end + + test "Wrestlers get points for byes in the consolation rounds" do + matches = @tournament.matches.reload + round2 = matches.select{|m| m.round == 2 and m.bracket_position == "Conso"}.first + quarter = matches.select{|m| m.bracket_position == "Conso Quarter"}.first + semi = matches.select{|m| m.bracket_position == "Conso Semis"}.first + winner_by_name_by_bye("Test1", round2) + 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 == 2 + end +end \ No newline at end of file