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

4 Commits

23 changed files with 630 additions and 164 deletions

View File

@@ -165,7 +165,7 @@ class TournamentsController < ApplicationController
end
def create_custom_weights
@custom = params[:customValue].to_s
@custom = params[:customValue].split(",")
@tournament.create_pre_defined_weights(@custom)
redirect_to "/tournaments/#{@tournament.id}"
end

View File

@@ -14,10 +14,15 @@ class School < ActiveRecord::Base
def abbreviation
name_array = self.name.split(' ')
if name_array.size > 1
return "#{name_array[0].chars.to_a.first}#{name_array[1].chars.to_a[0..1].join('').upcase}"
if name_array.size > 2
# If three words, use first letter of first word, first letter of second, and first two of third
return "#{name_array[0].chars.to_a.first}#{name_array[1].chars.to_a.first}#{name_array[2].chars.to_a[0..1].join('').upcase}"
elsif name_array.size > 1
# If two words use first letter of first word and first three of the second
return "#{name_array[0].chars.to_a.first}#{name_array[1].chars.to_a[0..2].join('').upcase}"
else
return "#{name_array[0].chars.to_a[0..2].join('').upcase}"
# If one word use first four letters
return "#{name_array[0].chars.to_a[0..3].join('').upcase}"
end
end

View File

@@ -29,17 +29,21 @@ class Tournament < ActiveRecord::Base
end
def tournament_types
["Pool to bracket","Modified 16 Man Double Elimination","Double Elimination 1-6"]
["Pool to bracket","Modified 16 Man Double Elimination 1-6","Modified 16 Man Double Elimination 1-8","Regular Double Elimination 1-6"]
end
def create_pre_defined_weights(value)
def number_of_placers
if self.tournament_type.include? "1-8"
return 8
elsif self.tournament_type.include? "1-6"
return 6
end
end
def create_pre_defined_weights(weight_classes)
weights.destroy_all
if value == 'hs'
Weight::HS_WEIGHT_CLASSES.each do |w|
weights.create(max: w)
end
else
raise "Unspecified behavior"
weight_classes.each do |w|
weights.create(max: w)
end
end
@@ -116,7 +120,7 @@ class Tournament < ActiveRecord::Base
def modified_sixteen_man_number_of_wrestlers
error_string = ""
if self.tournament_type == "Modified 16 Man Double Elimination"
if self.tournament_type.include? "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|

View File

@@ -7,7 +7,11 @@ class Weight < ActiveRecord::Base
validates :max, presence: true
HS_WEIGHT_CLASSES = [106,113,120,126,132,138,145,152,160,170,182,195,220,285]
# passed via layouts/_tournament-navbar.html.erb
# tournaments controller does a .split(',') on this string and creates an array via commas
# tournament model runs the code via method create_pre_defined_weights
HS_WEIGHT_CLASSES = "106,113,120,126,132,138,145,152,160,170,182,195,220,285"
HS_GIRLS_WEIGHT_CLASSES = "101,106,111,116,121,126,131,137,143,150,160,170,189,235"
before_destroy do
self.tournament.destroy_all_matches

View File

@@ -15,8 +15,8 @@ class AdvanceWrestler
def advance_raw
pool_to_bracket_advancement if @tournament.tournament_type == "Pool to bracket"
DoubleEliminationAdvance.new(@wrestler, @last_match).bracket_advancement if @tournament.tournament_type == "Modified 16 Man Double Elimination" or
@tournament.tournament_type == "Double Elimination 1-6"
DoubleEliminationAdvance.new(@wrestler, @last_match).bracket_advancement if @tournament.tournament_type.include? "Modified 16 Man Double Elimination" or
@tournament.tournament_type.include? "Regular Double Elimination"
end
def pool_to_bracket_advancement

View File

@@ -33,12 +33,12 @@ 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"
DoubleEliminationMatchGeneration.new(@tournament).generate_matches if @tournament.tournament_type == "Double Elimination 1-6"
ModifiedSixteenManMatchGeneration.new(@tournament).generate_matches if @tournament.tournament_type.include? "Modified 16 Man Double Elimination"
DoubleEliminationMatchGeneration.new(@tournament).generate_matches if @tournament.tournament_type.include? "Regular 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"
DoubleEliminationGenerateLoserNames.new(@tournament).assign_loser_names if @tournament.tournament_type == "Double Elimination 1-6"
ModifiedSixteenManGenerateLoserNames.new(@tournament).assign_loser_names if @tournament.tournament_type.include? "Modified 16 Man Double Elimination"
DoubleEliminationGenerateLoserNames.new(@tournament).assign_loser_names if @tournament.tournament_type.include? "Regular Double Elimination"
end
def standardStartingActions

View File

@@ -10,6 +10,7 @@ class ModifiedSixteenManGenerateLoserNames
conso_round_2(matches_by_weight)
conso_round_3(matches_by_weight)
third_fourth(matches_by_weight)
seventh_eighth(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)
@@ -55,11 +56,17 @@ class ModifiedSixteenManGenerateLoserNames
match.loser2_name = "Loser of #{matches.select{|m| m.bracket_position == "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 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 == "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

View File

@@ -1,6 +1,7 @@
class ModifiedSixteenManMatchGeneration
def initialize( tournament )
@tournament = tournament
@number_of_placers = @tournament.number_of_placers
end
def generate_matches
@@ -57,6 +58,9 @@ class ModifiedSixteenManMatchGeneration
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)
if @number_of_placers >= 8
create_matchup(nil,nil,"7/8",1,5,weight)
end
end
def wrestler_with_seed(seed,weight)

View File

@@ -1,6 +1,7 @@
class SixteenManDoubleEliminationMatchGeneration
def initialize( weight )
@weight = weight
@number_of_placers = @weight.tournament.number_of_placers
end
def generate_matches_for_weight

View File

@@ -26,8 +26,8 @@ class CalculateWrestlerTeamScore
def placement_points
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 DoubleEliminationPlacementPoints.new(@wrestler).calc_points if @tournament.tournament_type == "Double Elimination 1-6"
return ModifiedSixteenManPlacementPoints.new(@wrestler).calc_points if @tournament.tournament_type.include? "Modified 16 Man Double Elimination"
return DoubleEliminationPlacementPoints.new(@wrestler).calc_points if @tournament.tournament_type.include? "Regular Double Elimination"
return 0
end

View File

@@ -1,9 +1,7 @@
class DoubleEliminationPlacementPoints
def initialize(wrestler)
@wrestler = wrestler
if wrestler.tournament.tournament_type == "Double Elimination 1-6"
@number_of_placers = 6
end
@number_of_placers = @wrestler.tournament.number_of_placers
end
def calc_points

View File

@@ -1,7 +1,8 @@
class ModifiedSixteenManPlacementPoints
def initialize(wrestler)
@wrestler = wrestler
@number_of_placers = 6
@wrestler = wrestler
@number_of_placers = @wrestler.tournament.number_of_placers
end
def calc_points
@@ -17,6 +18,10 @@ class ModifiedSixteenManPlacementPoints
return PlacementPoints.new(@number_of_placers).fifthPlace
elsif bracket_position_size("5/6") > 0
return PlacementPoints.new(@number_of_placers).sixthPlace
elsif won_bracket_position_size("7/8") > 0
return PlacementPoints.new(@number_of_placers).seventhPlace
elsif bracket_position_size("Conso Semis") > 0 and @number_of_placers >= 8
return PlacementPoints.new(@number_of_placers).eighthPlace
else
return 0
end

View File

@@ -42,7 +42,8 @@
<% end %>
<% end %>
<li><strong>Time Savers</strong></li>
<li><%= link_to "Create High School Weights (106-285)" , "/tournaments/#{@tournament.id}/create_custom_weights?customValue=hs",data: { confirm: 'Are you sure? This will delete all current weights.' } %></li>
<li><%= link_to "Create Boys High School Weights (106-285)" , "/tournaments/#{@tournament.id}/create_custom_weights?customValue=#{Weight::HS_WEIGHT_CLASSES}",data: { confirm: 'Are you sure? This will delete all current weights.' } %></li>
<li><%= link_to "Create Girls High School Weights (101-235)" , "/tournaments/#{@tournament.id}/create_custom_weights?customValue=#{Weight::HS_GIRLS_WEIGHT_CLASSES}",data: { confirm: 'Are you sure? This will delete all current weights.' } %></li>
<li><strong>Tournament Actions</strong></li>
<li><%= link_to "Calculate Team Scores" , "/tournaments/#{@tournament.id}/calculate_team_scores", method: :post %></li>
<li><%= link_to "Generate Brackets" , "/tournaments/#{@tournament.id}/generate_matches", data: { confirm: 'Are you sure? This will delete all current matches.' } %></li>

View File

@@ -106,7 +106,7 @@ table.smallText tr td { font-size: 10px; }
<%= render 'fourPoolSemiBracket' %>
<% end %>
</td>
<% elsif @tournament.tournament_type == "Modified 16 Man Double Elimination" %>
<% elsif @tournament.tournament_type.include? "Modified 16 Man Double Elimination" %>
<td valign="top" style="padding: 10px;">
<%= render 'modified_sixteen_man_double_elimination_bracket' %>
</td>

View File

@@ -1,131 +1,48 @@
<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>
<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>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>
<div class="bracket">
<!--Round 1-->
<% @final_match = @matches.select{|m|m.bracket_position == "3/4"} %>
<% @winner_place = "3rd" %>
<%= render 'bracket_final' %>
</div>
<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>
<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 Quarter"} %>
<%= render 'bracket_round' %>
<!--Round 3-->
<% @round_matches = @matches.select{|m|m.bracket_position == "Conso Semis"} %>
<%= render 'bracket_round' %>
<!--Round 4-->
<% @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

@@ -3,6 +3,6 @@
<% end %>
<% if @tournament.tournament_type == "Pool to bracket" %>
<%= render 'pool_bracket_director_actions' %>
<% elsif @tournament.tournament_type == "Modified 16 Man Double Elimination" or @tournament.tournament_type == "Double Elimination 1-6" %>
<% elsif @tournament.tournament_type.include? "Modified 16 Man Double Elimination" or @tournament.tournament_type.include? "Regular Double Elimination" %>
<%= render 'bracket_director_actions' %>
<% end %>

View File

@@ -1,6 +1,9 @@
Wrestling::Application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# allow all hostnames
config.hosts.clear
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
@@ -32,9 +35,5 @@ Wrestling::Application.configure do
#Bullet.alert = true
#Bullet.console = true
#Bullet.bullet_logger = true
end
end

View File

@@ -0,0 +1,129 @@
require 'test_helper'
class ModifiedDoubleEliminationSixPlacesManMatchGeneration < ActionDispatch::IntegrationTest
def setup
create_double_elim_tournament_single_weight(14, "Modified 16 Man Double Elimination 1-6")
end
test "Match generation works" do
assert @tournament.matches.count == 27
assert @tournament.matches.select{|m| m.bracket_position == "1/2"}.count == 1
assert @tournament.matches.select{|m| m.bracket_position == "3/4"}.count == 1
assert @tournament.matches.select{|m| m.bracket_position == "5/6"}.count == 1
assert @tournament.matches.select{|m| m.bracket_position == "Bracket" and m.round == 1}.count == 8
assert @tournament.matches.select{|m| m.bracket_position == "Conso" and m.round == 2}.count == 4
assert @tournament.matches.select{|m| m.bracket_position == "Quarter"}.count == 4
assert @tournament.matches.select{|m| m.bracket_position == "Semis"}.count == 2
assert @tournament.matches.select{|m| m.bracket_position == "Conso Quarter"}.count == 4
assert @tournament.matches.select{|m| m.bracket_position == "Conso Semis"}.count == 2
end
test "Seeded wrestlers have correct first line" do
@tournament.matches.reload
match1 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 1}.first
match2 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 2}.first
match3 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 3}.first
match4 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 4}.first
match5 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 5}.first
match6 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 6}.first
match7 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 7}.first
match8 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 8}.first
assert match1.wrestler1.bracket_line == 1
assert match1.loser2_name == "BYE"
assert match2.wrestler1.bracket_line == 8
assert match2.wrestler2.bracket_line == 9
assert match3.wrestler1.bracket_line == 5
assert match3.wrestler2.bracket_line == 12
assert match4.wrestler1.bracket_line == 4
assert match4.wrestler2.bracket_line == 14
assert match5.wrestler1.bracket_line == 3
assert match5.wrestler2.bracket_line == 13
assert match6.wrestler1.bracket_line == 6
assert match6.wrestler2.bracket_line == 11
assert match7.wrestler1.bracket_line == 7
assert match7.wrestler2.bracket_line == 10
assert match8.wrestler1.bracket_line == 2
assert match8.loser2_name == "BYE"
end
test "Byes are advanced correctly" do
@tournament.matches.reload
match1 = @tournament.matches.select{|match| match.round == 2 and match.bracket_position == "Quarter" and match.bracket_position_number == 1}.first
match2 = @tournament.matches.select{|match| match.round == 2 and match.bracket_position == "Quarter" and match.bracket_position_number == 4}.first
assert match1.wrestler1.name == "Test1"
assert match2.wrestler2.name == "Test2"
end
test "Loser names set up correctly" do
@tournament.matches.reload
match1 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 1}.first
match2 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 2}.first
match3 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 3}.first
match4 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 4}.first
match5 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 5}.first
match6 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 6}.first
match7 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 7}.first
match8 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 8}.first
assert @tournament.matches.select{|m| m.bracket_position == "Conso" and m.round == 2 && m.bracket_position_number == 1}.first.loser1_name == "BYE"
assert @tournament.matches.select{|m| m.bracket_position == "Conso" and m.round == 2 && m.bracket_position_number == 1}.first.loser2_name == "Loser of #{match2.bout_number}"
assert @tournament.matches.select{|m| m.bracket_position == "Conso" and m.round == 2 && m.bracket_position_number == 2}.first.loser1_name == "Loser of #{match3.bout_number}"
assert @tournament.matches.select{|m| m.bracket_position == "Conso" and m.round == 2 && m.bracket_position_number == 2}.first.loser2_name == "Loser of #{match4.bout_number}"
assert @tournament.matches.select{|m| m.bracket_position == "Conso" and m.round == 2 && m.bracket_position_number == 3}.first.loser1_name == "Loser of #{match5.bout_number}"
assert @tournament.matches.select{|m| m.bracket_position == "Conso" and m.round == 2 && m.bracket_position_number == 3}.first.loser2_name == "Loser of #{match6.bout_number}"
assert @tournament.matches.select{|m| m.bracket_position == "Conso" and m.round == 2 && m.bracket_position_number == 4}.first.loser1_name == "Loser of #{match7.bout_number}"
assert @tournament.matches.select{|m| m.bracket_position == "Conso" and m.round == 2 && m.bracket_position_number == 4}.first.loser2_name == "BYE"
quarter1 = @tournament.matches.select{|match| match.bracket_position == "Quarter" and match.bracket_position_number == 1}.first
quarter2 = @tournament.matches.select{|match| match.bracket_position == "Quarter" and match.bracket_position_number == 2}.first
quarter3 = @tournament.matches.select{|match| match.bracket_position == "Quarter" and match.bracket_position_number == 3}.first
quarter4 = @tournament.matches.select{|match| match.bracket_position == "Quarter" and match.bracket_position_number == 4}.first
consoround2match1 = @tournament.matches.select{|match| match.bracket_position == "Conso Quarter" and match.round == 3 && match.bracket_position_number == 1}.first
consoround2match2 = @tournament.matches.select{|match| match.bracket_position == "Conso Quarter" and match.round == 3 && match.bracket_position_number == 2}.first
consoround2match3 = @tournament.matches.select{|match| match.bracket_position == "Conso Quarter" and match.round == 3 && match.bracket_position_number == 3}.first
consoround2match4 = @tournament.matches.select{|match| match.bracket_position == "Conso Quarter" and match.round == 3 && match.bracket_position_number == 4}.first
assert consoround2match1.loser1_name == "Loser of #{quarter4.bout_number}"
assert consoround2match2.loser1_name == "Loser of #{quarter3.bout_number}"
assert consoround2match3.loser1_name == "Loser of #{quarter2.bout_number}"
assert consoround2match4.loser1_name == "Loser of #{quarter1.bout_number}"
semis1 = @tournament.matches.select{|match| match.bracket_position == "Semis" and match.bracket_position_number == 1}.first
semis2 = @tournament.matches.select{|match| match.bracket_position == "Semis" and match.bracket_position_number == 2}.first
assert @tournament.matches.select{|m| m.bracket_position == "3/4" && m.bracket_position_number == 1}.first.loser1_name == "Loser of #{semis1.bout_number}"
assert @tournament.matches.select{|m| m.bracket_position == "3/4" && m.bracket_position_number == 1}.first.loser2_name == "Loser of #{semis2.bout_number}"
end
test "Placement points are given when moving through bracket" do
match = @tournament.matches.select{|m| m.bracket_position == "Semis"}.first
wrestler = get_wrestler_by_name("Test1")
match.w1 = wrestler.id
match.save
assert wrestler.reload.placement_points == 7
end
test "Run through all matches works" do
@tournament.matches.sort_by{ |match| match.bout_number }.each do |match|
match.reload
if match.finished != 1 and match.w1 and match.w2
match.winner_id = match.w1
match.win_type = "Decision"
match.score = "0-0"
match.finished = 1
match.save
end
end
assert @tournament.matches.reload.select{|m| m.finished == 0}.count == 0
end
end

View File

@@ -0,0 +1,104 @@
require 'test_helper'
class ModifiedDoubleEliminationSixPlacesRunThrough < ActionDispatch::IntegrationTest
def setup
end
def winner_by_name(winner_name,match)
wrestler = @tournament.weights.first.wrestlers.select{|w| w.name == winner_name}.first
match.winner_id = wrestler.id
match.finished = 1
match.win_type = "Decision"
match.score = "0-0"
match.save
end
test "16 man modified double elimination placing 1-6" do
@tournament = create_double_elim_tournament_single_weight(14, "Modified 16 Man Double Elimination 1-6")
matches = @tournament.matches.reload
round1 = matches.select{|m| m.round == 1}
winner_by_name("Test9", round1.select{|m| m.bracket_position_number == 2}.first)
winner_by_name("Test5", round1.select{|m| m.bracket_position_number == 3}.first)
winner_by_name("Test4", round1.select{|m| m.bracket_position_number == 4}.first)
winner_by_name("Test13", round1.select{|m| m.bracket_position_number == 5}.first)
winner_by_name("Test6", round1.select{|m| m.bracket_position_number == 6}.first)
winner_by_name("Test10", round1.select{|m| m.bracket_position_number == 7}.first)
quarter = matches.select{|m| m.bracket_position == "Quarter"}.sort_by{|m| m.bracket_position_number}
assert quarter.first.reload.wrestler1.name == "Test1"
assert quarter.first.reload.wrestler2.name == "Test9"
assert quarter.second.reload.wrestler1.name == "Test5"
assert quarter.second.reload.wrestler2.name == "Test4"
assert quarter.third.reload.wrestler1.name == "Test13"
assert quarter.third.reload.wrestler2.name == "Test6"
assert quarter.fourth.reload.wrestler1.name == "Test10"
assert quarter.fourth.reload.wrestler2.name == "Test2"
conso_round2 = matches.select{|m| m.bracket_position == "Conso" and m.round == 2}.sort_by{|m| m.bracket_position_number}
assert conso_round2.first.reload.wrestler2.name == "Test8"
assert conso_round2.second.reload.wrestler1.name == "Test12"
assert conso_round2.second.reload.wrestler2.name == "Test14"
assert conso_round2.third.reload.wrestler1.name == "Test3"
assert conso_round2.third.reload.wrestler2.name == "Test11"
assert conso_round2.fourth.reload.wrestler1.name == "Test7"
winner_by_name("Test1", quarter.first)
winner_by_name("Test5", quarter.second)
winner_by_name("Test13", quarter.third)
winner_by_name("Test10", quarter.fourth)
winner_by_name("Test12", conso_round2.second)
winner_by_name("Test3", conso_round2.third)
semis = matches.select{|m| m.bracket_position == "Semis"}.sort_by{|m| m.bracket_position_number}
assert semis.first.reload.wrestler1.name == "Test1"
assert semis.first.reload.wrestler2.name == "Test5"
assert semis.second.reload.wrestler1.name == "Test13"
assert semis.second.reload.wrestler2.name == "Test10"
conso_quarter = matches.select{|m| m.bracket_position == "Conso Quarter"}.sort_by{|m| m.bracket_position_number}
assert conso_quarter.first.reload.wrestler1.name == "Test2"
assert conso_quarter.first.reload.wrestler2.name == "Test8"
assert conso_quarter.second.reload.wrestler1.name == "Test6"
assert conso_quarter.second.reload.wrestler2.name == "Test12"
assert conso_quarter.third.reload.wrestler1.name == "Test4"
assert conso_quarter.third.reload.wrestler2.name == "Test3"
assert conso_quarter.fourth.reload.wrestler1.name == "Test9"
assert conso_quarter.fourth.reload.wrestler2.name == "Test7"
winner_by_name("Test5",semis.first)
winner_by_name("Test10",semis.second)
winner_by_name("Test2", conso_quarter.first)
winner_by_name("Test12", conso_quarter.second)
winner_by_name("Test4", conso_quarter.third)
winner_by_name("Test7", conso_quarter.fourth)
conso_semis = matches.select{|m| m.bracket_position == "Conso Semis"}.sort_by{|m| m.bracket_position_number}
assert conso_semis.first.reload.wrestler1.name == "Test2"
assert conso_semis.first.reload.wrestler2.name == "Test12"
assert conso_semis.second.reload.wrestler1.name == "Test4"
assert conso_semis.second.reload.wrestler2.name == "Test7"
winner_by_name("Test2",conso_semis.first)
winner_by_name("Test4",conso_semis.second)
first_finals = matches.select{|m| m.bracket_position == "1/2"}.first
third_finals = matches.select{|m| m.bracket_position == "3/4"}.first
fifth_finals = matches.select{|m| m.bracket_position == "5/6"}.first
assert first_finals.reload.wrestler1.name == "Test5"
assert first_finals.reload.wrestler2.name == "Test10"
assert third_finals.reload.wrestler1.name == "Test1"
assert third_finals.reload.wrestler2.name == "Test13"
assert fifth_finals.reload.wrestler1.name == "Test2"
assert fifth_finals.reload.wrestler2.name == "Test4"
# DEBUG
# matches.sort_by{|m| m.bout_number}.each do |match|
# match.reload
# puts "Round #{match.round} #{match.w1_bracket_name} vs #{match.w2_bracket_name}"
# end
end
end

View File

@@ -0,0 +1,142 @@
require 'test_helper'
class ModifiedDoubleEliminationEightPlacesManMatchGeneration < ActionDispatch::IntegrationTest
def setup
create_double_elim_tournament_single_weight(14, "Modified 16 Man Double Elimination 1-8")
end
test "Match generation works" do
assert @tournament.matches.count == 28
assert @tournament.matches.select{|m| m.bracket_position == "1/2"}.count == 1
assert @tournament.matches.select{|m| m.bracket_position == "3/4"}.count == 1
assert @tournament.matches.select{|m| m.bracket_position == "5/6"}.count == 1
assert @tournament.matches.select{|m| m.bracket_position == "7/8"}.count == 1
assert @tournament.matches.select{|m| m.bracket_position == "Bracket" and m.round == 1}.count == 8
assert @tournament.matches.select{|m| m.bracket_position == "Quarter"}.count == 4
assert @tournament.matches.select{|m| m.bracket_position == "Semis"}.count == 2
assert @tournament.matches.select{|m| m.bracket_position == "Conso" and m.round == 2}.count == 4
assert @tournament.matches.select{|m| m.bracket_position == "Conso Quarter"}.count == 4
assert @tournament.matches.select{|m| m.bracket_position == "Conso Semis"}.count == 2
end
test "Seeded wrestlers have correct first line" do
@tournament.matches.reload
match1 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 1}.first
match2 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 2}.first
match3 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 3}.first
match4 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 4}.first
match5 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 5}.first
match6 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 6}.first
match7 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 7}.first
match8 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 8}.first
assert match1.wrestler1.bracket_line == 1
assert match1.loser2_name == "BYE"
assert match2.wrestler1.bracket_line == 8
assert match2.wrestler2.bracket_line == 9
assert match3.wrestler1.bracket_line == 5
assert match3.wrestler2.bracket_line == 12
assert match4.wrestler1.bracket_line == 4
assert match4.wrestler2.bracket_line == 14
assert match5.wrestler1.bracket_line == 3
assert match5.wrestler2.bracket_line == 13
assert match6.wrestler1.bracket_line == 6
assert match6.wrestler2.bracket_line == 11
assert match7.wrestler1.bracket_line == 7
assert match7.wrestler2.bracket_line == 10
assert match8.wrestler1.bracket_line == 2
assert match8.loser2_name == "BYE"
end
test "Byes are advanced correctly" do
@tournament.matches.reload
match1 = @tournament.matches.select{|match| match.round == 2 and match.bracket_position == "Quarter" and match.bracket_position_number == 1}.first
match2 = @tournament.matches.select{|match| match.round == 2 and match.bracket_position == "Quarter" and match.bracket_position_number == 4}.first
assert match1.wrestler1.name == "Test1"
assert match2.wrestler2.name == "Test2"
end
test "Loser names set up correctly" do
@tournament.matches.reload
match1 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 1}.first
match2 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 2}.first
match3 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 3}.first
match4 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 4}.first
match5 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 5}.first
match6 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 6}.first
match7 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 7}.first
match8 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 8}.first
assert @tournament.matches.select{|m| m.bracket_position == "Conso" and m.round == 2 && m.bracket_position_number == 1}.first.loser1_name == "BYE"
assert @tournament.matches.select{|m| m.bracket_position == "Conso" and m.round == 2 && m.bracket_position_number == 1}.first.loser2_name == "Loser of #{match2.bout_number}"
assert @tournament.matches.select{|m| m.bracket_position == "Conso" and m.round == 2 && m.bracket_position_number == 2}.first.loser1_name == "Loser of #{match3.bout_number}"
assert @tournament.matches.select{|m| m.bracket_position == "Conso" and m.round == 2 && m.bracket_position_number == 2}.first.loser2_name == "Loser of #{match4.bout_number}"
assert @tournament.matches.select{|m| m.bracket_position == "Conso" and m.round == 2 && m.bracket_position_number == 3}.first.loser1_name == "Loser of #{match5.bout_number}"
assert @tournament.matches.select{|m| m.bracket_position == "Conso" and m.round == 2 && m.bracket_position_number == 3}.first.loser2_name == "Loser of #{match6.bout_number}"
assert @tournament.matches.select{|m| m.bracket_position == "Conso" and m.round == 2 && m.bracket_position_number == 4}.first.loser1_name == "Loser of #{match7.bout_number}"
assert @tournament.matches.select{|m| m.bracket_position == "Conso" and m.round == 2 && m.bracket_position_number == 4}.first.loser2_name == "BYE"
quarter1 = @tournament.matches.select{|match| match.bracket_position == "Quarter" and match.bracket_position_number == 1}.first
quarter2 = @tournament.matches.select{|match| match.bracket_position == "Quarter" and match.bracket_position_number == 2}.first
quarter3 = @tournament.matches.select{|match| match.bracket_position == "Quarter" and match.bracket_position_number == 3}.first
quarter4 = @tournament.matches.select{|match| match.bracket_position == "Quarter" and match.bracket_position_number == 4}.first
consoround2match1 = @tournament.matches.select{|match| match.bracket_position == "Conso Quarter" and match.round == 3 && match.bracket_position_number == 1}.first
consoround2match2 = @tournament.matches.select{|match| match.bracket_position == "Conso Quarter" and match.round == 3 && match.bracket_position_number == 2}.first
consoround2match3 = @tournament.matches.select{|match| match.bracket_position == "Conso Quarter" and match.round == 3 && match.bracket_position_number == 3}.first
consoround2match4 = @tournament.matches.select{|match| match.bracket_position == "Conso Quarter" and match.round == 3 && match.bracket_position_number == 4}.first
assert consoround2match1.loser1_name == "Loser of #{quarter4.bout_number}"
assert consoround2match2.loser1_name == "Loser of #{quarter3.bout_number}"
assert consoround2match3.loser1_name == "Loser of #{quarter2.bout_number}"
assert consoround2match4.loser1_name == "Loser of #{quarter1.bout_number}"
semis1 = @tournament.matches.select{|match| match.bracket_position == "Semis" and match.bracket_position_number == 1}.first
semis2 = @tournament.matches.select{|match| match.bracket_position == "Semis" and match.bracket_position_number == 2}.first
assert @tournament.matches.select{|m| m.bracket_position == "3/4" && m.bracket_position_number == 1}.first.loser1_name == "Loser of #{semis1.bout_number}"
assert @tournament.matches.select{|m| m.bracket_position == "3/4" && m.bracket_position_number == 1}.first.loser2_name == "Loser of #{semis2.bout_number}"
consosemis1 = @tournament.matches.select{|match| match.bracket_position == "Conso Semis" and match.bracket_position_number == 1}.first
consosemis2 = @tournament.matches.select{|match| match.bracket_position == "Conso Semis" and match.bracket_position_number == 2}.first
assert @tournament.matches.select{|m| m.bracket_position == "7/8" && m.bracket_position_number == 1}.first.loser1_name == "Loser of #{consosemis1.bout_number}"
assert @tournament.matches.select{|m| m.bracket_position == "7/8" && m.bracket_position_number == 1}.first.loser2_name == "Loser of #{consosemis2.bout_number}"
end
test "Placement points are given when moving through bracket" do
match = @tournament.matches.select{|m| m.bracket_position == "Semis"}.first
wrestler = get_wrestler_by_name("Test1")
match.w1 = wrestler.id
match.save
match2 = @tournament.matches.select{|m| m.bracket_position == "Conso Semis"}.first
wrestler2 = get_wrestler_by_name("Test2")
match2.w1 = wrestler2.id
match2.save
assert wrestler.reload.placement_points == 7
assert wrestler2.reload.placement_points == 1
end
test "Run through all matches works" do
@tournament.matches.sort_by{ |match| match.bout_number }.each do |match|
match.reload
if match.finished != 1 and match.w1 and match.w2
match.winner_id = match.w1
match.win_type = "Decision"
match.score = "0-0"
match.finished = 1
match.save
end
end
assert @tournament.matches.reload.select{|m| m.finished == 0}.count == 0
end
end

View File

@@ -0,0 +1,108 @@
require 'test_helper'
class ModifiedDoubleEliminationEightPlacesRunThrough < ActionDispatch::IntegrationTest
def setup
end
def winner_by_name(winner_name,match)
wrestler = @tournament.weights.first.wrestlers.select{|w| w.name == winner_name}.first
match.winner_id = wrestler.id
match.finished = 1
match.win_type = "Decision"
match.score = "0-0"
match.save
end
test "16 man modified double elimination placing 1-8" do
@tournament = create_double_elim_tournament_single_weight(14, "Modified 16 Man Double Elimination 1-8")
matches = @tournament.matches.reload
round1 = matches.select{|m| m.round == 1}
winner_by_name("Test9", round1.select{|m| m.bracket_position_number == 2}.first)
winner_by_name("Test5", round1.select{|m| m.bracket_position_number == 3}.first)
winner_by_name("Test4", round1.select{|m| m.bracket_position_number == 4}.first)
winner_by_name("Test13", round1.select{|m| m.bracket_position_number == 5}.first)
winner_by_name("Test6", round1.select{|m| m.bracket_position_number == 6}.first)
winner_by_name("Test10", round1.select{|m| m.bracket_position_number == 7}.first)
quarter = matches.select{|m| m.bracket_position == "Quarter"}.sort_by{|m| m.bracket_position_number}
assert quarter.first.reload.wrestler1.name == "Test1"
assert quarter.first.reload.wrestler2.name == "Test9"
assert quarter.second.reload.wrestler1.name == "Test5"
assert quarter.second.reload.wrestler2.name == "Test4"
assert quarter.third.reload.wrestler1.name == "Test13"
assert quarter.third.reload.wrestler2.name == "Test6"
assert quarter.fourth.reload.wrestler1.name == "Test10"
assert quarter.fourth.reload.wrestler2.name == "Test2"
conso_round2 = matches.select{|m| m.bracket_position == "Conso" and m.round == 2}.sort_by{|m| m.bracket_position_number}
assert conso_round2.first.reload.wrestler2.name == "Test8"
assert conso_round2.second.reload.wrestler1.name == "Test12"
assert conso_round2.second.reload.wrestler2.name == "Test14"
assert conso_round2.third.reload.wrestler1.name == "Test3"
assert conso_round2.third.reload.wrestler2.name == "Test11"
assert conso_round2.fourth.reload.wrestler1.name == "Test7"
winner_by_name("Test1", quarter.first)
winner_by_name("Test5", quarter.second)
winner_by_name("Test13", quarter.third)
winner_by_name("Test10", quarter.fourth)
winner_by_name("Test12", conso_round2.second)
winner_by_name("Test3", conso_round2.third)
semis = matches.select{|m| m.bracket_position == "Semis"}.sort_by{|m| m.bracket_position_number}
assert semis.first.reload.wrestler1.name == "Test1"
assert semis.first.reload.wrestler2.name == "Test5"
assert semis.second.reload.wrestler1.name == "Test13"
assert semis.second.reload.wrestler2.name == "Test10"
conso_quarter = matches.select{|m| m.bracket_position == "Conso Quarter"}.sort_by{|m| m.bracket_position_number}
assert conso_quarter.first.reload.wrestler1.name == "Test2"
assert conso_quarter.first.reload.wrestler2.name == "Test8"
assert conso_quarter.second.reload.wrestler1.name == "Test6"
assert conso_quarter.second.reload.wrestler2.name == "Test12"
assert conso_quarter.third.reload.wrestler1.name == "Test4"
assert conso_quarter.third.reload.wrestler2.name == "Test3"
assert conso_quarter.fourth.reload.wrestler1.name == "Test9"
assert conso_quarter.fourth.reload.wrestler2.name == "Test7"
winner_by_name("Test5",semis.first)
winner_by_name("Test10",semis.second)
winner_by_name("Test2", conso_quarter.first)
winner_by_name("Test12", conso_quarter.second)
winner_by_name("Test4", conso_quarter.third)
winner_by_name("Test7", conso_quarter.fourth)
conso_semis = matches.select{|m| m.bracket_position == "Conso Semis"}.sort_by{|m| m.bracket_position_number}
assert conso_semis.first.reload.wrestler1.name == "Test2"
assert conso_semis.first.reload.wrestler2.name == "Test12"
assert conso_semis.second.reload.wrestler1.name == "Test4"
assert conso_semis.second.reload.wrestler2.name == "Test7"
winner_by_name("Test2",conso_semis.first)
winner_by_name("Test4",conso_semis.second)
first_finals = matches.select{|m| m.bracket_position == "1/2"}.first
third_finals = matches.select{|m| m.bracket_position == "3/4"}.first
fifth_finals = matches.select{|m| m.bracket_position == "5/6"}.first
seventh_finals = matches.select{|m| m.bracket_position == "7/8"}.first
assert first_finals.reload.wrestler1.name == "Test5"
assert first_finals.reload.wrestler2.name == "Test10"
assert third_finals.reload.wrestler1.name == "Test1"
assert third_finals.reload.wrestler2.name == "Test13"
assert fifth_finals.reload.wrestler1.name == "Test2"
assert fifth_finals.reload.wrestler2.name == "Test4"
assert seventh_finals.reload.wrestler1.name == "Test12"
assert seventh_finals.reload.wrestler2.name == "Test7"
# DEBUG
# matches.sort_by{|m| m.bout_number}.each do |match|
# match.reload
# puts "Round #{match.round} #{match.w1_bracket_name} vs #{match.w2_bracket_name}"
# end
end
end

View File

@@ -11,4 +11,20 @@ class TournamentTest < ActiveSupport::TestCase
assert_not tourney.valid?
assert_equal [:date, :name, :tournament_type, :address, :director, :director_email], tourney.errors.attribute_names
end
test "Tournament create_pre_defined_weights High School Boys Weights" do
tournament = Tournament.find(1)
tournament.create_pre_defined_weights(Weight::HS_WEIGHT_CLASSES.split(","))
Weight::HS_WEIGHT_CLASSES.split(",").each do |weight|
assert tournament.weights.select{|w| w.max == weight.to_i}.count == 1
end
end
test "Tournament create_pre_defined_weights High School Girls Weights" do
tournament = Tournament.find(1)
tournament.create_pre_defined_weights(Weight::HS_GIRLS_WEIGHT_CLASSES.split(","))
Weight::HS_GIRLS_WEIGHT_CLASSES.split(",").each do |weight|
assert tournament.weights.select{|w| w.max == weight.to_i}.count == 1
end
end
end

View File

@@ -41,7 +41,29 @@ class ActiveSupport::TestCase
@tournament.address = "some place"
@tournament.director = "some guy"
@tournament.director_email= "test@test.com"
@tournament.tournament_type = "Double Elimination 1-6"
@tournament.tournament_type = "Regular Double Elimination 1-6"
@tournament.date = "2015-12-30"
@tournament.save
@school = School.new
@school.name = "Test"
@school.tournament_id = @tournament.id
@school.save
@weight = Weight.new
@weight.max = 106
@weight.tournament_id = @tournament.id
@weight.save
create_wrestlers_for_weight_for_double_elim(@weight, @school, number_of_wrestlers, 1)
GenerateTournamentMatches.new(@tournament).generate
return @tournament
end
def create_double_elim_tournament_single_weight(number_of_wrestlers, tournament_type)
@tournament = Tournament.new
@tournament.name = "Test Tournament"
@tournament.address = "some place"
@tournament.director = "some guy"
@tournament.director_email= "test@test.com"
@tournament.tournament_type = tournament_type
@tournament.date = "2015-12-30"
@tournament.save
@school = School.new