diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index fb7c2ce..d940233 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -181,8 +181,10 @@ class TournamentsController < ApplicationController @weight = Weight.where(:id => params[:weight]).includes(:matches,:wrestlers).first @matches = @weight.matches @wrestlers = @weight.wrestlers.includes(:school) - @pools = @weight.pool_rounds(@matches) - @bracketType = @weight.pool_bracket_type + if @tournament.tournament_type == "Pool to bracket" + @pools = @weight.pool_rounds(@matches) + @bracketType = @weight.pool_bracket_type + end end end diff --git a/app/models/match.rb b/app/models/match.rb index 548a7f8..3b67843 100644 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -22,8 +22,24 @@ class Match < ActiveRecord::Base end end - BRACKET_POSITIONS = ["Pool","1/2","3/4","5/6","7/8","Quarter","Semis","Conso Semis"] - WIN_TYPES = ["Decision", "Major", "Tech Fall", "Pin", "Forfeit", "Injury Default", "Default", "DQ"] + BRACKET_POSITIONS = ["Pool","1/2","3/4","5/6","7/8","Quarter","Semis","Conso Semis","Bracket","Conso", "Conso Quarter"] + WIN_TYPES = ["Decision", "Major", "Tech Fall", "Pin", "Forfeit", "Injury Default", "Default", "DQ", "BYE"] + + def is_consolation_match + if self.bracket_position == "Conso" or self.bracket_position == "Conso Quarter" or self.bracket_position == "Conso Semis" or self.bracket_position == "3/4" or self.bracket_position == "5/6" or self.bracket_position == "7/8" + return true + else + return false + end + end + + def is_championship_match + if self.bracket_position == "Pool" or self.bracket_position == "Quarter" or self.bracket_position == "Semis" or self.bracket_position == "Bracket" or self.bracket_position == "1/2" + return true + else + return false + end + end def calculate_school_points if self.w1 && self.w2 @@ -60,10 +76,12 @@ class Match < ActiveRecord::Base end def advance_wrestlers - if self.w1 && self.w2 + if self.w1 AdvanceWrestler.new(wrestler1).advance - AdvanceWrestler.new(wrestler2).advance end + if self.w2 + AdvanceWrestler.new(wrestler2).advance + end end @@ -127,6 +145,22 @@ class Match < ActiveRecord::Base end end + def w1_bracket_name_round_one + if self.w1 != nil + return "#{wrestler1.original_seed} #{w1_name} - #{wrestler1.school.name}" + else + "#{w1_name}" + end + end + + def w2_bracket_name_round_one + if self.w2 != nil + return "#{wrestler2.original_seed} #{w2_name} - #{wrestler2.school.name}" + else + "#{w2_name}" + end + end + def winner_name if self.finished != 1 return "" @@ -161,6 +195,18 @@ class Match < ActiveRecord::Base self.save end end + + def replace_loser_name_with_bye(loser_name) + if self.loser1_name == loser_name + self.loser1_name = "BYE" + self.save + end + if self.loser2_name == loser_name + self.loser2_name = "BYE" + self.save + end + end + def pool_number if self.w1? wrestler1.pool @@ -168,10 +214,18 @@ class Match < ActiveRecord::Base end def list_w2_stats - "#{w2_name} (#{wrestler2.school.name}): #{w2_stat}" + if self.w2 + "#{w2_name} (#{wrestler2.school.name}): #{w2_stat}" + else + "" + end end def list_w1_stats - "#{w1_name} (#{wrestler1.school.name}): #{w1_stat}" + if self.w1 + "#{w1_name} (#{wrestler1.school.name}): #{w1_stat}" + else + "" + end end end diff --git a/app/models/tournament.rb b/app/models/tournament.rb index 8efe60f..51e41e9 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -29,7 +29,7 @@ class Tournament < ActiveRecord::Base end def tournament_types - ["Pool to bracket"] + ["Pool to bracket","Modified 16 Man Double Elimination"] end def create_pre_defined_weights(value) @@ -113,15 +113,33 @@ class Tournament < ActiveRecord::Base nil end end + + def modified_sixteen_man_number_of_wrestlers + error_string = "" + if self.tournament_type == "Modified 16 Man Double Elimination" + weights_with_too_many_wrestlers = weights.select{|w| w.wrestlers.size > 16} + weight_with_too_few_wrestlers = weights.select{|w| w.wrestlers.size < 12} + weights_with_too_many_wrestlers.each do |weight| + error_string = error_string + " The weight class #{weight.max} has more than 16 wrestlers." + end + weight_with_too_few_wrestlers.each do |weight| + error_string = error_string + " The weight class #{weight.max} has less than 12 wrestlers." + end + end + return error_string + end def match_generation_error errorString = "There is a tournament error." + modified_sixteen_man_error = modified_sixteen_man_number_of_wrestlers if pool_to_bracket_weights_with_too_many_wrestlers != nil errorString = errorString + " The following weights have too many wrestlers " pool_to_bracket_weights_with_too_many_wrestlers.each do |w| errorString = errorString + "#{w.max} " end return errorString + elsif modified_sixteen_man_error.length > 0 + return errorString + modified_sixteen_man_error else nil end diff --git a/app/models/wrestler.rb b/app/models/wrestler.rb index f613e00..506a6ab 100644 --- a/app/models/wrestler.rb +++ b/app/models/wrestler.rb @@ -138,11 +138,11 @@ class Wrestler < ActiveRecord::Base end def championship_advancement_wins - matches_won.select{|m| m.bracket_position == "Quarter" or m.bracket_position == "Semis"} + 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_advancement_wins - matches_won.select{|m| m.bracket_position == "Conso Semis"} + 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 @@ -162,7 +162,7 @@ class Wrestler < ActiveRecord::Base end def pool_wins - matches_won.select{|m| m.bracket_position == "Pool"} + matches_won.select{|m| m.bracket_position == "Pool" and m.win_type != "BYE"} end def pin_wins diff --git a/app/services/bracket_advancement/advance_wrestler.rb b/app/services/bracket_advancement/advance_wrestler.rb index 39c98ce..3892c77 100644 --- a/app/services/bracket_advancement/advance_wrestler.rb +++ b/app/services/bracket_advancement/advance_wrestler.rb @@ -14,6 +14,7 @@ class AdvanceWrestler def advance_raw pool_to_bracket_advancement if @tournament.tournament_type == "Pool to bracket" + DoubleEliminationAdvance.new(@wrestler).bracket_advancement if @tournament.tournament_type == "Modified 16 Man Double Elimination" end def pool_to_bracket_advancement diff --git a/app/services/bracket_advancement/double_elimination_advance.rb b/app/services/bracket_advancement/double_elimination_advance.rb new file mode 100644 index 0000000..091b989 --- /dev/null +++ b/app/services/bracket_advancement/double_elimination_advance.rb @@ -0,0 +1,107 @@ +class DoubleEliminationAdvance + + def initialize(wrestler) + @wrestler = wrestler + @last_match = @wrestler.last_match + end + + def bracket_advancement + if @last_match.winner_id == @wrestler.id + winner_advance + end + if @last_match.winner_id != @wrestler.id + loser_advance + end + end + + def winner_advance + if (@last_match.loser1_name == "BYE" or @last_match.loser2_name == "BYE") and @last_match.is_championship_match + update_consolation_bye + end + 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 + update_new_match(new_match, get_wrestler_number) + elsif @wrestler.last_match.bracket_position == "Semis" + new_match = Match.where("bracket_position = ? AND bracket_position_number = ? AND weight_id = ?","1/2",@wrestler.next_match_position_number.ceil,@wrestler.weight_id).first + update_new_match(new_match, get_wrestler_number) + elsif @wrestler.last_match.bracket_position == "Conso Semis" + # if its a regular double elim + if Match.where("bracket_position = ? AND bracket_position_number = ? AND weight_id = ?","Conso Semis",@wrestler.next_match_position_number.ceil,@wrestler.weight_id).first.loser1_name != nil + new_match = Match.where("bracket_position = ? AND bracket_position_number = ? AND weight_id = ?","3/4",@wrestler.next_match_position_number.ceil,@wrestler.weight_id).first + update_new_match(new_match, get_wrestler_number) + # if it's a special bracket where consolations wrestler for 5th + else + new_match = Match.where("bracket_position = ? AND bracket_position_number = ? AND weight_id = ?","5/6",@wrestler.next_match_position_number.ceil,@wrestler.weight_id).first + update_new_match(new_match, get_wrestler_number) + end + elsif @wrestler.last_match.bracket_position == "Conso Quarter" + next_round_matches = Match.where("weight_id = ? and bracket_position = ?", @wrestler.weight_id, "Conso Semis").sort_by{|m| m.round} + this_round_matches = Match.where("weight_id = ? and round = ? and bracket_position = ?", @wrestler.weight_id, @wrestler.last_match.round, "Conso Quarter") + if next_round_matches.size == this_round_matches.size + # if a semi loser is dropping down + new_match = Match.where("bracket_position = ? AND bracket_position_number = ? AND weight_id = ?","Conso Semis",@wrestler.last_match.bracket_position_number,@wrestler.weight_id).first + update_new_match(new_match,2) + else + # if it's a special bracket where a semi loser is not dropping down + new_match = Match.where("bracket_position = ? AND bracket_position_number = ? AND weight_id = ?","Conso Semis",@wrestler.next_match_position_number.ceil,@wrestler.weight_id).first + update_new_match(new_match, get_wrestler_number) + end + elsif @wrestler.last_match.bracket_position == "Bracket" + new_match = Match.where("bracket_position_number = ? and weight_id = ? and round > ? and (bracket_position = ? or bracket_position = ?)", @wrestler.next_match_position_number.ceil,@wrestler.weight_id, @wrestler.last_match.round , "Bracket", "Quarter").sort_by{|m| m.round}.first + update_new_match(new_match, get_wrestler_number) + elsif @wrestler.last_match.bracket_position == "Conso" + next_round_matches = Match.where("weight_id = ? and round > ? and (bracket_position = ? or bracket_position = ?)", @wrestler.weight_id, @wrestler.last_match.round, "Conso", "Conso Quarter").sort_by{|m| m.round} + this_round_matches = Match.where("weight_id = ? and round = ? and (bracket_position = ? or bracket_position = ?)", @wrestler.weight_id, @wrestler.last_match.round, "Conso", "Conso Quarter") + # if a loser is dropping down + if next_round_matches.size == this_round_matches.size + new_match = Match.where("bracket_position_number = ? and weight_id = ? and round > ? and (bracket_position = ? or bracket_position = ?)", @wrestler.last_match.bracket_position_number,@wrestler.weight_id, @wrestler.last_match.round, "Conso", "Conso Quarter").sort_by{|m| m.round}.first + update_new_match(new_match, 2) + else + new_match = Match.where("bracket_position_number = ? and weight_id = ? and round > ? and (bracket_position = ? or bracket_position = ?)", @wrestler.next_match_position_number.ceil,@wrestler.weight_id, @wrestler.last_match.round, "Conso", "Conso Quarter").sort_by{|m| m.round}.first + update_new_match(new_match, get_wrestler_number) + end + end + end + + def update_new_match(match, wrestler_number) + if wrestler_number == 2 or match.loser1_name != nil + match.w2 = @wrestler.id + match.save + elsif + match.w1 = @wrestler.id + match.save + end + end + + def update_consolation_bye + 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 + next_match.first.replace_loser_name_with_bye("Loser of #{bout}") + end + end + + def get_wrestler_number + if @wrestler.next_match_position_number != @wrestler.next_match_position_number.ceil + return 1 + elsif @wrestler.next_match_position_number == @wrestler.next_match_position_number.ceil + return 2 + end + end + + 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 + next_match = next_match.first + next_match.replace_loser_name_with_wrestler(@wrestler,"Loser of #{bout}") + if next_match.loser1_name == "BYE" or next_match.loser2_name == "BYE" + next_match.winner_id = @wrestler.id + next_match.win_type = "BYE" + next_match.finished = 1 + next_match.save + next_match.advance_wrestlers + end + end + end +end diff --git a/app/services/tournament_services/generate_tournament_matches.rb b/app/services/tournament_services/generate_tournament_matches.rb index 6bebef1..209371c 100644 --- a/app/services/tournament_services/generate_tournament_matches.rb +++ b/app/services/tournament_services/generate_tournament_matches.rb @@ -33,8 +33,10 @@ class GenerateTournamentMatches def generate_raw standardStartingActions PoolToBracketMatchGeneration.new(@tournament).generatePoolToBracketMatches if @tournament.tournament_type == "Pool to bracket" + ModifiedSixteenManMatchGeneration.new(@tournament).generate_matches if @tournament.tournament_type == "Modified 16 Man Double Elimination" postMatchCreationActions PoolToBracketMatchGeneration.new(@tournament).assignLoserNames if @tournament.tournament_type == "Pool to bracket" + ModifiedSixteenManGenerateLoserNames.new(@tournament).assign_loser_names if @tournament.tournament_type == "Modified 16 Man Double Elimination" end def standardStartingActions @@ -45,7 +47,7 @@ class GenerateTournamentMatches end def postMatchCreationActions - moveFinalsMatchesToLastRound + moveFinalsMatchesToLastRound if @tournament.tournament_type == "Pool to bracket" assignBouts assignFirstMatchesToMats @tournament.curently_generating_matches = nil diff --git a/app/services/tournament_services/modified_sixteen_man_generate_loser_names.rb b/app/services/tournament_services/modified_sixteen_man_generate_loser_names.rb new file mode 100644 index 0000000..c5add12 --- /dev/null +++ b/app/services/tournament_services/modified_sixteen_man_generate_loser_names.rb @@ -0,0 +1,86 @@ +class ModifiedSixteenManGenerateLoserNames + def initialize( tournament ) + @tournament = tournament + end + + def assign_loser_names + matches_by_weight = nil + @tournament.weights.each do |w| + matches_by_weight = @tournament.matches.where(weight_id: w.id) + conso_round_2(matches_by_weight) + conso_round_3(matches_by_weight) + third_fourth(matches_by_weight) + save_matches(matches_by_weight) + matches_by_weight = @tournament.matches.where(weight_id: w.id).reload + advance_bye_matches_championship(matches_by_weight) + save_matches(matches_by_weight) + end + end + + def conso_round_2(matches) + matches.select{|m| m.round == 2 and m.bracket_position == "Conso"}.sort_by{|m| m.bracket_position_number}.each do |match| + if match.bracket_position_number == 1 + match.loser1_name = "Loser of #{matches.select{|m| m.bracket_position_number == 1 and m.round == 1 and m.bracket_position == "Bracket"}.first.bout_number}" + match.loser2_name = "Loser of #{matches.select{|m| m.bracket_position_number == 2 and m.round == 1 and m.bracket_position == "Bracket"}.first.bout_number}" + elsif match.bracket_position_number == 2 + match.loser1_name = "Loser of #{matches.select{|m| m.bracket_position_number == 3 and m.round == 1 and m.bracket_position == "Bracket"}.first.bout_number}" + match.loser2_name = "Loser of #{matches.select{|m| m.bracket_position_number == 4 and m.round == 1 and m.bracket_position == "Bracket"}.first.bout_number}" + elsif match.bracket_position_number == 3 + match.loser1_name = "Loser of #{matches.select{|m| m.bracket_position_number == 5 and m.round == 1 and m.bracket_position == "Bracket"}.first.bout_number}" + match.loser2_name = "Loser of #{matches.select{|m| m.bracket_position_number == 6 and m.round == 1 and m.bracket_position == "Bracket"}.first.bout_number}" + elsif match.bracket_position_number == 4 + match.loser1_name = "Loser of #{matches.select{|m| m.bracket_position_number == 7 and m.round == 1 and m.bracket_position == "Bracket"}.first.bout_number}" + match.loser2_name = "Loser of #{matches.select{|m| m.bracket_position_number == 8 and m.round == 1 and m.bracket_position == "Bracket"}.first.bout_number}" + end + end + end + + def conso_round_3(matches) + matches.select{|m| m.round == 3 and m.bracket_position == "Conso Quarter"}.sort_by{|m| m.bracket_position_number}.each do |match| + if match.bracket_position_number == 1 + match.loser1_name = "Loser of #{matches.select{|m| m.bracket_position_number == 4 and m.bracket_position == "Quarter"}.first.bout_number}" + elsif match.bracket_position_number == 2 + match.loser1_name = "Loser of #{matches.select{|m| m.bracket_position_number == 3 and m.bracket_position == "Quarter"}.first.bout_number}" + elsif match.bracket_position_number == 3 + match.loser1_name = "Loser of #{matches.select{|m| m.bracket_position_number == 2 and m.bracket_position == "Quarter"}.first.bout_number}" + elsif match.bracket_position_number == 4 + match.loser1_name = "Loser of #{matches.select{|m| m.bracket_position_number == 1 and m.bracket_position == "Quarter"}.first.bout_number}" + end + end + end + + def third_fourth(matches) + matches.select{|m| m.bracket_position == "3/4"}.sort_by{|m| m.bracket_position_number}.each do |match| + match.loser1_name = "Loser of #{matches.select{|m| m.bracket_position == "Semis"}.first.bout_number}" + match.loser2_name = "Loser of #{matches.select{|m| m.bracket_position == "Semis"}.second.bout_number}" + end + end + + def advance_bye_matches_championship(matches) + matches.select{|m| m.round == 1 and m.bracket_position == "Bracket"}.sort_by{|m| m.bracket_position_number}.each do |match| + if match.w1 == nil or match.w2 == nil + puts match.bout_number + match.finished = 1 + match.win_type = "BYE" + if match.w1 != nil + match.winner_id = match.w1 + match.loser2_name = "BYE" + match.save + match.advance_wrestlers + elsif match.w2 != nil + match.winner_id = match.w2 + match.loser1_name = "BYE" + match.save + match.advance_wrestlers + end + end + end + end + + def save_matches(matches) + matches.each do |m| + m.save! + end + end + +end \ No newline at end of file diff --git a/app/services/tournament_services/modified_sixteen_man_match_generation.rb b/app/services/tournament_services/modified_sixteen_man_match_generation.rb new file mode 100644 index 0000000..fc3f137 --- /dev/null +++ b/app/services/tournament_services/modified_sixteen_man_match_generation.rb @@ -0,0 +1,87 @@ +class ModifiedSixteenManMatchGeneration + def initialize( tournament ) + @tournament = tournament + end + + def generate_matches + @tournament.weights.each do |weight| + generate_matches_for_weight(weight) + end + end + + def generate_matches_for_weight(weight) + round_one(weight) + round_two(weight) + round_three(weight) + round_four(weight) + round_five(weight) + end + + def round_one(weight) + create_matchup_from_seed(1,16, "Bracket", 1, 1,weight) + create_matchup_from_seed(8,9, "Bracket", 2, 1,weight) + create_matchup_from_seed(5,12, "Bracket", 3, 1,weight) + create_matchup_from_seed(4,14, "Bracket", 4, 1,weight) + create_matchup_from_seed(3,13, "Bracket", 5, 1,weight) + create_matchup_from_seed(6,11, "Bracket", 6, 1,weight) + create_matchup_from_seed(7,10, "Bracket", 7, 1,weight) + create_matchup_from_seed(2,15, "Bracket", 8, 1,weight) + end + + def round_two(weight) + create_matchup(nil,nil,"Quarter",1,2,weight) + create_matchup(nil,nil,"Quarter",2,2,weight) + create_matchup(nil,nil,"Quarter",3,2,weight) + create_matchup(nil,nil,"Quarter",4,2,weight) + create_matchup(nil,nil,"Conso",1,2,weight) + create_matchup(nil,nil,"Conso",2,2,weight) + create_matchup(nil,nil,"Conso",3,2,weight) + create_matchup(nil,nil,"Conso",4,2,weight) + end + + def round_three(weight) + create_matchup(nil,nil,"Semis",1,3,weight) + create_matchup(nil,nil,"Semis",2,3,weight) + create_matchup(nil,nil,"Conso Quarter",1,3,weight) + create_matchup(nil,nil,"Conso Quarter",2,3,weight) + create_matchup(nil,nil,"Conso Quarter",3,3,weight) + create_matchup(nil,nil,"Conso Quarter",4,3,weight) + end + + def round_four(weight) + create_matchup(nil,nil,"Conso Semis",1,4,weight) + create_matchup(nil,nil,"Conso Semis",2,4,weight) + end + + def round_five(weight) + create_matchup(nil,nil,"1/2",1,5,weight) + create_matchup(nil,nil,"3/4",1,5,weight) + create_matchup(nil,nil,"5/6",1,5,weight) + end + + def wrestler_with_seed(seed,weight) + wrestler = Wrestler.where("weight_id = ? and bracket_line = ?", weight.id, seed).first + if wrestler + return wrestler.id + else + return nil + end + end + + def create_matchup_from_seed(w1_seed, w2_seed, bracket_position, bracket_position_number,round,weight) + # if wrestler_with_seed(w1_seed,weight) and wrestler_with_seed(w2_seed,weight) + create_matchup(wrestler_with_seed(w1_seed,weight),wrestler_with_seed(w2_seed,weight), bracket_position, bracket_position_number,round,weight) + # end + end + + def create_matchup(w1, w2, bracket_position, bracket_position_number,round,weight) + @tournament.matches.create( + w1: w1, + w2: w2, + weight_id: weight.id, + round: round, + bracket_position: bracket_position, + bracket_position_number: bracket_position_number + ) + end +end \ No newline at end of file diff --git a/app/services/wrestler_services/calculate_wrestler_team_score.rb b/app/services/wrestler_services/calculate_wrestler_team_score.rb index 59fbf5a..76f2983 100644 --- a/app/services/wrestler_services/calculate_wrestler_team_score.rb +++ b/app/services/wrestler_services/calculate_wrestler_team_score.rb @@ -25,7 +25,9 @@ class CalculateWrestlerTeamScore end def placement_points - PoolBracketPlacementPoints.new(@wrestler).calcPoints if @tournament.tournament_type == "Pool to bracket" + return PoolBracketPlacementPoints.new(@wrestler).calcPoints if @tournament.tournament_type == "Pool to bracket" + return ModifiedSixteenManPlacementPoints.new(@wrestler).calc_points if @tournament.tournament_type == "Modified 16 Man Double Elimination" + return 0 end def bracketPoints diff --git a/app/services/wrestler_services/modified_sixteen_man_placement_points.rb b/app/services/wrestler_services/modified_sixteen_man_placement_points.rb new file mode 100644 index 0000000..3c5bead --- /dev/null +++ b/app/services/wrestler_services/modified_sixteen_man_placement_points.rb @@ -0,0 +1,32 @@ +class ModifiedSixteenManPlacementPoints + def initialize(wrestler) + @wrestler = wrestler + @number_of_placers = 6 + end + + def calc_points + if won_bracket_position_size("1/2") > 0 + return PlacementPoints.new(@number_of_placers).firstPlace + elsif bracket_position_size("1/2") > 0 + return PlacementPoints.new(@number_of_placers).secondPlace + elsif won_bracket_position_size("3/4") > 0 + return PlacementPoints.new(@number_of_placers).thirdPlace + elsif bracket_position_size("Semis") > 0 + return PlacementPoints.new(@number_of_placers).fourthPlace + elsif won_bracket_position_size("5/6") > 0 + return PlacementPoints.new(@number_of_placers).fifthPlace + elsif bracket_position_size("5/6") > 0 + return PlacementPoints.new(@number_of_placers).sixthPlace + else + return 0 + end + end + + def bracket_position_size(bracket_position_name) + @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 +end \ No newline at end of file diff --git a/app/services/wrestler_services/placement_points.rb b/app/services/wrestler_services/placement_points.rb new file mode 100644 index 0000000..99e53c9 --- /dev/null +++ b/app/services/wrestler_services/placement_points.rb @@ -0,0 +1,53 @@ +class PlacementPoints + def initialize(number_of_placers) + @number_of_placers = number_of_placers + end + + def firstPlace + if @number_of_placers == 4 + return 14 + else + return 16 + end + end + + def secondPlace + if @number_of_placers == 4 + return 10 + else + return 12 + end + end + + def thirdPlace + if @number_of_placers == 4 + return 9 + else + return 7 + end + end + + def fourthPlace + if @number_of_placers == 4 + return 4 + else + return 7 + end + end + + def fifthPlace + 5 + end + + def sixthPlace + 3 + end + + def seventhPlace + 2 + end + + def eighthPlace + 1 + end +end \ No newline at end of file diff --git a/app/services/wrestler_services/pool_bracket_placement_points.rb b/app/services/wrestler_services/pool_bracket_placement_points.rb index 5b93edf..738020c 100644 --- a/app/services/wrestler_services/pool_bracket_placement_points.rb +++ b/app/services/wrestler_services/pool_bracket_placement_points.rb @@ -48,120 +48,72 @@ class PoolBracketPlacementPoints def fourPoolsToQuarter if bracket_position_size("Semis") > 0 - return fourthPlace + return PlacementPoints.new(number_of_placers).fourthPlace end if bracket_position_size("Quarter") > 0 - return eighthPlace + return PlacementPoints.new(number_of_placers).eighthPlace end return 0 end def twoPoolsToSemi if bracket_position_size("Semis") > 0 - return fourthPlace + return PlacementPoints.new(number_of_placers).fourthPlace end if bracket_position_size("Conso Semis") > 0 - return eighthPlace + return PlacementPoints.new(number_of_placers).eighthPlace end return 0 end def fourPoolsToSemi if bracket_position_size("Semis") > 0 - return fourthPlace + return PlacementPoints.new(number_of_placers).fourthPlace end if bracket_position_size("Conso Semis") > 0 - return eighthPlace + return PlacementPoints.new(number_of_placers).eighthPlace end return 0 end def onePool if @wrestler.pool_placement == 1 - return firstPlace + return PlacementPoints.new(number_of_placers).firstPlace elsif @wrestler.pool_placement == 2 - return secondPlace + return PlacementPoints.new(number_of_placers).secondPlace elsif @wrestler.pool_placement == 3 - return thirdPlace + return PlacementPoints.new(number_of_placers).thirdPlace elsif @wrestler.pool_placement == 4 - return fourthPlace + return PlacementPoints.new(number_of_placers).fourthPlace end return 0 end def finalMatchPoints if won_bracket_position_size("1/2") > 0 - return firstPlace + return PlacementPoints.new(number_of_placers).firstPlace end if won_bracket_position_size("3/4") > 0 - return thirdPlace + return PlacementPoints.new(number_of_placers).thirdPlace end if won_bracket_position_size("5/6") > 0 - return fifthPlace + return PlacementPoints.new(number_of_placers).fifthPlace end if won_bracket_position_size("7/8") > 0 - return seventhPlace + return PlacementPoints.new(number_of_placers).seventhPlace end if bracket_position_size("1/2") > 0 - return secondPlace + return PlacementPoints.new(number_of_placers).secondPlace end if bracket_position_size("3/4") > 0 - return fourthPlace + return PlacementPoints.new(number_of_placers).fourthPlace end if bracket_position_size("5/6") > 0 - return sixthPlace + return PlacementPoints.new(number_of_placers).sixthPlace end if bracket_position_size("7/8") > 0 - return eighthPlace + return PlacementPoints.new(number_of_placers).eighthPlace end return 0 end - - def firstPlace - if number_of_placers == 4 - return 14 - else - return 16 - end - end - - def secondPlace - if number_of_placers == 4 - return 10 - else - return 12 - end - end - - def thirdPlace - if number_of_placers == 4 - return 9 - else - return 7 - end - end - - def fourthPlace - if number_of_placers == 4 - return 4 - else - return 7 - end - end - - def fifthPlace - 5 - end - - def sixthPlace - 3 - end - - def seventhPlace - 2 - end - - def eighthPlace - 1 - end end diff --git a/app/views/tournaments/_bracket_director_actions.html.erb b/app/views/tournaments/_bracket_director_actions.html.erb new file mode 100644 index 0000000..1c95693 --- /dev/null +++ b/app/views/tournaments/_bracket_director_actions.html.erb @@ -0,0 +1,22 @@ +<% if can? :manage, @tournament %> +

Tournament Director Bracket Actions

+ + + + +
+ Swap Bracket Position + <%= form_for(Wrestler.new, url: swap_wrestlers_path(@tournament)) do |f| %> +
+ <%= f.label 'Wrestler 1' %>
+ <%= f.collection_select :originalId, @weight.wrestlers, :id, :name %> +
+
+ <%= f.label 'Wrestler 2' %>
+ <%= f.collection_select :swapId, @weight.wrestlers, :id, :name %> +
+
+ <%= submit_tag "Swap", :class=>"btn btn-success"%> + <% end %> +
+<% end %> \ No newline at end of file diff --git a/app/views/tournaments/_bracket_partial.html.erb b/app/views/tournaments/_bracket_partial.html.erb new file mode 100644 index 0000000..8881a43 --- /dev/null +++ b/app/views/tournaments/_bracket_partial.html.erb @@ -0,0 +1,95 @@ + + +
<%= @tournament.name %> - <%= @weight.max %> lbs Bracket
+ + <% if @tournament.tournament_type == "Pool to bracket" %> + + + + + <% elsif @tournament.tournament_type == "Modified 16 Man Double Elimination" %> + + <% end %> + +
+ <% @matches = @tournament.matches.select{|m| m.weight_id == @weight.id} %> + <% @wrestlers = Wrestler.where(weight_id: @weight.id) %> + <% @pools = @weight.pool_rounds(@matches) %> + <%= render 'pool' %> + + <% if @weight.pool_bracket_type == "twoPoolsToFinal" %> + <%= render 'twoPoolFinalBracket' %> + <% end %> + <% if @weight.pool_bracket_type == "twoPoolsToSemi" %> + <%= render 'twoPoolSemiBracket' %> + <% end %> + <% if @weight.pool_bracket_type == "fourPoolsToQuarter" %> + <%= render 'fourPoolQuarterBracket' %> + <% end %> + <% if @weight.pool_bracket_type == "eightPoolsToQuarter" %> + <%= render 'fourPoolQuarterBracket' %> + <% end %> + <% if @weight.pool_bracket_type == "fourPoolsToSemi" %> + <%= render 'fourPoolSemiBracket' %> + <% end %> + + <%= render 'modified_sixteen_man_double_elimination_bracket' %> +
\ No newline at end of file diff --git a/app/views/tournaments/_modified_sixteen_man_double_elimination_bracket.html.erb b/app/views/tournaments/_modified_sixteen_man_double_elimination_bracket.html.erb new file mode 100644 index 0000000..a471422 --- /dev/null +++ b/app/views/tournaments/_modified_sixteen_man_double_elimination_bracket.html.erb @@ -0,0 +1,131 @@ +

Championship Bracket

+
+ + + + + + <% end %> +
+

3/4 place match

+
+ + + <% end %> +
+

Consolation Bracket

+
+ + + + + + <% end %> +
\ No newline at end of file diff --git a/app/views/tournaments/all_brackets.html.erb b/app/views/tournaments/all_brackets.html.erb index 215be07..ded7392 100644 --- a/app/views/tournaments/all_brackets.html.erb +++ b/app/views/tournaments/all_brackets.html.erb @@ -1,104 +1,26 @@ -<% cache ["#{@tournament.id}_all_brackets", @tournament] do %> - - - +<% cache ["#{@tournament.id}_all_brackets", @tournament] do %>
<%= render :file => 'tournaments/team_scores' %> - <% @tournament.weights.sort_by{|w| w.max}.each do |w| %> + <% @tournament.weights.sort_by{|w| w.max}.each do |weight| %> -
<%= @tournament.name %> - <%= w.max %> lbs Bracket
- - - + <% if @tournament.tournament_type == "Pool to bracket" %> + <% elsif @tournament.tournament_type == "Modified 16 Man Double Elimination" %> + + <% end %>
- <% @weight = w %> - <% @matches = @tournament.matches.select{|m| m.weight_id == @weight.id} %> - <% @wrestlers = Wrestler.where(weight_id: @weight.id) %> - <% @pools = w.pool_rounds(@matches) %> - <%= render 'pool' %> - - <% if w.pool_bracket_type == "twoPoolsToFinal" %> - <%= render 'twoPoolFinalBracket' %> - <% end %> - <% if w.pool_bracket_type == "twoPoolsToSemi" %> - <%= render 'twoPoolSemiBracket' %> - <% end %> - <% if w.pool_bracket_type == "fourPoolsToQuarter" or w.pool_bracket_type == "eightPoolsToQuarter" %> - <%= render 'fourPoolQuarterBracket' %> - <% end %> - <% if w.pool_bracket_type == "fourPoolsToSemi" %> - <%= render 'fourPoolSemiBracket' %> - <% end %> + + <% @matches = @tournament.matches.select{|m| m.weight_id == weight.id} %> + <% @wrestlers = Wrestler.where(weight_id: weight.id) %> + <% @pools = weight.pool_rounds(@matches) %> + <% @weight = weight %> + <%= render 'bracket_partial' %> + + <% @matches = weight.matches %> + <% @weight = weight %> + <%= render 'bracket_partial' %> +
<% end %> diff --git a/app/views/tournaments/bracket.html.erb b/app/views/tournaments/bracket.html.erb index aa3301c..1817b7a 100644 --- a/app/views/tournaments/bracket.html.erb +++ b/app/views/tournaments/bracket.html.erb @@ -1,95 +1,8 @@ - <% cache ["#{@weight.id}_bracket", @weight] do %> - -
<%= @tournament.name %> - <%= @weight.max %> lbs Bracket
- - - - - - -
- <% @matches = @tournament.matches.select{|m| m.weight_id == @weight.id} %> - <% @wrestlers = Wrestler.where(weight_id: @weight.id) %> - <% @pools = @weight.pool_rounds(@matches) %> - <%= render 'pool' %> - - <% if @weight.pool_bracket_type == "twoPoolsToFinal" %> - <%= render 'twoPoolFinalBracket' %> - <% end %> - <% if @weight.pool_bracket_type == "twoPoolsToSemi" %> - <%= render 'twoPoolSemiBracket' %> - <% end %> - <% if @weight.pool_bracket_type == "fourPoolsToQuarter" %> - <%= render 'fourPoolQuarterBracket' %> - <% end %> - <% if @weight.pool_bracket_type == "eightPoolsToQuarter" %> - <%= render 'fourPoolQuarterBracket' %> - <% end %> - <% if @weight.pool_bracket_type == "fourPoolsToSemi" %> - <%= render 'fourPoolSemiBracket' %> - <% end %> -
+<%= render 'bracket_partial' %> <% end %> - <% if @tournament.tournament_type == "Pool to bracket" %> <%= render 'pool_bracket_director_actions' %> +<% elsif @tournament.tournament_type == "Modified 16 Man Double Elimination" %> + <%= render 'bracket_director_actions' %> <% end %> \ No newline at end of file