1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-04-04 22:03:49 +00:00

Fixed double elim bracket views, fixed double elim match generation and loser name generation for 4 man bracket, fixed seed page submission and added tests, added tests for tournament generation errors and added a new error for assigning a seed higher than the number of wrestlers.

This commit is contained in:
2024-12-08 19:29:56 -05:00
parent f6ef471591
commit f18802a933
10 changed files with 278 additions and 37 deletions

View File

@@ -8,15 +8,21 @@ class WeightsController < ApplicationController
# GET /weights/1.json
def show
if params[:wrestler]
check_access_manage
respond_to do |format|
Wrestler.update(params[:wrestler].keys, params[:wrestler].values)
# Sanitize the wrestler parameters
sanitized_wrestlers = params.require(:wrestler).to_unsafe_h.transform_values do |attributes|
ActionController::Parameters.new(attributes).permit(:original_seed)
end
Wrestler.update(sanitized_wrestlers.keys, sanitized_wrestlers.values)
format.html { redirect_to @weight, notice: 'Seeds were successfully updated.' }
end
end
@wrestlers = @weight.wrestlers
@tournament = @weight.tournament
session[:return_path] = "/weights/#{@weight.id}"
end
end
# GET /weights/new
def new

View File

@@ -129,7 +129,7 @@ class Tournament < ApplicationRecord
end
end
def pool_to_bracket_number_of_wrestlers
def pool_to_bracket_number_of_wrestlers_error
error_string = ""
if self.tournament_type.include? "Pool to bracket"
weights_with_too_many_wrestlers = weights.select{|w| w.wrestlers.size > 24}
@@ -144,7 +144,7 @@ class Tournament < ApplicationRecord
return error_string
end
def modified_sixteen_man_number_of_wrestlers
def modified_sixteen_man_number_of_wrestlers_error
error_string = ""
if self.tournament_type.include? "Modified 16 Man Double Elimination"
weights_with_too_many_wrestlers = weights.select{|w| w.wrestlers.size > 16}
@@ -159,7 +159,7 @@ class Tournament < ApplicationRecord
return error_string
end
def double_elim_number_of_wrestlers
def double_elim_number_of_wrestlers_error
error_string = ""
if self.tournament_type == "Double Elimination 1-6" or self.tournament_type == "Double Elimination 1-8"
weights_with_too_many_wrestlers = weights.select{|w| w.wrestlers.size > 16}
@@ -173,21 +173,35 @@ class Tournament < ApplicationRecord
end
return error_string
end
def wrestlers_with_higher_seed_than_bracket_size_error
error_string = ""
weights.each do |weight|
weight.wrestlers.each do |wrestler|
if wrestler.original_seed != nil && wrestler.original_seed > weight.wrestlers.size
error_string += "Wrestler: #{wrestler.name} has a seed of #{wrestler.original_seed} which is greater than the amount of wrestlers (#{weight.wrestlers.size}) in the weight class #{weight.max}."
end
end
end
return error_string
end
def match_generation_error
error_string = "There is a tournament error."
modified_sixteen_man_error = modified_sixteen_man_number_of_wrestlers
double_elim_error = double_elim_number_of_wrestlers
pool_to_bracket_error = pool_to_bracket_number_of_wrestlers
if pool_to_bracket_error.length > 0
return error_string + pool_to_bracket_error
elsif modified_sixteen_man_error.length > 0
return error_string + modified_sixteen_man_error
elsif double_elim_error.length > 0
return error_string + double_elim_error
else
nil
error_string = ""
if pool_to_bracket_number_of_wrestlers_error.length > 0
error_string += pool_to_bracket_number_of_wrestlers_error
elsif modified_sixteen_man_number_of_wrestlers_error.length > 0
error_string += modified_sixteen_man_number_of_wrestlers_error
elsif double_elim_number_of_wrestlers_error.length > 0
error_string += double_elim_number_of_wrestlers_error
elsif wrestlers_with_higher_seed_than_bracket_size_error.length > 0
error_string += wrestlers_with_higher_seed_than_bracket_size_error
end
if error_string.length > 0
return "There is a tournament error. #{error_string}"
else
return nil
end
end
def reset_and_fill_bout_board

View File

@@ -15,7 +15,12 @@ class DoubleEliminationGenerateLoserNames
# 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
# except for bracket_size of 4
case bracket_size
when 4 then
return [
[@tournament.total_rounds, "3/4", 1, "Semis", false, true]
]
when 8 then
return [
[2, "Conso Quarter", 1, "Quarter", false, true],
@@ -24,8 +29,8 @@ class DoubleEliminationGenerateLoserNames
when 16 then
return [
[2, "Conso", 1, "Bracket", false, true],
[3, "Conso", 2, "Quarter", true],
[5, "Conso Semis", 4, "Semis", false]
[3, "Conso", 2, "Quarter", true, false],
[5, "Conso Semis", 4, "Semis", false, false]
]
else
return nil
@@ -35,7 +40,7 @@ class DoubleEliminationGenerateLoserNames
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
matches_by_weight = weight.matches.reload
loser_name_championship_mappings = define_losername_championship_mappings(bracket_size)
@@ -68,14 +73,14 @@ class DoubleEliminationGenerateLoserNames
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
if number_of_placers >= 6 && weight.wrestlers.size >= 5
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
if number_of_placers >= 8 && weight.wrestlers.size >= 7
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

View File

@@ -19,6 +19,12 @@ class DoubleEliminationMatchGeneration
# consolation_rounds define [round_number, number_of_matches_in_round, bracket_position]
case bracket_size
when 4 then
return BracketMatchups.new(
[[1, 4, "Semis"], [2, 3, "Semis"]],
[[2, 1, "1/2"]],
[[2, 1, "3/4"]]
)
when 8 then
return BracketMatchups.new(
[[1, 8, "Quarter"], [4, 5, "Quarter"], [3, 6, "Quarter"], [2, 7, "Quarter"]],
@@ -75,8 +81,12 @@ class DoubleEliminationMatchGeneration
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
if weight.wrestlers.size >=5
create_matchup(nil, nil, "5/6", 1, round, weight) if @tournament.number_of_placers >= 6 && matches_this_round == 1
end
if weight.wrestlers.size >= 7
create_matchup(nil, nil, "7/8", 1, round, weight) if @tournament.number_of_placers >= 8 && matches_this_round == 1
end
end
end

View File

@@ -1,15 +1,9 @@
<% @final_match.each do |match| %>
<div class="round">
<% @final_match.each do |match| %>
<div class="game">
<div class="game-top "><%= match.w1_bracket_name.html_safe %> <span></span></div>
<div class="bout-number"><p><%= match.bout_number %> <%= match.bracket_score_string %></p><p><%= @winner_place %> Place Winner</p></div>
<div class="game-bottom "><%= match.w2_bracket_name.html_safe %><span></span></div>
</div>
</div>
<!-- <div class="round">
<div class="game">
<div class="bracket-winner"> <%= match.bracket_winner_name %></div>
<div class="bout_number"><%= @winner_place %> Place Winner</div>
</div>
<% end %>
</div> -->
<% end %>

View File

@@ -32,7 +32,6 @@
</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' %>
@@ -40,7 +39,6 @@
<% 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' %>