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

Finished pool advance logic still need tests

This commit is contained in:
2015-10-14 17:58:28 -04:00
parent 087c383996
commit 386dc1605f
11 changed files with 120 additions and 70 deletions

View File

@@ -3,9 +3,31 @@ class Match < ActiveRecord::Base
belongs_to :weight
belongs_to :mat
after_save do
if self.finished == 1
advance_wrestlers
end
end
WIN_TYPES = ["Decision", "Major", "Tech Fall", "Pin", "Forfeit", "Injury Default", "Default", "DQ"]
def advance_wrestlers
if self.w1? && self.w2?
@w1 = Wrestler.find(self.w1)
@w2 = Wrestler.find(self.w2)
@w1.advanceInBracket
@w2.advanceInBracket
end
end
def bracketScore
if self.finished != 1
return ""
end
if self.finished == 1
return "(#{self.score})"
end
end
def w1_name
if self.w1
@@ -38,7 +60,7 @@ class Match < ActiveRecord::Base
end
end
def poolNumber
if self.w1
if self.w1?
Wrestler.find(self.w1).generatePoolNumber
end
end

View File

@@ -17,7 +17,7 @@ class Pool
def roundRobin
matches = []
wrestlers = @weight.wrestlers_for_pool(@pool)
wrestlers = @weight.wrestlersForPool(@pool)
poolMatches = RoundRobinTournament.schedule(wrestlers).reverse
poolMatches.each_with_index do |b, index|
round = index + 1

View File

@@ -2,29 +2,17 @@ class Pooladvance
attr_accessor :wrestler
def poolRank
#Give wrestlers pool points then give extra points for tie breakers and spit them out
#in order from first to last
#Calculate wrestlers pool points in their model
#Order wrestlers by pool in the weight model
end
def advanceWrestler
if self.wrestler.poolMatches.size > self.wrestler.finishedMatches.size
return nil
if self.wrestler.weight.allPoolMatchesFinished(self.wrestler.generatePoolNumber) && self.wrestler.finishedBracketMatches.size == 0
poolToBracketAdvancment
end
if self.wrestler.finishedBracketMatches.size != 0
bracketAdvancment
end
poolToBracketAdvancment
bracketAdvancment
end
def poolToBracketAdvancment
@pool = self.wrestler.generatePoolNumber
@poolWrestlers = self.wrestler.weight.wrestlers_for_pool(@pool)
@poolWrestlers.each do |w|
if w.finishedBracketMatches.size > 0
return nil
end
end
#Move to correct spot in bracket from pool
#Pool criteria
#Wins
@@ -35,8 +23,7 @@ class Pooladvance
#Coin flip
#if not one pool
if self.wrestler.weight.wrestlers.size > 6
@poolOrder = self.wrestler.weight.poolOrder
@poolOrder = self.wrestler.weight.poolOrder(@pool)
#Take pool order and move winner and runner up to correct match based on w1_name and w2_name
@matches = self.wrestler.weight.matches
@winnerMatch = @matches.select{|m| m.loser1_name == "Winner Pool #{@pool}" || m.loser2_name == "Winner Pool #{@pool}"}.first
@@ -49,9 +36,6 @@ class Pooladvance
end
def bracketAdvancment
if self.wrestler.finishedBracketMatches.size == 0
return nil
end
#Move to next correct spot in bracket
@matches = self.wrestler.finishedMatches.sort_by{|m| m.round}.reverse
@last_match = @matches.first
@@ -64,12 +48,35 @@ end
end
def winnerAdvance(last_match)
#Quarter to Semis
#Semis to 1/2
#Conso Semis to 5/6
@pos = last_match.bracket_position_number
@new_pos = (@pos/2.0)
if last_match.bracket_position == "Quarter"
@new_match = Match.where("bracket_position = ? AND bracket_position_number = ?","Semis",@new_pos.ceil).first
end
if last_match.bracket_position == "Semis"
@new_match = Match.where("bracket_position = ? AND bracket_position_number = ?","1/2",@new_pos.ceil).first
end
if last_match.bracket_position == "Conso Semis"
@new_match = Match.where("bracket_position = ? AND bracket_position_number = ?","5/6",@new_pos.ceil).first
end
if @new_match
if @new_pos == @new_pos.ceil
@new_match.w2 = self.wrestler.id
@new_match.save
end
if @new_pos != @new_pos.ceil
@new_match.w1 = self.wrestler.id
@new_match.save
end
end
end
def loserAdvance(last_match)
@bout = last_match.bout_number
@next_match = Match.where("loser_name = ?","Loser of #{@bout}")
@next_match = Match.where("loser1_name = ? or loser2_name = ?","Loser of #{@bout}","Loser of #{@bout}")
if @next_match.size > 0
@next_match.first.replaceLoserNameWithWrestler(self.wrestler,"Loser of #{@bout}")
end

View File

@@ -11,8 +11,18 @@ class Weight < ActiveRecord::Base
self.tournament.destroyAllMatches
end
def wrestlers_for_pool(pool)
wrestlers.select{|w| w.generatePoolNumber == pool}.to_a
def wrestlersForPool(pool)
self.wrestlers.select{|w| w.generatePoolNumber == pool}
end
def allPoolMatchesFinished(pool)
@wrestlers = wrestlersForPool(pool)
@wrestlers.each do |w|
if w.poolMatches.size != w.finishedPoolMatches.size
return false
end
end
return true
end
def pools
@@ -118,19 +128,19 @@ class Weight < ActiveRecord::Base
def totalRounds(matches)
@matchups = matches.select{|m| m.weight_id == self.id}
@lastRound = matches.sort_by{|m| m.round}.last.round
@count = 0
count = 0
@round =1
until @round > @lastRound do
if @matchups.select{|m| m.round == @round}
@count = @count + 1
count = count + 1
end
@round = @round + 1
end
return @count
return count
end
def poolOrder
@wrestlers = self.wrestlers
@wrestlers.sort_by{|w| w.poolWins.count}.reverse!
def poolOrder(pool)
@wrestlers = wrestlersForPool(pool)
@wrestlers.sort_by{|w| w.poolWins.size}.reverse!
end
end

View File

@@ -8,6 +8,19 @@ class Wrestler < ActiveRecord::Base
self.tournament.destroyAllMatches
end
def resultByBout(bout)
@match = Match.where("bout_number = ? AND finished = ?",bout,1)
if @match.size == 0
return ""
end
if @match.first.winner_id == self.id
return "W #{@match.first.score}"
end
if @match.first.winner_id != self.id
return "L #{@match.first.score}"
end
end
def isWrestlingThisRound(matchRound)
if allMatches.blank?

View File

@@ -66,7 +66,7 @@ li.game{
<li class="spacer">&nbsp;</li>
<li class="game game-top "><%= match.w1_name %> <span>Score</span></li>
<li class="game game-spacer"><%= match.bout_number %> &nbsp;</li>
<li class="game game-spacer"><%= match.bout_number %> <%= match.bracketScore %>&nbsp;</li>
<li class="game game-bottom "><%= match.w2_name %><span>Score</span></li>
<li class="spacer">&nbsp;</li>
@@ -78,7 +78,7 @@ li.game{
<li class="spacer">&nbsp;</li>
<li class="game game-top "><%= match.w1_name %> <span>Score</span></li>
<li class="game game-spacer"><%= match.bout_number %> &nbsp;</li>
<li class="game game-spacer"><%= match.bout_number %> <%= match.bracketScore %>&nbsp;</li>
<li class="game game-bottom "><%= match.w2_name %><span>Score</span></li>
<li class="spacer">&nbsp;</li>
@@ -90,7 +90,7 @@ li.game{
<li class="spacer">&nbsp;</li>
<li class="game game-top "><%= match.w1_name %> <span>Score</span></li>
<li class="game game-spacer"><%= match.bout_number %> &nbsp;</li>
<li class="game game-spacer"><%= match.bout_number %> <%= match.bracketScore %>&nbsp;</li>
<li class="game game-bottom "><%= match.w2_name %><span>Score</span></li>
<li class="spacer">&nbsp;</li>
@@ -115,7 +115,7 @@ li.game{
<li class="spacer">&nbsp;</li>
<li class="game game-top "><%= match.w1_name %> <span>Score</span></li>
<li class="game game-spacer"><%= match.bout_number %> &nbsp;</li>
<li class="game game-spacer"><%= match.bout_number %> <%= match.bracketScore %>&nbsp;</li>
<li class="game game-bottom "><%= match.w2_name %><span>Score</span></li>
<li class="spacer">&nbsp;</li>
@@ -140,7 +140,7 @@ li.game{
<li class="spacer">&nbsp;</li>
<li class="game game-top "><%= match.w1_name %> <span>Score</span></li>
<li class="game game-spacer"><%= match.bout_number %> &nbsp;</li>
<li class="game game-spacer"><%= match.bout_number %> <%= match.bracketScore %>&nbsp;</li>
<li class="game game-bottom "><%= match.w2_name %><span>Score</span></li>
<li class="spacer">&nbsp;</li>
@@ -152,7 +152,7 @@ li.game{
<li class="spacer">&nbsp;</li>
<li class="game game-top "><%= match.w1_name %> <span>Score</span></li>
<li class="game game-spacer"><%= match.bout_number %> &nbsp;</li>
<li class="game game-spacer"><%= match.bout_number %> <%= match.bracketScore %>&nbsp;</li>
<li class="game game-bottom "><%= match.w2_name %><span>Score</span></li>
<li class="spacer">&nbsp;</li>
@@ -177,7 +177,7 @@ li.game{
<li class="spacer">&nbsp;</li>
<li class="game game-top "><%= match.w1_name %> <span>Score</span></li>
<li class="game game-spacer"><%= match.bout_number %> &nbsp;</li>
<li class="game game-spacer"><%= match.bout_number %> <%= match.bracketScore %>&nbsp;</li>
<li class="game game-bottom "><%= match.w2_name %><span>Score</span></li>
<li class="spacer">&nbsp;</li>

View File

@@ -66,7 +66,7 @@ li.game{
<li class="spacer">&nbsp;</li>
<li class="game game-top "><%= match.w1_name %> <span>Score</span></li>
<li class="game game-spacer"><%= match.bout_number %> &nbsp;</li>
<li class="game game-spacer"><%= match.bout_number %> <%= match.bracketScore %>&nbsp;</li>
<li class="game game-bottom "><%= match.w2_name %><span>Score</span></li>
<li class="spacer">&nbsp;</li>
@@ -78,7 +78,7 @@ li.game{
<li class="spacer">&nbsp;</li>
<li class="game game-top "><%= match.w1_name %> <span>Score</span></li>
<li class="game game-spacer"><%= match.bout_number %> &nbsp;</li>
<li class="game game-spacer"><%= match.bout_number %> <%= match.bracketScore %>&nbsp;</li>
<li class="game game-bottom "><%= match.w2_name %><span>Score</span></li>
<li class="spacer">&nbsp;</li>
@@ -104,7 +104,7 @@ li.game{
<li class="spacer">&nbsp;</li>
<li class="game game-top "><%= match.w1_name %> <span>Score</span></li>
<li class="game game-spacer"><%= match.bout_number %> &nbsp;</li>
<li class="game game-spacer"><%= match.bout_number %> <%= match.bracketScore %>&nbsp;</li>
<li class="game game-bottom "><%= match.w2_name %><span>Score</span></li>
<li class="spacer">&nbsp;</li>
@@ -131,7 +131,7 @@ li.game{
<li class="spacer">&nbsp;</li>
<li class="game game-top "><%= match.w1_name %> <span>Score</span></li>
<li class="game game-spacer"><%= match.bout_number %> &nbsp;</li>
<li class="game game-spacer"><%= match.bout_number %> <%= match.bracketScore %>&nbsp;</li>
<li class="game game-bottom "><%= match.w2_name %><span>Score</span></li>
<li class="spacer">&nbsp;</li>
@@ -143,7 +143,7 @@ li.game{
<li class="spacer">&nbsp;</li>
<li class="game game-top "><%= match.w1_name %> <span>Score</span></li>
<li class="game game-spacer"><%= match.bout_number %> &nbsp;</li>
<li class="game game-spacer"><%= match.bout_number %> <%= match.bracketScore %>&nbsp;</li>
<li class="game game-bottom "><%= match.w2_name %><span>Score</span></li>
<li class="spacer">&nbsp;</li>
@@ -168,7 +168,7 @@ li.game{
<li class="spacer">&nbsp;</li>
<li class="game game-top "><%= match.w1_name %> <span>Score</span></li>
<li class="game game-spacer"><%= match.bout_number %> &nbsp;</li>
<li class="game game-spacer"><%= match.bout_number %> <%= match.bracketScore %>&nbsp;</li>
<li class="game game-bottom "><%= match.w2_name %><span>Score</span></li>
<li class="spacer">&nbsp;</li>

View File

@@ -21,7 +21,7 @@
<% @round = 1 %>
<% until @matches.select{|m| m.round == @round}.blank? %>
<% if @round <= @pools %>
<td><%= w.boutByRound(@round) %><br>Result</td>
<td><%= w.boutByRound(@round) %><br><%= w.resultByBout(w.boutByRound(@round)) %></td>
<% end %>
<% @round = @round + 1 %>
<% end %>

View File

@@ -66,7 +66,7 @@ li.game{
<li class="spacer">&nbsp;</li>
<li class="game game-top "><%= match.w1_name %> <span>Score</span></li>
<li class="game game-spacer"><%= match.bout_number %> &nbsp;</li>
<li class="game game-spacer"><%= match.bout_number %> <%= match.bracketScore %>&nbsp;</li>
<li class="game game-bottom "><%= match.w2_name %><span>Score</span></li>
<li class="spacer">&nbsp;</li>
@@ -90,7 +90,7 @@ li.game{
<li class="spacer">&nbsp;</li>
<li class="game game-top "><%= match.w1_name %> <span>Score</span></li>
<li class="game game-spacer"><%= match.bout_number %> &nbsp;</li>
<li class="game game-spacer"><%= match.bout_number %> <%= match.bracketScore %>&nbsp;</li>
<li class="game game-bottom "><%= match.w2_name %><span>Score</span></li>
<li class="spacer">&nbsp;</li>

View File

@@ -66,7 +66,7 @@ li.game{
<li class="spacer">&nbsp;</li>
<li class="game game-top "><%= match.w1_name %> <span>Score</span></li>
<li class="game game-spacer"><%= match.bout_number %> &nbsp;</li>
<li class="game game-spacer"><%= match.bout_number %> <%= match.bracketScore %>&nbsp;</li>
<li class="game game-bottom "><%= match.w2_name %><span>Score</span></li>
<li class="spacer">&nbsp;</li>
@@ -78,7 +78,7 @@ li.game{
<li class="spacer">&nbsp;</li>
<li class="game game-top "><%= match.w1_name %> <span>Score</span></li>
<li class="game game-spacer"><%= match.bout_number %> &nbsp;</li>
<li class="game game-spacer"><%= match.bout_number %> <%= match.bracketScore %>&nbsp;</li>
<li class="game game-bottom "><%= match.w2_name %><span>Score</span></li>
<li class="spacer">&nbsp;</li>
@@ -104,7 +104,7 @@ li.game{
<li class="spacer">&nbsp;</li>
<li class="game game-top "><%= match.w1_name %> <span>Score</span></li>
<li class="game game-spacer"><%= match.bout_number %> &nbsp;</li>
<li class="game game-spacer"><%= match.bout_number %> <%= match.bracketScore %>&nbsp;</li>
<li class="game game-bottom "><%= match.w2_name %><span>Score</span></li>
<li class="spacer">&nbsp;</li>
@@ -120,4 +120,4 @@ li.game{
<li class="spacer">&nbsp;</li>
</ul>
</main>
</main>

View File

@@ -8,28 +8,25 @@ class PoolAdvancementTest < ActionDispatch::IntegrationTest
def setup
@tournament = Tournament.find(1)
@tournament.generateMatchups
@matches = @tournament.matches.select{|m| m.weight_id == 3 && m.bracket_position == "Pool"}
nineManBracketPoolOne
@wrestlers = Wrestler.where("weight_id = ?", 3)
@wrestlers.each do |w|
w.advanceInBracket
end
end
def nineManBracketPoolOne
endMatch(1002,"Guy8")
endMatch(1003,"Guy10")
endMatch(2002,"Guy2")
endMatch(2003,"Guy8")
endMatch(3003,"Guy2")
endMatch(4002,"Guy8")
endMatch(4003,"Guy2")
endMatch(5002,"Guy2")
endMatch(5003,"Guy5")
@matches = @tournament.matches.select{|m| m.weight_id == 3 && m.bracket_position == "Pool"}
endMatch(1002,"Guy8",@matches)
endMatch(1003,"Guy10",@matches)
endMatch(2002,"Guy2",@matches)
endMatch(2003,"Guy8",@matches)
endMatch(3003,"Guy2",@matches)
endMatch(4002,"Guy8",@matches)
endMatch(4003,"Guy2",@matches)
endMatch(5002,"Guy2",@matches)
endMatch(5003,"Guy5",@matches)
endMatch(3002,"Guy5",@matches)
end
def endMatch(bout,winner)
@match = @matches.select{|m| m.bout_number == bout}.first
def endMatch(bout,winner,matches)
@match = matches.select{|m| m.bout_number == bout}.first
@match.finished = 1
@match.winner_id = translateNameToId(winner)
@match.win_type = "Decision"
@@ -41,6 +38,7 @@ class PoolAdvancementTest < ActionDispatch::IntegrationTest
test "nine man outright finals advance" do
@wrestler = Wrestler.where("name = ?", "Guy2").first
@match = Match.where("bout_number = ?",6000).first
assert_equal 6000, @wrestler.boutByRound(6)
end