mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-03-25 01:14:43 +00:00
Added persistence to pool placement and pool order
This commit is contained in:
@@ -140,7 +140,7 @@ class Weight < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def pool_placement_order(pool)
|
||||
PoolOrder.new(wrestlers_in_pool(pool)).getPoolOrder
|
||||
#PoolOrder.new(wrestlers_in_pool(pool)).getPoolOrder
|
||||
end
|
||||
|
||||
def wrestlers_without_pool_assignment
|
||||
|
||||
@@ -40,6 +40,10 @@ class Wrestler < ActiveRecord::Base
|
||||
def total_pool_points_for_pool_order
|
||||
CalculateWrestlerTeamScore.new(self).poolPoints + CalculateWrestlerTeamScore.new(self).bonusWinPoints
|
||||
end
|
||||
|
||||
def unfinished_pool_matches
|
||||
unfinished_matches.select{|match| match.finished != 1}
|
||||
end
|
||||
|
||||
def next_match
|
||||
unfinished_matches.first
|
||||
@@ -195,6 +199,14 @@ class Wrestler < ActiveRecord::Base
|
||||
def fastest_pin
|
||||
pin_wins.sort_by{|m| m.pin_time_in_seconds}.first
|
||||
end
|
||||
|
||||
def pin_time
|
||||
time = 0
|
||||
pin_wins.each do | m |
|
||||
time = time + m.pin_time_in_seconds
|
||||
end
|
||||
time
|
||||
end
|
||||
|
||||
def season_win_percentage
|
||||
win = self.season_win.to_f
|
||||
|
||||
@@ -5,10 +5,17 @@ class AdvanceWrestler
|
||||
end
|
||||
|
||||
def advance
|
||||
PoolAdvance.new(@wrestler,@wrestler.last_match).advanceWrestler if @tournament.tournament_type == "Pool to bracket"
|
||||
pool_to_bracket_advancement if @tournament.tournament_type == "Pool to bracket"
|
||||
end
|
||||
if Rails.env.production?
|
||||
handle_asynchronously :advance
|
||||
end
|
||||
|
||||
def pool_to_bracket_advancement
|
||||
if @wrestler.weight.all_pool_matches_finished(@wrestler.pool) and (@wrestler.finished_bracket_matches.size == 0 or @wrestler.weight.pools == 1)
|
||||
PoolOrder.new(@wrestler.weight.wrestlers_in_pool(@wrestler.pool)).getPoolOrder
|
||||
end
|
||||
PoolAdvance.new(@wrestler,@wrestler.last_match).advanceWrestler
|
||||
end
|
||||
|
||||
end
|
||||
@@ -6,7 +6,7 @@ class PoolAdvance
|
||||
end
|
||||
|
||||
def advanceWrestler
|
||||
if @wrestler.weight.all_pool_matches_finished(@wrestler.pool) && @wrestler.finished_bracket_matches.size == 0
|
||||
if @wrestler.pool_placement and @wrestler.weight.pools > 1
|
||||
poolToBracketAdvancment
|
||||
end
|
||||
if @wrestler.finished_bracket_matches.size > 0
|
||||
@@ -15,20 +15,12 @@ class PoolAdvance
|
||||
end
|
||||
|
||||
def poolToBracketAdvancment
|
||||
pool = @wrestler.pool
|
||||
if @wrestler.weight.wrestlers.size > 6
|
||||
pool_placement_order = @wrestler.weight.pool_placement_order(pool)
|
||||
#Take pool order and move winner and runner up to correct match based on w1_name and w2_name
|
||||
matches = @wrestler.weight.matches
|
||||
winnerMatch = matches.select{|m| m.loser1_name == "Winner Pool #{pool}" || m.loser2_name == "Winner Pool #{pool}"}.first
|
||||
runnerUpMatch = matches.select{|m| m.loser1_name == "Runner Up Pool #{pool}" || m.loser2_name == "Runner Up Pool #{pool}"}.first
|
||||
winner = pool_placement_order.first
|
||||
runnerUp = pool_placement_order.second
|
||||
if runnerUpMatch
|
||||
runnerUpMatch.replace_loser_name_with_wrestler(runnerUp,"Runner Up Pool #{pool}")
|
||||
end
|
||||
winnerMatch.replace_loser_name_with_wrestler(winner,"Winner Pool #{pool}")
|
||||
end
|
||||
if @wrestler.pool_placement == 2
|
||||
runnerUpMatch.replace_loser_name_with_wrestler(runnerUp,"Runner Up Pool #{pool}")
|
||||
end
|
||||
if @wrestler.pool_placement == 1
|
||||
winnerMatch.replace_loser_name_with_wrestler(winner,"Winner Pool #{pool}")
|
||||
end
|
||||
end
|
||||
|
||||
def bracketAdvancment
|
||||
|
||||
@@ -8,6 +8,11 @@ class PoolOrder
|
||||
while checkForTieBreakers == true
|
||||
breakTie
|
||||
end
|
||||
@wrestlers.sort_by{|w| w.poolAdvancePoints}.reverse.each_with_index do |wrestler, index|
|
||||
placement = index + 1
|
||||
wrestler.pool_placement = placement
|
||||
wrestler.save
|
||||
end
|
||||
@wrestlers.sort_by{|w| w.poolAdvancePoints}.reverse!
|
||||
end
|
||||
|
||||
@@ -41,7 +46,7 @@ class PoolOrder
|
||||
|
||||
def breakTie
|
||||
originalTieSize = wrestlersWithSamePoints.size
|
||||
ifWrestlersWithSamePointsIsSameAsOriginal(originalTieSize) { deductedPoints }
|
||||
#ifWrestlersWithSamePointsIsSameAsOriginal(originalTieSize) { deductedPoints }
|
||||
if originalTieSize == 2
|
||||
ifWrestlersWithSamePointsIsSameAsOriginal(originalTieSize) { headToHead }
|
||||
end
|
||||
@@ -50,7 +55,7 @@ class PoolOrder
|
||||
ifWrestlersWithSamePointsIsSameAsOriginal(originalTieSize) { mostTechs }
|
||||
ifWrestlersWithSamePointsIsSameAsOriginal(originalTieSize) { mostMajors }
|
||||
ifWrestlersWithSamePointsIsSameAsOriginal(originalTieSize) { mostDecisionPointsScored }
|
||||
ifWrestlersWithSamePointsIsSameAsOriginal(originalTieSize) { fastest_pin }
|
||||
ifWrestlersWithSamePointsIsSameAsOriginal(originalTieSize) { fastest_pins }
|
||||
ifWrestlersWithSamePointsIsSameAsOriginal(originalTieSize) { coinFlip }
|
||||
end
|
||||
|
||||
@@ -60,6 +65,8 @@ class PoolOrder
|
||||
otherWrestler = wrestlersWithSamePoints.select{|w| w.id != wr.id}.first
|
||||
if wr.match_against(otherWrestler).first.winner_id == wr.id
|
||||
addPointsToWrestlersAhead(wr)
|
||||
wr.pool_placement_tiebreaker = "Head to Head"
|
||||
wr.save
|
||||
addPoints(wr)
|
||||
end
|
||||
end
|
||||
@@ -85,6 +92,8 @@ class PoolOrder
|
||||
wrestlersWithLeastDeductedPoints = wrestlersWithSamePoints.select{|w| w.total_points_deducted == leastPoints}
|
||||
addPointsToWrestlersAhead(wrestlersWithLeastDeductedPoints.first)
|
||||
wrestlersWithLeastDeductedPoints.each do |wr|
|
||||
wr.pool_placement_tiebreaker = "Least Deducted Points"
|
||||
wr.save
|
||||
addPoints(wr)
|
||||
end
|
||||
end
|
||||
@@ -98,17 +107,21 @@ class PoolOrder
|
||||
wrestlersWithMostPoints = wrestlersWithSamePoints.select{|w| w.decision_points_scored == mostPoints}
|
||||
addPointsToWrestlersAhead(wrestlersWithMostPoints.first)
|
||||
wrestlersWithMostPoints.each do |wr|
|
||||
wr.pool_placement_tiebreaker = "Points Scored"
|
||||
wr.save
|
||||
addPoints(wr)
|
||||
end
|
||||
secondPoints = pointsArray.sort[-2]
|
||||
wrestlersWithSecondMostPoints = wrestlersWithSamePoints.select{|w| w.decision_points_scored == secondPoints}
|
||||
addPointsToWrestlersAhead(wrestlersWithSecondMostPoints.first)
|
||||
wrestlersWithSecondMostPoints.each do |wr|
|
||||
wr.pool_placement_tiebreaker = "Points Scored"
|
||||
wr.save
|
||||
addPoints(wr)
|
||||
end
|
||||
end
|
||||
|
||||
def fastest_pin
|
||||
def fastest_pins
|
||||
wrestlersWithSamePointsWithPins = []
|
||||
wrestlersWithSamePoints.each do |wr|
|
||||
if wr.pin_wins.size > 0
|
||||
@@ -121,12 +134,16 @@ class PoolOrder
|
||||
wrestlersWithFastestPin = wrestlersWithSamePointsWithPins.select{|w| w.fastest_pin.pin_time_in_seconds == fastest.pin_time_in_seconds}
|
||||
addPointsToWrestlersAhead(wrestlersWithFastestPin.first)
|
||||
wrestlersWithFastestPin.each do |wr|
|
||||
wr.pool_placement_tiebreaker = "Pin Time"
|
||||
wr.save
|
||||
addPoints(wr)
|
||||
end
|
||||
|
||||
wrestlersWithSecondFastestPin = wrestlersWithSamePointsWithPins.select{|w| w.fastest_pin.pin_time_in_seconds == secondFastest.pin_time_in_seconds}
|
||||
addPointsToWrestlersAhead(wrestlersWithSecondFastestPin.first)
|
||||
wrestlersWithSecondFastestPin.each do |wr|
|
||||
wr.pool_placement_tiebreaker = "Pin Time"
|
||||
wr.save
|
||||
addPoints(wr)
|
||||
end
|
||||
end
|
||||
@@ -138,9 +155,11 @@ class PoolOrder
|
||||
pointsArray << w.total_pool_points_for_pool_order
|
||||
end
|
||||
mostPoints = pointsArray.max
|
||||
wrestlersWithLeastDeductedPoints = wrestlersWithSamePoints.select{|w| w.total_pool_points_for_pool_order == mostPoints}
|
||||
addPointsToWrestlersAhead(wrestlersWithLeastDeductedPoints.first)
|
||||
wrestlersWithLeastDeductedPoints.each do |wr|
|
||||
wrestlersSortedByTeamPoints = wrestlersWithSamePoints.select{|w| w.total_pool_points_for_pool_order == mostPoints}
|
||||
addPointsToWrestlersAhead(wrestlersSortedByTeamPoints.first)
|
||||
wrestlersSortedByTeamPoints.each do |wr|
|
||||
wr.pool_placement_tiebreaker = "Team Points"
|
||||
wr.save
|
||||
addPoints(wr)
|
||||
end
|
||||
end
|
||||
@@ -151,9 +170,11 @@ class PoolOrder
|
||||
pointsArray << w.pin_wins.size
|
||||
end
|
||||
mostPoints = pointsArray.max
|
||||
wrestlersWithLeastDeductedPoints = wrestlersWithSamePoints.select{|w| w.pin_wins.size == mostPoints}
|
||||
addPointsToWrestlersAhead(wrestlersWithLeastDeductedPoints.first)
|
||||
wrestlersWithLeastDeductedPoints.each do |wr|
|
||||
wrestlersSortedByFallWins = wrestlersWithSamePoints.select{|w| w.pin_wins.size == mostPoints}
|
||||
addPointsToWrestlersAhead(wrestlersSortedByFallWins.first)
|
||||
wrestlersSortedByFallWins.each do |wr|
|
||||
wr.pool_placement_tiebreaker = "Most Pins"
|
||||
wr.save
|
||||
addPoints(wr)
|
||||
end
|
||||
end
|
||||
@@ -164,9 +185,11 @@ class PoolOrder
|
||||
pointsArray << w.tech_wins.size
|
||||
end
|
||||
mostPoints = pointsArray.max
|
||||
wrestlersWithLeastDeductedPoints = wrestlersWithSamePoints.select{|w| w.tech_wins.size == mostPoints}
|
||||
addPointsToWrestlersAhead(wrestlersWithLeastDeductedPoints.first)
|
||||
wrestlersWithLeastDeductedPoints.each do |wr|
|
||||
wrestlersSortedByTechWins = wrestlersWithSamePoints.select{|w| w.tech_wins.size == mostPoints}
|
||||
addPointsToWrestlersAhead(wrestlersSortedByTechWins.first)
|
||||
wrestlersSortedByTechWins.each do |wr|
|
||||
wr.pool_placement_tiebreaker = "Most Techs"
|
||||
wr.save
|
||||
addPoints(wr)
|
||||
end
|
||||
end
|
||||
@@ -177,15 +200,19 @@ class PoolOrder
|
||||
pointsArray << w.major_wins.size
|
||||
end
|
||||
mostPoints = pointsArray.max
|
||||
wrestlersWithLeastDeductedPoints = wrestlersWithSamePoints.select{|w| w.major_wins.size == mostPoints}
|
||||
addPointsToWrestlersAhead(wrestlersWithLeastDeductedPoints.first)
|
||||
wrestlersWithLeastDeductedPoints.each do |wr|
|
||||
wrestlersSortedByMajorWins = wrestlersWithSamePoints.select{|w| w.major_wins.size == mostPoints}
|
||||
addPointsToWrestlersAhead(wrestlersSortedByMajorWins.first)
|
||||
wrestlersSortedByMajorWins.each do |wr|
|
||||
wr.pool_placement_tiebreaker = "Most Majors"
|
||||
wr.save
|
||||
addPoints(wr)
|
||||
end
|
||||
end
|
||||
|
||||
def coinFlip
|
||||
wrestler = wrestlersWithSamePoints.sample
|
||||
wrestler.pool_placement_tiebreaker = "Coin Flip"
|
||||
wrestler.save
|
||||
addPointsToWrestlersAhead(wrestler)
|
||||
addPoints(wrestler)
|
||||
end
|
||||
|
||||
@@ -67,14 +67,13 @@ class PoolBracketPlacementPoints
|
||||
end
|
||||
|
||||
def onePool
|
||||
pool_placement_order = @wrestler.weight.pool_placement_order(1)
|
||||
if @wrestler == pool_placement_order.first
|
||||
if @wrestler.pool_placement == 1
|
||||
return firstPlace
|
||||
elsif @wrestler == pool_placement_order.second
|
||||
elsif @wrestler.pool_placement == 2
|
||||
return secondPlace
|
||||
elsif @wrestler == pool_placement_order.third
|
||||
elsif @wrestler.pool_placement == 3
|
||||
return thirdPlace
|
||||
elsif @wrestler == pool_placement_order.fourth
|
||||
elsif @wrestler.pool_placement == 4
|
||||
return fourthPlace
|
||||
end
|
||||
return 0
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
<% end %>
|
||||
<% @round = @round + 1 %>
|
||||
<% end %>
|
||||
<th>Placement</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -25,6 +26,7 @@
|
||||
<% end %>
|
||||
<% @round = @round + 1 %>
|
||||
<% end %>
|
||||
<td><%= w.pool_placement %><br><%= w.pool_placement_tiebreaker %></td>
|
||||
|
||||
</tr>
|
||||
<% end %>
|
||||
|
||||
@@ -24,14 +24,14 @@
|
||||
<tr>
|
||||
<td><%= link_to "#{tournament.name}", tournament %></td>
|
||||
<td><%= tournament.date %></td>
|
||||
<td>
|
||||
<% if can? :manage, tournament %>
|
||||
<td>
|
||||
<%= link_to '', edit_tournament_path(tournament), :class=>"fas fa-edit" %>
|
||||
<% if can? :destroy, tournament %>
|
||||
<%= link_to '', tournament, method: :delete, data: { confirm: "Are you sure you want to delete #{tournament.name}?" }, :class=>"fas fa-trash-alt" %>
|
||||
<% end %>
|
||||
</td>
|
||||
<% end %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
|
||||
Reference in New Issue
Block a user