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

Consolidated the double elimination bracket view, the double elimination match generation, and the double elimination loser names

This commit is contained in:
2024-12-04 17:01:02 -05:00
parent 5d37e5e0d8
commit db440c0603
12 changed files with 341 additions and 438 deletions

View File

@@ -201,7 +201,7 @@ class Match < ApplicationRecord
return_string_ending = return_string_ending + "</strong>"
end
if self.w2 != nil
if self.round == 1 and self.bracket_position == "Bracket"
if self.round == 1 and (self.bracket_position == "Bracket" or self.bracket_position == "Quarter")
if self.wrestler2.original_seed
return_string = return_string + "#{wrestler2.original_seed} "
end

View File

@@ -153,5 +153,30 @@ class Weight < ApplicationRecord
def wrestlers_without_pool_assignment
wrestlers.select{|w| w.pool == nil}
end
def calculate_bracket_size()
num_wrestlers = wrestlers.reload.size
return nil if num_wrestlers <= 0 # Handle invalid input
# Find the smallest power of 2 greater than or equal to num_wrestlers
2**Math.log2(num_wrestlers).ceil
end
def highest_bracket_round
bracket_matches_sorted_by_round_descending = matches.select{|m| m.bracket_position == "Bracket"}.sort_by{|m| m.round}.reverse
if bracket_matches_sorted_by_round_descending.size > 0
return bracket_matches_sorted_by_round_descending.first.round
else
return nil
end
end
def highest_conso_round
conso_matches_sorted_by_round_descending = matches.select{|m| m.bracket_position == "Conso"}.sort_by{|m| m.round}.reverse
if conso_matches_sorted_by_round_descending.size > 0
return conso_matches_sorted_by_round_descending.first.round
else
return nil
end
end
end

View File

@@ -5,9 +5,111 @@ class DoubleEliminationGenerateLoserNames
def assign_loser_names
@tournament.weights.each do |weight|
SixteenManDoubleEliminationGenerateLoserNames.new(weight).assign_loser_names_for_weight if weight.wrestlers.size >= 9 and weight.wrestlers.size <= 16
EightManDoubleEliminationGenerateLoserNames.new(weight).assign_loser_names_for_weight if weight.wrestlers.size >= 4 and weight.wrestlers.size <= 8
assign_loser_names_for_weight(weight)
advance_bye_matches_championship(weight.matches.reload)
end
end
def define_losername_championship_mappings(bracket_size)
# [conso_round, conso_bracket_position, championship_round, championship_bracket_position, cross_bracket, both_wrestlers]
# cross_bracket is true or false. crossing should happen every other round.
# both_wrestlers defines if you're filling out loser1_name and loser2_name or just loser1_name
# don't need to define 3/4, 5/6, or 7/8 those happen in the assign_loser_names_for_weight method
case bracket_size
when 8 then
return [
[2, "Conso Quarter", 1, "Quarter", false, true],
[3, "Conso Semis", 2, "Semis", true, false]
]
when 16 then
return [
[2, "Conso", 1, "Bracket", false, true],
[3, "Conso", 2, "Quarter", true],
[5, "Conso Semis", 4, "Semis", false]
]
else
return nil
end
end
def assign_loser_names_for_weight(weight)
number_of_placers = @tournament.number_of_placers
bracket_size = weight.calculate_bracket_size
matches_by_weight = weight.matches
loser_name_championship_mappings = define_losername_championship_mappings(bracket_size)
loser_name_championship_mappings.each do |mapping|
conso_round = mapping[0]
conso_bracket_position = mapping[1]
championship_round = mapping[2]
championship_bracket_position = mapping[3]
cross_bracket = mapping[4]
both_wrestlers = mapping[5]
conso_matches = matches_by_weight.select{|match| match.round == conso_round && match.bracket_position == conso_bracket_position}.sort_by{|match| match.bracket_position_number}
championship_matches = matches_by_weight.select{|match| match.round == championship_round && match.bracket_position == championship_bracket_position}.sort_by{|match| match.bracket_position_number}
if cross_bracket
conso_matches = conso_matches.reverse!
end
championship_bracket_position_number = 1
conso_matches.each do |match|
bout_number1 = championship_matches.select{|bout_match| bout_match.bracket_position_number == championship_bracket_position_number}.first.bout_number
match.loser1_name = "Loser of #{bout_number1}"
if both_wrestlers
championship_bracket_position_number += 1
bout_number2 = championship_matches.select{|bout_match| bout_match.bracket_position_number == championship_bracket_position_number}.first.bout_number
match.loser2_name = "Loser of #{bout_number2}"
end
championship_bracket_position_number += 1
end
end
conso_semi_matches = matches_by_weight.select{|match| match.bracket_position == "Conso Semis"}
conso_quarter_matches = matches_by_weight.select{|match| match.bracket_position == "Conso Quarter"}
if number_of_placers >= 6
five_six_match = matches_by_weight.select{|match| match.bracket_position == "5/6"}.first
bout_number1 = conso_semi_matches.select{|match| match.bracket_position_number == 1}.first.bout_number
bout_number2 = conso_semi_matches.select{|match| match.bracket_position_number == 2}.first.bout_number
five_six_match.loser1_name = "Loser of #{bout_number1}"
five_six_match.loser2_name = "Loser of #{bout_number2}"
end
if number_of_placers >= 8
seven_eight_match = matches_by_weight.select{|match| match.bracket_position == "7/8"}.first
bout_number1 = conso_quarter_matches.select{|match| match.bracket_position_number == 1}.first.bout_number
bout_number2 = conso_quarter_matches.select{|match| match.bracket_position_number == 2}.first.bout_number
seven_eight_match.loser1_name = "Loser of #{bout_number1}"
seven_eight_match.loser2_name = "Loser of #{bout_number2}"
end
save_matches(matches_by_weight)
end
def save_matches(matches)
matches.each do |m|
m.save!
end
end
def advance_bye_matches_championship(matches)
matches.select{|m| m.round == 1 and (m.bracket_position == "Bracket" or m.bracket_position == "Quarter")}.sort_by{|m| m.bracket_position_number}.each do |match|
if match.w1 == nil or match.w2 == nil
match.finished = 1
match.win_type = "BYE"
if match.w1 != nil
match.winner_id = match.w1
match.loser2_name = "BYE"
match.score = ""
match.save
match.advance_wrestlers
elsif match.w2 != nil
match.winner_id = match.w2
match.loser1_name = "BYE"
match.score = ""
match.save
match.advance_wrestlers
end
end
end
end
end

View File

@@ -1,3 +1,5 @@
BracketMatchups = Struct.new(:round_one_matchups, :championship_rounds, :consolation_rounds)
class DoubleEliminationMatchGeneration
def initialize( tournament )
@tournament = tournament
@@ -5,8 +7,126 @@ class DoubleEliminationMatchGeneration
def generate_matches
@tournament.weights.each do |weight|
SixteenManDoubleEliminationMatchGeneration.new(weight).generate_matches_for_weight if weight.wrestlers.size >= 9 and weight.wrestlers.size <= 16
EightManDoubleEliminationMatchGeneration.new(weight).generate_matches_for_weight if weight.wrestlers.size >= 4 and weight.wrestlers.size <= 8
generate_matches_for_weight(weight)
end
end
def define_bracket_matches(bracket_size)
# Defined at the top of the file
# BracketMatchups = Struct.new(:round_one_matchups, :championship_rounds, :consolation_rounds)
# round_one_matchups are the matchups by seed in the correct order for bracket position.
# championship_rounds define [round_number, number_of_matches_in_round, bracket_position]
# consolation_rounds define [round_number, number_of_matches_in_round, bracket_position]
case bracket_size
when 8 then
return BracketMatchups.new(
[[1, 8, "Quarter"], [4, 5, "Quarter"], [3, 6, "Quarter"], [2, 7, "Quarter"]],
[[2, 2, "Semis"], [4, 1, "1/2"]],
[[2, 2, "Conso Quarter"], [3, 2, "Conso Semis"], [4, 1, "3/4"]]
)
when 16 then
return BracketMatchups.new(
[[1, 16, "Bracket"], [8, 9, "Bracket"], [5, 12, "Bracket"], [4, 14, "Bracket"], [3, 13, "Bracket"], [6, 11, "Bracket"], [7, 10, "Bracket"], [2, 15, "Bracket"]],
[[2, 4, "Quarter"], [4, 2, "Semis"], [6, 1, "1/2"]],
[[2, 4, "Conso"], [3, 4, "Conso"], [4, 2, "Conso Quarter"], [5, 2, "Conso Semis"], [6, 1, "3/4"]]
)
else
return nil
end
end
def generate_matches_for_weight(weight)
number_of_placers = @tournament.number_of_placers
bracket_size = weight.calculate_bracket_size
bracket_matches = define_bracket_matches(bracket_size)
# Generate round 1 matches
bracket_matches.round_one_matchups.each_with_index do |matchup, index|
matches_this_round = bracket_matches.round_one_matchups.size
bracket_position = matchup[2]
create_matchup_from_seed(
matchup[0],
matchup[1],
bracket_position,
index + 1,
1,
weight
)
end
# Generate remaining championship rounds
bracket_matches.championship_rounds.each do |matchup|
round = matchup[0]
matches_this_round = matchup[1]
bracket_position = matchup[2]
matches_this_round.times do |bracket_position_number|
create_matchup(nil, nil, bracket_position, bracket_position_number + 1, round, weight)
end
end
# Generate consolation matches
bracket_matches.consolation_rounds.each do |matchup|
round = matchup[0]
matches_this_round = matchup[1]
bracket_position = matchup[2]
matches_this_round.times do |bracket_position_number|
create_matchup(nil, nil, bracket_position, bracket_position_number + 1, round, weight)
end
create_matchup(nil, nil, "5/6", 1, round, weight) if @tournament.number_of_placers >= 6 && matches_this_round == 1
create_matchup(nil, nil, "7/8", 1, round, weight) if @tournament.number_of_placers >= 8 && matches_this_round == 1
end
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)
create_matchup(wrestler_with_seed(w1_seed,weight),wrestler_with_seed(w2_seed,weight), bracket_position, bracket_position_number,round,weight)
end
def create_matchup(w1, w2, bracket_position, bracket_position_number,round,weight)
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
#### Logic below works but not used. Could not find a way to reliably determine a couple things.
# For example, properly forcing the semis to be after round 2 of consolations in a 16 man bracket.
# and properly calculating the number of matches in a round for the consolation rounds.
def calculate_championship_rounds(bracket_size)
return nil if bracket_size <= 0 # Handle invalid input
Math.log2(bracket_size).to_i
end
def calculate_consolation_rounds(bracket_size)
return nil if bracket_size <= 0 || !bracket_size.is_a?(Integer)
championship_rounds = calculate_championship_rounds(bracket_size)
if championship_rounds == 2
return 1
elsif
championship_rounds == 1
return 0
end
extra_powers_of_two = championship_rounds - 3
consolation_rounds = championship_rounds + extra_powers_of_two
consolation_rounds
end
end

View File

@@ -1,75 +0,0 @@
class EightManDoubleEliminationGenerateLoserNames
def initialize( weight )
@weight = weight
end
def assign_loser_names_for_weight
matches_by_weight = nil
matches_by_weight = @weight.matches
conso_round_2(matches_by_weight)
conso_round_4(matches_by_weight)
fifth_sixth(matches_by_weight)
save_matches(matches_by_weight)
matches_by_weight = @weight.matches.reload
advance_bye_matches_championship(matches_by_weight)
save_matches(matches_by_weight)
end
def conso_round_2(matches)
matches.select{|m| 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 == 1 and m.round == 1 and m.bracket_position == "Quarter"}.first.bout_number}"
match.loser2_name = "Loser of #{matches.select{|m| m.bracket_position_number == 2 and m.round == 1 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.round == 1 and m.bracket_position == "Quarter"}.first.bout_number}"
match.loser2_name = "Loser of #{matches.select{|m| m.bracket_position_number == 4 and m.round == 1 and m.bracket_position == "Quarter"}.first.bout_number}"
end
end
end
def conso_round_4(matches)
matches.select{|m| m.bracket_position == "Conso Semis"}.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 == 2 and m.bracket_position == "Semis"}.first.bout_number}"
elsif match.bracket_position_number == 2
match.loser1_name = "Loser of #{matches.select{|m| m.bracket_position_number == 1 and m.bracket_position == "Semis"}.first.bout_number}"
end
end
end
def fifth_sixth(matches)
matches.select{|m| m.bracket_position == "5/6"}.sort_by{|m| m.bracket_position_number}.each do |match|
match.loser1_name = "Loser of #{matches.select{|m| m.bracket_position == "Conso Semis"}.first.bout_number}"
match.loser2_name = "Loser of #{matches.select{|m| m.bracket_position == "Conso Semis"}.second.bout_number}"
end
end
def advance_bye_matches_championship(matches)
matches.select{|m| m.round == 1 and m.bracket_position == "Quarter"}.sort_by{|m| m.bracket_position_number}.each do |match|
if match.w1 == nil or match.w2 == nil
match.finished = 1
match.win_type = "BYE"
if match.w1 != nil
match.winner_id = match.w1
match.loser2_name = "BYE"
match.score = ""
match.save
match.advance_wrestlers
elsif match.w2 != nil
match.winner_id = match.w2
match.loser1_name = "BYE"
match.score = ""
match.save
match.advance_wrestlers
end
end
end
end
def save_matches(matches)
matches.each do |m|
m.save!
end
end
end

View File

@@ -1,63 +0,0 @@
class EightManDoubleEliminationMatchGeneration
def initialize( weight )
@weight = weight
end
def generate_matches_for_weight
round_one(@weight)
round_two(@weight)
round_three(@weight)
round_four(@weight)
end
def round_one(weight)
create_matchup_from_seed(1,8,"Quarter",1,1,weight)
create_matchup_from_seed(4,5,"Quarter",2,1,weight)
create_matchup_from_seed(3,6,"Quarter",3,1,weight)
create_matchup_from_seed(2,7,"Quarter",4,1,weight)
end
def round_two(weight)
create_matchup(nil,nil,"Semis",1,2,weight)
create_matchup(nil,nil,"Semis",2,2,weight)
create_matchup(nil,nil,"Conso Quarter",1,2,weight)
create_matchup(nil,nil,"Conso Quarter",2,2,weight)
end
def round_three(weight)
create_matchup(nil,nil,"Conso Semis",1,3,weight)
create_matchup(nil,nil,"Conso Semis",2,3,weight)
end
def round_four(weight)
create_matchup(nil,nil,"1/2",1,4,weight)
create_matchup(nil,nil,"3/4",1,4,weight)
create_matchup(nil,nil,"5/6",1,4,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)
@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

@@ -1,104 +0,0 @@
class SixteenManDoubleEliminationGenerateLoserNames
def initialize( weight )
@weight = weight
end
def assign_loser_names_for_weight
matches_by_weight = nil
matches_by_weight = @weight.matches
conso_round_2(matches_by_weight)
conso_round_3(matches_by_weight)
conso_round_5(matches_by_weight)
fifth_sixth(matches_by_weight)
seventh_eighth(matches_by_weight)
save_matches(matches_by_weight)
matches_by_weight = @weight.matches.reload
advance_bye_matches_championship(matches_by_weight)
save_matches(matches_by_weight)
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"}.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 conso_round_5(matches)
matches.select{|m| m.round == 5 and m.bracket_position == "Conso Semis"}.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.bracket_position == "Semis"}.first.bout_number}"
elsif match.bracket_position_number == 2
match.loser1_name = "Loser of #{matches.select{|m| m.bracket_position_number == 2 and m.bracket_position == "Semis"}.first.bout_number}"
end
end
end
def fifth_sixth(matches)
matches.select{|m| m.bracket_position == "5/6"}.sort_by{|m| m.bracket_position_number}.each do |match|
match.loser1_name = "Loser of #{matches.select{|m| m.bracket_position == "Conso Semis"}.first.bout_number}"
match.loser2_name = "Loser of #{matches.select{|m| m.bracket_position == "Conso Semis"}.second.bout_number}"
end
end
def seventh_eighth(matches)
matches.select{|m| m.bracket_position == "7/8"}.sort_by{|m| m.bracket_position_number}.each do |match|
match.loser1_name = "Loser of #{matches.select{|m| m.bracket_position == "Conso Quarter"}.first.bout_number}"
match.loser2_name = "Loser of #{matches.select{|m| m.bracket_position == "Conso Quarter"}.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
match.finished = 1
match.win_type = "BYE"
if match.w1 != nil
match.winner_id = match.w1
match.loser2_name = "BYE"
match.score = ""
match.save
match.advance_wrestlers
elsif match.w2 != nil
match.winner_id = match.w2
match.loser1_name = "BYE"
match.score = ""
match.save
match.advance_wrestlers
end
end
end
end
def save_matches(matches)
matches.each do |m|
m.save!
end
end
end

View File

@@ -1,91 +0,0 @@
class SixteenManDoubleEliminationMatchGeneration
def initialize( weight )
@weight = weight
@number_of_placers = @weight.tournament.number_of_placers
end
def generate_matches_for_weight
round_one(@weight)
round_two(@weight)
round_three(@weight)
round_four(@weight)
round_five(@weight)
round_six(@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,"Conso",1,3,weight)
create_matchup(nil,nil,"Conso",2,3,weight)
create_matchup(nil,nil,"Conso",3,3,weight)
create_matchup(nil,nil,"Conso",4,3,weight)
end
def round_four(weight)
create_matchup(nil,nil,"Semis",1,4,weight)
create_matchup(nil,nil,"Semis",2,4,weight)
create_matchup(nil,nil,"Conso Quarter",1,4,weight)
create_matchup(nil,nil,"Conso Quarter",2,4,weight)
end
def round_five(weight)
create_matchup(nil,nil,"Conso Semis",1,5,weight)
create_matchup(nil,nil,"Conso Semis",2,5,weight)
end
def round_six(weight)
create_matchup(nil,nil,"1/2",1,6,weight)
create_matchup(nil,nil,"3/4",1,6,weight)
create_matchup(nil,nil,"5/6",1,6,weight)
if @number_of_placers >= 8
create_matchup(nil,nil,"7/8",1,6,weight)
end
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)
@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

@@ -1,5 +1,48 @@
<% if @weight.wrestlers.size <= 16 and @weight.wrestlers.size >= 9 %>
<%= render 'sixteen_man_double_elimination_bracket' %>
<% elsif @weight.wrestlers.size >= 4 and @weight.wrestlers.size <= 8 %>
<%= render 'eight_man_double_elimination_bracket' %>
<% end %>
<h4>Championship Bracket</h4>
<div class="bracket">
<% if @weight.highest_bracket_round %>
<% (1..@weight.highest_bracket_round).each do |round| %>
<% @round_matches = @matches.select{|m|m.bracket_position == "Bracket" and m.round == round} %>
<%= render 'bracket_round' %>
<% end %>
<% end %>
<% @round_matches = @matches.select{|m|m.bracket_position == "Quarter"} %>
<%= render 'bracket_round' %>
<% @round_matches = @matches.select{|m|m.bracket_position == "Semis"} %>
<%= render 'bracket_round' %>
<% @final_match = @matches.select{|m|m.bracket_position == "1/2"} %>
<% @winner_place = "1st" %>
<%= render 'bracket_final' %>
</div>
<h4>Consolation Bracket</h4>
<div class="bracket">
<% if @weight.highest_conso_round %>
<% (1..@weight.highest_conso_round).each do |round| %>
<% @round_matches = @matches.select{|m|m.bracket_position == "Conso" and m.round == round} %>
<%= render 'bracket_round' %>
<% end %>
<% end %>
<% @round_matches = @matches.select{|m|m.bracket_position == "Conso Quarter"} %>
<%= render 'bracket_round' %>
<% @round_matches = @matches.select{|m|m.bracket_position == "Conso Semis"} %>
<%= render 'bracket_round' %>
<% @final_match = @matches.select{|m|m.bracket_position == "3/4"} %>
<% @winner_place = "3rd" %>
<%= render 'bracket_final' %>
</div>
<h4>5/6 place match</h4>
<div class="bracket">
<!--Round 1-->
<% @final_match = @matches.select{|m|m.bracket_position == "5/6"} %>
<% @winner_place = "5th" %>
<%= render 'bracket_final' %>
</div>
<% if @tournament.number_of_placers >= 8 %>
<h4>7/8 place match</h4>
<div class="bracket">
<!--Round 1-->
<% @final_match = @matches.select{|m|m.bracket_position == "7/8"} %>
<% @winner_place = "7th" %>
<%= render 'bracket_final' %>
</div>
<% end %>

View File

@@ -1,33 +0,0 @@
<h4>Championship Bracket</h4>
<div class="bracket">
<!--Round 1-->
<% @round_matches = @matches.select{|m|m.bracket_position == "Quarter"} %>
<%= render 'bracket_round' %>
<!--Round 2-->
<% @round_matches = @matches.select{|m|m.bracket_position == "Semis"} %>
<%= render 'bracket_round' %>
<!--Round 3-->
<% @final_match = @matches.select{|m|m.bracket_position == "1/2"} %>
<% @winner_place = "1st" %>
<%= render 'bracket_final' %>
</div>
<h4>Consolation Bracket</h4>
<div class="bracket">
<!--Round 1-->
<% @round_matches = @matches.select{|m|m.bracket_position == "Conso Quarter"} %>
<%= render 'bracket_round' %>
<!--Round 2-->
<% @round_matches = @matches.select{|m|m.bracket_position == "Conso Semis"} %>
<%= render 'bracket_round' %>
<!--Round 3-->
<% @final_match = @matches.select{|m|m.bracket_position == "3/4"} %>
<% @winner_place = "3rd" %>
<%= render 'bracket_final' %>
</div>
<h4>5/6 place match</h4>
<div class="bracket">
<!--Round 1-->
<% @final_match = @matches.select{|m|m.bracket_position == "5/6"} %>
<% @winner_place = "5th" %>
<%= render 'bracket_final' %>
</div>

View File

@@ -1,51 +0,0 @@
<h4>Championship Bracket</h4>
<div class="bracket">
<!--Round 1-->
<% @round_matches = @matches.select{|m|m.bracket_position == "Bracket" and m.round == 1} %>
<%= render 'bracket_round' %>
<!--Round 2-->
<% @round_matches = @matches.select{|m|m.bracket_position == "Quarter"} %>
<%= render 'bracket_round' %>
<!--Round 3-->
<% @round_matches = @matches.select{|m|m.bracket_position == "Semis"} %>
<%= render 'bracket_round' %>
<!--Round 4-->
<% @final_match = @matches.select{|m|m.bracket_position == "1/2"} %>
<% @winner_place = "1st" %>
<%= render 'bracket_final' %>
</div>
<h4>Consolation Bracket</h4>
<div class="bracket">
<!--Round 1-->
<% @round_matches = @matches.select{|m|m.bracket_position == "Conso" and m.round == 2} %>
<%= render 'bracket_round' %>
<!--Round 2-->
<% @round_matches = @matches.select{|m|m.bracket_position == "Conso" and m.round == 3} %>
<%= render 'bracket_round' %>
<!--Round 3-->
<% @round_matches = @matches.select{|m|m.bracket_position == "Conso Quarter"} %>
<%= render 'bracket_round' %>
<!--Round 4-->
<% @round_matches = @matches.select{|m|m.bracket_position == "Conso Semis"} %>
<%= render 'bracket_round' %>
<!--Round 5-->
<% @final_match = @matches.select{|m|m.bracket_position == "3/4"} %>
<% @winner_place = "3rd" %>
<%= render 'bracket_final' %>
</div>
<h4>5/6 place match</h4>
<div class="bracket">
<!--Round 1-->
<% @final_match = @matches.select{|m|m.bracket_position == "5/6"} %>
<% @winner_place = "5th" %>
<%= render 'bracket_final' %>
</div>
<% if @tournament.number_of_placers >= 8 %>
<h4>7/8 place match</h4>
<div class="bracket">
<!--Round 1-->
<% @final_match = @matches.select{|m|m.bracket_position == "7/8"} %>
<% @winner_place = "7th" %>
<%= render 'bracket_final' %>
</div>
<% end %>

View File

@@ -32,13 +32,27 @@
# Pool to bracket
tournament = Tournament.create(id: 200, name: 'Pool to bracket', address: 'some place', director: 'some guy', director_email: 'their@email.com', tournament_type: 'Pool to bracket', user_id: 1, date: Date.today, is_public: true)
create_schools(tournament, 16)
create_schools(tournament, 24)
weight_classes=Weight::HS_WEIGHT_CLASSES.split(",")
tournament.create_pre_defined_weights(weight_classes)
wrestler_name_number = 1
tournament.weights.each do |weight|
create_wrestlers_for_weight(weight, tournament, 16, wrestler_name_number)
wrestler_name_number += 16
tournament.weights.each_with_index do |weight, index|
if index == 0
number_of_wrestlers = 6
elsif index == 1
number_of_wrestlers = 8
elsif index == 2
number_of_wrestlers = 10
elsif index == 3
number_of_wrestlers = 12
elsif index == 4
number_of_wrestlers = 24
else
number_of_wrestlers = 16
end
create_wrestlers_for_weight(weight, tournament, number_of_wrestlers, wrestler_name_number)
wrestler_name_number += number_of_wrestlers
end
# Modified 16 Man Double Elimination 1-6
@@ -69,9 +83,17 @@
weight_classes=Weight::HS_WEIGHT_CLASSES.split(",")
tournament.create_pre_defined_weights(weight_classes)
wrestler_name_number = 1
tournament.weights.each do |weight|
create_wrestlers_for_weight(weight, tournament, 16, wrestler_name_number)
wrestler_name_number += 16
tournament.weights.each_with_index do |weight, index|
if index == 0
number_of_wrestlers = 4
elsif index == 1
number_of_wrestlers = 8
else
number_of_wrestlers = 16
end
create_wrestlers_for_weight(weight, tournament, number_of_wrestlers, wrestler_name_number)
wrestler_name_number += number_of_wrestlers
end
# Regular Double Elimination 1-8
@@ -80,9 +102,17 @@
weight_classes=Weight::HS_WEIGHT_CLASSES.split(",")
tournament.create_pre_defined_weights(weight_classes)
wrestler_name_number = 1
tournament.weights.each do |weight|
create_wrestlers_for_weight(weight, tournament, 16, wrestler_name_number)
wrestler_name_number += 16
tournament.weights.each_with_index do |weight, index|
if index == 0
number_of_wrestlers = 4
elsif index == 1
number_of_wrestlers = 8
else
number_of_wrestlers = 16
end
create_wrestlers_for_weight(weight, tournament, number_of_wrestlers, wrestler_name_number)
wrestler_name_number += number_of_wrestlers
end
#end