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

Added 16 man modified double elimination bracket type. Still need to fix swap wrestlers code.

This commit is contained in:
2020-01-23 07:46:23 -05:00
parent 314124107c
commit ff102a1862
18 changed files with 744 additions and 265 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -0,0 +1,22 @@
<% if can? :manage, @tournament %>
<h3>Tournament Director Bracket Actions</h3>
<table class="table">
<tr>
<td>
<strong>Swap Bracket Position</strong>
<%= form_for(Wrestler.new, url: swap_wrestlers_path(@tournament)) do |f| %>
<div class="field">
<%= f.label 'Wrestler 1' %><br>
<%= f.collection_select :originalId, @weight.wrestlers, :id, :name %>
</div>
<div class="field">
<%= f.label 'Wrestler 2' %><br>
<%= f.collection_select :swapId, @weight.wrestlers, :id, :name %>
</div>
<br>
<%= submit_tag "Swap", :class=>"btn btn-success"%>
<% end %>
</td>
</tr>
</table>
<% end %>

View File

@@ -0,0 +1,95 @@
<style>
table.smallText tr td { font-size: 10px; }
/*
* Bracket Layout Specifics
*/
main {
display:flex;
}
.round {
display:flex;
flex-direction:column;
width: 145px;
list-style:none;
padding:0;
font-size: 10px;
}
.game + li {
flex-grow:1;
}
li:first-child,li:last-child {
flex-grow:.5;
}
.game {
padding-left:5px;
}
.winner {
font-weight:bold;
}
.game span {
float:right;
margin-right:5px;
}
.game-top {
border-bottom:1px solid #aaa;
}
.game-top + li {
border-right:1px solid #aaa; min-height:5px;
}
.bout-number {
text-align: center;
padding-top: 15px;
}
.bracket-winner {
border-bottom:1px solid #aaa;
}
.game-bottom {
border-bottom:1px solid #aaa; border-right:1px solid #aaa;
}
</style>
<table class='smallText'>
<h5><strong><%= @tournament.name %> - <%= @weight.max %> lbs Bracket</strong></h5>
<tr>
<% if @tournament.tournament_type == "Pool to bracket" %>
<td valign="top" style="padding: 10px;">
<% @matches = @tournament.matches.select{|m| m.weight_id == @weight.id} %>
<% @wrestlers = Wrestler.where(weight_id: @weight.id) %>
<% @pools = @weight.pool_rounds(@matches) %>
<%= render 'pool' %>
</td>
<td valign="top" style="padding: 10px;">
<% 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 %>
</td>
<% elsif @tournament.tournament_type == "Modified 16 Man Double Elimination" %>
<td valign="top" style="padding: 10px;">
<%= render 'modified_sixteen_man_double_elimination_bracket' %>
</td>
<% end %>
</tr>
</table>

View File

@@ -0,0 +1,131 @@
<h4>Championship Bracket</h4>
<main id="bracket">
<ul class="round round-1">
<% @matches.select{|m|m.bracket_position == "Bracket" and m.round == 1}.sort_by{|m| m.bracket_position_number}.each do |match| %>
<li>&nbsp;</li>
<li class="game game-top "><%= match.w1_bracket_name_round_one %> <span></span></li>
<li class="bout-number"><%= match.bout_number %> <%= match.bracket_score_string %>&nbsp;</li>
<li class="game game-bottom "><%= match.w2_bracket_name_round_one %><span></span></li>
<li>&nbsp;</li>
<% end %>
</ul>
<ul class="round round-2">
<% @matches.select{|m|m.bracket_position == "Quarter"}.sort_by{|m| m.bracket_position_number}.each do |match| %>
<li></li>
<li class="game game-top "><%= match.w1_bracket_name %> <span></span></li>
<li class="bout-number"><%= match.bout_number %> <%= match.bracket_score_string %>&nbsp;</li>
<li class="game game-bottom "><%= match.w2_bracket_name %><span></span></li>
<li></li>
<% end %>
</ul>
<ul class="round round-3">
<% @matches.select{|m|m.bracket_position == "Semis"}.sort_by{|m| m.bracket_position_number}.each do |match| %>
<li></li>
<li class="game game-top "><%= match.w1_bracket_name %> <span></span></li>
<li class="bout-number"><%= match.bout_number %> <%= match.bracket_score_string %>&nbsp;</li>
<li class="game game-bottom "><%= match.w2_bracket_name %><span></span></li>
<li></li>
<% end %>
</ul>
<ul class="round round-4">
<% @matches.select{|m|m.bracket_position == "1/2"}.each do |match| %>
<li></li>
<li class="game game-top "><%= match.w1_bracket_name %> <span></span></li>
<li class="bout-number"><%= match.bout_number %> <%= match.bracket_score_string %>&nbsp;</li>
<li class="game game-bottom "><%= match.w2_bracket_name %><span></span></li>
<li></li>
</ul>
<ul class="round round-5">
<li></li>
<li class="bracket-winner"> <%= match.bracket_winner_name %> <span></span></li>
1st
<li></li>
</ul>
<% end %>
</main>
<h4>3/4 place match</h4>
<main id="bracket">
<ul class="round round-3">
<% @matches.select{|m|m.bracket_position == "3/4"}.each do |match| %>
<li>&nbsp;</li>
<li class="game game-top "><%= match.w1_bracket_name %> <span></span></li>
<li class="bout-number"><%= match.bout_number %> <%= match.bracket_score_string %>&nbsp;</li>
<li class="game game-bottom "><%= match.w2_bracket_name %><span></span></li>
<li>&nbsp;</li>
</ul>
<ul class="round round-4">
<li>&nbsp;</li>
<li class="bracket-winner"> <%= match.bracket_winner_name %> <span></span></li>
3rd
<li>&nbsp;</li>
</ul>
<% end %>
</main>
<h4>Consolation Bracket</h4>
<main id="bracket">
<ul class="round round-1">
<% @matches.select{|m|m.bracket_position == "Conso" and m.round == 2}.sort_by{|m| m.bracket_position_number}.each do |match| %>
<li>&nbsp;</li>
<li>&nbsp;</li>
<li class="game game-top "><%= match.w1_bracket_name %> <span></span></li>
<li class="bout-number"><%= match.bout_number %> <%= match.bracket_score_string %>&nbsp;</li>
<li class="game game-bottom "><%= match.w2_bracket_name %><span></span></li>
<% end %>
</ul>
<ul class="round round-2">
<% @matches.select{|m|m.bracket_position == "Conso Quarter"}.sort_by{|m| m.bracket_position_number}.each do |match| %>
<li>&nbsp;</li>
<li class="game game-top "><%= match.w1_bracket_name %> <span></span></li>
<li class="bout-number"><%= match.bout_number %> <%= match.bracket_score_string %>&nbsp;</li>
<li class="game game-bottom "><%= match.w2_bracket_name %><span></span></li>
<li>&nbsp;</li>
<% end %>
</ul>
<ul class="round round-3">
<% @matches.select{|m|m.bracket_position == "Conso Semis"}.sort_by{|m| m.bracket_position_number}.each do |match| %>
<li>&nbsp;</li>
<li class="game game-top "><%= match.w1_bracket_name %> <span></span></li>
<li class="bout-number"><%= match.bout_number %> <%= match.bracket_score_string %>&nbsp;</li>
<li class="game game-bottom "><%= match.w2_bracket_name %><span></span></li>
<li>&nbsp;</li>
<% end %>
</ul>
<ul class="round round-4">
<% @matches.select{|m|m.bracket_position == "5/6"}.each do |match| %>
<li>&nbsp;</li>
<li class="game game-top "><%= match.w1_bracket_name %> <span></span></li>
<li class="bout-number"><%= match.bout_number %> <%= match.bracket_score_string %>&nbsp;</li>
<li class="game game-bottom "><%= match.w2_bracket_name %><span></span></li>
<li>&nbsp;</li>
</ul>
<ul class="round round-5">
<li>&nbsp;</li>
<li class="bracket-winner"> <%= match.bracket_winner_name %> <span></span></li>
5th
<li>&nbsp;</li>
</ul>
<% end %>
</main>

View File

@@ -1,104 +1,26 @@
<% cache ["#{@tournament.id}_all_brackets", @tournament] do %>
<style>
.pagebreak {
page-break-after: always;
border: none;
margin: 0px;
padding: 0px;
width: 8in; /* width: 7in; */
height: 9.5in; /* or height: 9.5in; */
font-size: 8px;
position: relative;
left: 0in;
height: 1in;
}
/*
* Bracket Layout Specifics
*/
main, ul {
display:flex;
}
ul {
flex-direction:column;
width: 125px;
list-style:none;
padding:0;
}
.game + li {
flex-grow:1;
}
li:first-child,li:last-child {
flex-grow:.5;
}
.game {
padding-left:5px;
}
.winner {
font-weight:bold;
}
.game span {
float:right;
margin-right:5px;
}
.game-top {
border-bottom:1px solid #aaa;
}
.game-top + li {
border-right:1px solid #aaa; min-height:60px;
}
.bracket-winner {
border-bottom:1px solid #aaa;
}
.bout-number {
text-align: center;
padding-top: 15px;
}
.game-bottom {
border-top:1px solid #aaa;
}
</style>
<% cache ["#{@tournament.id}_all_brackets", @tournament] do %>
<div id="exportable">
<%= 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| %>
<table class='pagebreak'>
<h5><strong><%= @tournament.name %> - <%= w.max %> lbs Bracket</strong></h5>
<tr>
<td valign="top" style="padding: 0px;">
<% @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' %>
</td>
<% if @tournament.tournament_type == "Pool to bracket" %>
<td valign="top" style="padding: 10px;">
<% 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 %>
<!-- Need to define what the tournaments#bracket controller defines -->
<% @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' %>
</td>
<% elsif @tournament.tournament_type == "Modified 16 Man Double Elimination" %>
<td valign="top" style="padding: 10px;">
<!-- Need to define what the tournaments#bracket controller defines -->
<% @matches = weight.matches %>
<% @weight = weight %>
<%= render 'bracket_partial' %>
</td>
<% end %>
</tr>
</table>
<% end %>

View File

@@ -1,95 +1,8 @@
<style>
table.smallText tr td { font-size: 10px; }
/*
* Bracket Layout Specifics
*/
main {
display:flex;
}
.round {
display:flex;
flex-direction:column;
width: 145px;
list-style:none;
padding:0;
font-size: 10px;
}
.game + li {
flex-grow:1;
}
li:first-child,li:last-child {
flex-grow:.5;
}
.game {
padding-left:5px;
}
.winner {
font-weight:bold;
}
.game span {
float:right;
margin-right:5px;
}
.game-top {
border-bottom:1px solid #aaa;
}
.game-top + li {
border-right:1px solid #aaa; min-height:60px;
}
.bout-number {
text-align: center;
padding-top: 20px;
}
.bracket-winner {
border-bottom:1px solid #aaa;
}
.game-bottom {
border-top:1px solid #aaa;
}
</style>
<% cache ["#{@weight.id}_bracket", @weight] do %>
<table class='smallText'>
<h5><strong><%= @tournament.name %> - <%= @weight.max %> lbs Bracket</strong></h5>
<tr>
<td valign="top" style="padding: 10px;">
<% @matches = @tournament.matches.select{|m| m.weight_id == @weight.id} %>
<% @wrestlers = Wrestler.where(weight_id: @weight.id) %>
<% @pools = @weight.pool_rounds(@matches) %>
<%= render 'pool' %>
</td>
<td valign="top" style="padding: 10px;">
<% 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 %>
</td>
</tr>
</table>
<%= 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 %>