mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-03-30 19:22:21 +00:00
Random seeding now works
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
module GeneratesTournamentMatches
|
||||
|
||||
def generateMatchups
|
||||
resetSchoolScores
|
||||
setSeedsAndRandomSeedingWrestlersWithoutSeeds
|
||||
poolToBracket() if tournament_type == "Pool to bracket"
|
||||
matches
|
||||
end
|
||||
@@ -9,7 +11,6 @@ module GeneratesTournamentMatches
|
||||
end
|
||||
|
||||
def poolToBracket
|
||||
resetSchoolScores
|
||||
destroyAllMatches
|
||||
buildTournamentWeights
|
||||
generateMatches
|
||||
@@ -39,5 +40,11 @@ module GeneratesTournamentMatches
|
||||
m.save
|
||||
end
|
||||
end
|
||||
|
||||
def setSeedsAndRandomSeedingWrestlersWithoutSeeds
|
||||
weights.each do |w|
|
||||
w.setSeeds
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -49,7 +49,7 @@ class Weight < ActiveRecord::Base
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
return wrestlers
|
||||
@@ -58,14 +58,14 @@ class Weight < ActiveRecord::Base
|
||||
|
||||
def twoPoolNumbers(wrestlers)
|
||||
pool = 1
|
||||
wrestlers.sort_by{|x|[x.original_seed]}.reverse.each do |w|
|
||||
if w.original_seed == 1
|
||||
wrestlers.sort_by{|x|[x.seed]}.reverse.each do |w|
|
||||
if w.seed == 1
|
||||
w.poolNumber = 1
|
||||
elsif w.original_seed == 2
|
||||
elsif w.seed == 2
|
||||
w.poolNumber = 2
|
||||
elsif w.original_seed == 3
|
||||
elsif w.seed == 3
|
||||
w.poolNumber = 2
|
||||
elsif w.original_seed == 4
|
||||
elsif w.seed == 4
|
||||
w.poolNumber = 1
|
||||
else
|
||||
w.poolNumber = pool
|
||||
@@ -81,14 +81,14 @@ class Weight < ActiveRecord::Base
|
||||
|
||||
def fourPoolNumbers(wrestlers)
|
||||
pool = 1
|
||||
wrestlers.sort_by{|x|[x.original_seed]}.reverse.each do |w|
|
||||
if w.original_seed == 1
|
||||
wrestlers.sort_by{|x|[x.seed]}.reverse.each do |w|
|
||||
if w.seed == 1
|
||||
w.poolNumber = 1
|
||||
elsif w.original_seed == 2
|
||||
elsif w.seed == 2
|
||||
w.poolNumber = 2
|
||||
elsif w.original_seed == 3
|
||||
elsif w.seed == 3
|
||||
w.poolNumber = 3
|
||||
elsif w.original_seed == 4
|
||||
elsif w.seed == 4
|
||||
w.poolNumber = 4
|
||||
else
|
||||
w.poolNumber = pool
|
||||
@@ -141,4 +141,26 @@ class Weight < ActiveRecord::Base
|
||||
def poolOrder(pool)
|
||||
PoolOrder.new(wrestlersForPool(pool)).getPoolOrder
|
||||
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
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<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>
|
||||
<td><%= w.original_seed %> <%= w.name %> <%= w.season_win %>-<%= w.season_loss %> <%= w.school.name %></td>
|
||||
<% @round = 1 %>
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
<%= 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 %>
|
||||
<tr>
|
||||
<td><%= wrestler.name %></td>
|
||||
@@ -53,7 +53,9 @@
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<br><p>*All wrestlers without a seed (determined by tournament director) will be assigned a random seed.</p>
|
||||
<% if tournament_permissions(@tournament) %>
|
||||
<br>
|
||||
<%= submit_tag "Save", :class=>"btn btn-success"%>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
5
test/fixtures/mats.yml
vendored
5
test/fixtures/mats.yml
vendored
@@ -11,3 +11,8 @@
|
||||
name: Mat1
|
||||
tournament_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
|
||||
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
|
||||
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
|
||||
|
||||
|
||||
|
||||
six:
|
||||
id: 6
|
||||
max: 285
|
||||
tournament_id: 1
|
||||
|
||||
54
test/fixtures/wrestlers.yml
vendored
54
test/fixtures/wrestlers.yml
vendored
@@ -430,4 +430,58 @@ fourtyeight:
|
||||
original_seed: 16
|
||||
season_loss: 2
|
||||
season_win: 50
|
||||
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
|
||||
end
|
||||
|
||||
test "advancement points fourPoolsToSemi Semis" do
|
||||
test "advancement points fourPoolsToSemi Semis and Conso Semis" do
|
||||
sixteenManToSemi
|
||||
wrestler = Wrestler.where("name = ?", "Guy22").first
|
||||
|
||||
assert_equal 9, wrestler.placementPoints
|
||||
end
|
||||
|
||||
test "advancement points fourPoolsToSemi Conso Semis" do
|
||||
sixteenManToSemi
|
||||
|
||||
wrestler = Wrestler.where("name = ?", "Guy29").first
|
||||
|
||||
assert_equal 3, wrestler.placementPoints
|
||||
|
||||
@@ -256,5 +256,12 @@ class PoolbracketMatchupsTest < ActionDispatch::IntegrationTest
|
||||
assert_equal lastRound, m.round
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user