mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-04-17 13:24:36 +00:00
Random seeding now works
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
module GeneratesTournamentMatches
|
module GeneratesTournamentMatches
|
||||||
|
|
||||||
def generateMatchups
|
def generateMatchups
|
||||||
|
resetSchoolScores
|
||||||
|
setSeedsAndRandomSeedingWrestlersWithoutSeeds
|
||||||
poolToBracket() if tournament_type == "Pool to bracket"
|
poolToBracket() if tournament_type == "Pool to bracket"
|
||||||
matches
|
matches
|
||||||
end
|
end
|
||||||
@@ -9,7 +11,6 @@ module GeneratesTournamentMatches
|
|||||||
end
|
end
|
||||||
|
|
||||||
def poolToBracket
|
def poolToBracket
|
||||||
resetSchoolScores
|
|
||||||
destroyAllMatches
|
destroyAllMatches
|
||||||
buildTournamentWeights
|
buildTournamentWeights
|
||||||
generateMatches
|
generateMatches
|
||||||
@@ -40,4 +41,10 @@ module GeneratesTournamentMatches
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def setSeedsAndRandomSeedingWrestlersWithoutSeeds
|
||||||
|
weights.each do |w|
|
||||||
|
w.setSeeds
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ class Weight < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def onePoolNumbers(wrestlers)
|
def onePoolNumbers(wrestlers)
|
||||||
wrestlers.sort_by{|x|[x.original_seed]}.each do |w|
|
wrestlers.sort_by{|x|[x.seed]}.each do |w|
|
||||||
w.poolNumber = 1
|
w.poolNumber = 1
|
||||||
end
|
end
|
||||||
return wrestlers
|
return wrestlers
|
||||||
@@ -58,14 +58,14 @@ class Weight < ActiveRecord::Base
|
|||||||
|
|
||||||
def twoPoolNumbers(wrestlers)
|
def twoPoolNumbers(wrestlers)
|
||||||
pool = 1
|
pool = 1
|
||||||
wrestlers.sort_by{|x|[x.original_seed]}.reverse.each do |w|
|
wrestlers.sort_by{|x|[x.seed]}.reverse.each do |w|
|
||||||
if w.original_seed == 1
|
if w.seed == 1
|
||||||
w.poolNumber = 1
|
w.poolNumber = 1
|
||||||
elsif w.original_seed == 2
|
elsif w.seed == 2
|
||||||
w.poolNumber = 2
|
w.poolNumber = 2
|
||||||
elsif w.original_seed == 3
|
elsif w.seed == 3
|
||||||
w.poolNumber = 2
|
w.poolNumber = 2
|
||||||
elsif w.original_seed == 4
|
elsif w.seed == 4
|
||||||
w.poolNumber = 1
|
w.poolNumber = 1
|
||||||
else
|
else
|
||||||
w.poolNumber = pool
|
w.poolNumber = pool
|
||||||
@@ -81,14 +81,14 @@ class Weight < ActiveRecord::Base
|
|||||||
|
|
||||||
def fourPoolNumbers(wrestlers)
|
def fourPoolNumbers(wrestlers)
|
||||||
pool = 1
|
pool = 1
|
||||||
wrestlers.sort_by{|x|[x.original_seed]}.reverse.each do |w|
|
wrestlers.sort_by{|x|[x.seed]}.reverse.each do |w|
|
||||||
if w.original_seed == 1
|
if w.seed == 1
|
||||||
w.poolNumber = 1
|
w.poolNumber = 1
|
||||||
elsif w.original_seed == 2
|
elsif w.seed == 2
|
||||||
w.poolNumber = 2
|
w.poolNumber = 2
|
||||||
elsif w.original_seed == 3
|
elsif w.seed == 3
|
||||||
w.poolNumber = 3
|
w.poolNumber = 3
|
||||||
elsif w.original_seed == 4
|
elsif w.seed == 4
|
||||||
w.poolNumber = 4
|
w.poolNumber = 4
|
||||||
else
|
else
|
||||||
w.poolNumber = pool
|
w.poolNumber = pool
|
||||||
@@ -141,4 +141,26 @@ class Weight < ActiveRecord::Base
|
|||||||
def poolOrder(pool)
|
def poolOrder(pool)
|
||||||
PoolOrder.new(wrestlersForPool(pool)).getPoolOrder
|
PoolOrder.new(wrestlersForPool(pool)).getPoolOrder
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def randomSeeding
|
||||||
|
wrestlerWithSeeds = wrestlers.select{|w| w.original_seed != nil }.sort_by{|w| w.original_seed}
|
||||||
|
highestSeed = wrestlerWithSeeds.last.original_seed
|
||||||
|
seed = highestSeed
|
||||||
|
wrestlersWithoutSeed = wrestlers.select{|w| w.original_seed == nil }
|
||||||
|
wrestlersWithoutSeed.shuffle.each do |w|
|
||||||
|
w.seed = seed
|
||||||
|
w.save
|
||||||
|
seed += 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def setSeeds
|
||||||
|
wrestlerWithSeeds = wrestlers.select{|w| w.original_seed != nil }.sort_by{|w| w.original_seed}
|
||||||
|
wrestlerWithSeeds.each do |w|
|
||||||
|
w.seed = w.original_seed
|
||||||
|
w.save
|
||||||
|
end
|
||||||
|
randomSeeding
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<% @wrestlers.select{|w| w.generatePoolNumber == @pool}.sort_by{|w| w.original_seed}.each do |w| %>
|
<% @wrestlers.select{|w| w.generatePoolNumber == @pool}.sort_by{|w| w.seed}.each do |w| %>
|
||||||
<tr>
|
<tr>
|
||||||
<td><%= w.original_seed %> <%= w.name %> <%= w.season_win %>-<%= w.season_loss %> <%= w.school.name %></td>
|
<td><%= w.original_seed %> <%= w.name %> <%= w.season_win %>-<%= w.season_loss %> <%= w.school.name %></td>
|
||||||
<% @round = 1 %>
|
<% @round = 1 %>
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<%= form_tag @wrestlers_update_path do %>
|
<%= form_tag @wrestlers_update_path do %>
|
||||||
<% @wrestlers.order("original_seed asc").each do |wrestler| %>
|
<% @wrestlers.sort_by{|w| [w.original_seed ? 0 : 1, w.original_seed || 0]}.each do |wrestler| %>
|
||||||
<% if wrestler.weight_id == @weight.id %>
|
<% if wrestler.weight_id == @weight.id %>
|
||||||
<tr>
|
<tr>
|
||||||
<td><%= wrestler.name %></td>
|
<td><%= wrestler.name %></td>
|
||||||
@@ -53,7 +53,9 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
<br><p>*All wrestlers without a seed (determined by tournament director) will be assigned a random seed.</p>
|
||||||
<% if tournament_permissions(@tournament) %>
|
<% if tournament_permissions(@tournament) %>
|
||||||
|
<br>
|
||||||
<%= submit_tag "Save", :class=>"btn btn-success"%>
|
<%= submit_tag "Save", :class=>"btn btn-success"%>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
5
test/fixtures/mats.yml
vendored
5
test/fixtures/mats.yml
vendored
@@ -11,3 +11,8 @@
|
|||||||
name: Mat1
|
name: Mat1
|
||||||
tournament_id: 1
|
tournament_id: 1
|
||||||
id: 1
|
id: 1
|
||||||
|
|
||||||
|
two:
|
||||||
|
name: 1
|
||||||
|
tournament_id: 2
|
||||||
|
id: 2
|
||||||
|
|||||||
4
test/fixtures/schools.yml
vendored
4
test/fixtures/schools.yml
vendored
@@ -10,4 +10,8 @@ two:
|
|||||||
name: Grove City
|
name: Grove City
|
||||||
tournament_id: 1
|
tournament_id: 1
|
||||||
|
|
||||||
|
three:
|
||||||
|
id: 3
|
||||||
|
name: Central Crossing
|
||||||
|
tournament_id: 2
|
||||||
|
|
||||||
|
|||||||
9
test/fixtures/tournaments.yml
vendored
9
test/fixtures/tournaments.yml
vendored
@@ -9,4 +9,13 @@ one:
|
|||||||
tournament_type: Pool to bracket
|
tournament_type: Pool to bracket
|
||||||
user_id: 1
|
user_id: 1
|
||||||
|
|
||||||
|
two:
|
||||||
|
id: 2
|
||||||
|
name: Comet Classic 2
|
||||||
|
address: Some Place
|
||||||
|
director: Jacob Cody Wimer
|
||||||
|
director_email: jacob.wimer@gmail.com
|
||||||
|
tournament_type: Pool to bracket
|
||||||
|
user_id: 1
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
5
test/fixtures/weights.yml
vendored
5
test/fixtures/weights.yml
vendored
@@ -26,4 +26,7 @@ five:
|
|||||||
tournament_id: 1
|
tournament_id: 1
|
||||||
|
|
||||||
|
|
||||||
|
six:
|
||||||
|
id: 6
|
||||||
|
max: 285
|
||||||
|
tournament_id: 1
|
||||||
|
|||||||
54
test/fixtures/wrestlers.yml
vendored
54
test/fixtures/wrestlers.yml
vendored
@@ -431,3 +431,57 @@ fourtyeight:
|
|||||||
season_loss: 2
|
season_loss: 2
|
||||||
season_win: 50
|
season_win: 50
|
||||||
criteria:
|
criteria:
|
||||||
|
|
||||||
|
fourtynine:
|
||||||
|
name: Guy38
|
||||||
|
school_id: 1
|
||||||
|
weight_id: 6
|
||||||
|
original_seed: 1
|
||||||
|
season_loss: 2
|
||||||
|
season_win: 50
|
||||||
|
criteria:
|
||||||
|
|
||||||
|
fourtynine:
|
||||||
|
name: Guy39
|
||||||
|
school_id: 1
|
||||||
|
weight_id: 6
|
||||||
|
original_seed: 2
|
||||||
|
season_loss: 2
|
||||||
|
season_win: 50
|
||||||
|
criteria:
|
||||||
|
|
||||||
|
fifty:
|
||||||
|
name: Guy40
|
||||||
|
school_id: 1
|
||||||
|
weight_id: 6
|
||||||
|
original_seed:
|
||||||
|
season_loss: 2
|
||||||
|
season_win: 50
|
||||||
|
criteria:
|
||||||
|
|
||||||
|
fiftyone:
|
||||||
|
name: Guy41
|
||||||
|
school_id: 1
|
||||||
|
weight_id: 6
|
||||||
|
original_seed:
|
||||||
|
season_loss: 2
|
||||||
|
season_win: 50
|
||||||
|
criteria:
|
||||||
|
|
||||||
|
fiftytwo:
|
||||||
|
name: Guy42
|
||||||
|
school_id: 1
|
||||||
|
weight_id: 6
|
||||||
|
original_seed:
|
||||||
|
season_loss: 2
|
||||||
|
season_win: 50
|
||||||
|
criteria:
|
||||||
|
|
||||||
|
fiftythree:
|
||||||
|
name: Guy43
|
||||||
|
school_id: 1
|
||||||
|
weight_id: 6
|
||||||
|
original_seed:
|
||||||
|
season_loss: 2
|
||||||
|
season_win: 50
|
||||||
|
criteria:
|
||||||
@@ -536,15 +536,12 @@ class PoolAdvancementTest < ActionDispatch::IntegrationTest
|
|||||||
assert_equal 12, wrestler.placementPoints
|
assert_equal 12, wrestler.placementPoints
|
||||||
end
|
end
|
||||||
|
|
||||||
test "advancement points fourPoolsToSemi Semis" do
|
test "advancement points fourPoolsToSemi Semis and Conso Semis" do
|
||||||
sixteenManToSemi
|
sixteenManToSemi
|
||||||
wrestler = Wrestler.where("name = ?", "Guy22").first
|
wrestler = Wrestler.where("name = ?", "Guy22").first
|
||||||
|
|
||||||
assert_equal 9, wrestler.placementPoints
|
assert_equal 9, wrestler.placementPoints
|
||||||
end
|
|
||||||
|
|
||||||
test "advancement points fourPoolsToSemi Conso Semis" do
|
|
||||||
sixteenManToSemi
|
|
||||||
wrestler = Wrestler.where("name = ?", "Guy29").first
|
wrestler = Wrestler.where("name = ?", "Guy29").first
|
||||||
|
|
||||||
assert_equal 3, wrestler.placementPoints
|
assert_equal 3, wrestler.placementPoints
|
||||||
|
|||||||
@@ -257,4 +257,11 @@ class PoolbracketMatchupsTest < ActionDispatch::IntegrationTest
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "Random seeding works" do
|
||||||
|
weight = Weight.find(6)
|
||||||
|
wrestlersWithoutSeed = weight.wrestlers.select{|w| w.seed == nil }.size
|
||||||
|
|
||||||
|
assert_equal 0, wrestlersWithoutSeed
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user