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

Continuing pool bracket movements

This commit is contained in:
2015-10-13 20:57:35 -04:00
parent 906d79c5ac
commit 087c383996
7 changed files with 94 additions and 8 deletions

View File

@@ -37,4 +37,9 @@ class Match < ActiveRecord::Base
self.save
end
end
def poolNumber
if self.w1
Wrestler.find(self.w1).generatePoolNumber
end
end
end

View File

@@ -11,7 +11,7 @@ class Pooladvance
def advanceWrestler
if self.wrestler.poolMatches.size > self.wrestler.finishedMatches.size
exit
return nil
end
poolToBracketAdvancment
bracketAdvancment
@@ -22,7 +22,7 @@ class Pooladvance
@poolWrestlers = self.wrestler.weight.wrestlers_for_pool(@pool)
@poolWrestlers.each do |w|
if w.finishedBracketMatches.size > 0
exit
return nil
end
end
#Move to correct spot in bracket from pool
@@ -49,8 +49,29 @@ 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
if @last_match.winner_id == self.wrestler.id
winnerAdvance(@last_match)
end
if @last_match.winner_id != self.wrestler.id
loserAdvance(@last_match)
end
end
def winnerAdvance(last_match)
end
def loserAdvance(last_match)
@bout = last_match.bout_number
@next_match = Match.where("loser_name = ?","Loser of #{@bout}")
if @next_match.size > 0
@next_match.first.replaceLoserNameWithWrestler(self.wrestler,"Loser of #{@bout}")
end
end
end

View File

@@ -131,6 +131,6 @@ class Weight < ActiveRecord::Base
def poolOrder
@wrestlers = self.wrestlers
@wrestlers.sort_by{|w| w.poolWins}.reverse
@wrestlers.sort_by{|w| w.poolWins.count}.reverse!
end
end

View File

@@ -21,7 +21,7 @@ class Wrestler < ActiveRecord::Base
@pool = self.weight.returnPoolNumber(self)
end
def boutByRound(round,matches)
def boutByRound(round)
@match = allMatches.select{|m| m.round == round}.first
if @match.blank?
return "BYE"
@@ -36,7 +36,8 @@ class Wrestler < ActiveRecord::Base
end
def poolMatches
allMatches.select{|m| m.bracket_position == "Pool"}
@poolMatches = allMatches.select{|m| m.bracket_position == "Pool"}
@poolMatches.select{|m| m.poolNumber == self.generatePoolNumber}
end
def finishedMatches
@@ -67,4 +68,10 @@ class Wrestler < ActiveRecord::Base
return 0
end
end
def advanceInBracket
@advance = Pooladvance.new
@advance.wrestler = self
@advance.advanceWrestler
end
end

View File

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

View File

@@ -0,0 +1,53 @@
require 'test_helper'
class PoolAdvancementTest < ActionDispatch::IntegrationTest
test "the truth" do
assert true
end
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")
end
def endMatch(bout,winner)
@match = @matches.select{|m| m.bout_number == bout}.first
@match.finished = 1
@match.winner_id = translateNameToId(winner)
@match.win_type = "Decision"
@match.save
end
def translateNameToId(wrestler)
Wrestler.where("name = ?", wrestler).first.id
end
test "nine man outright finals advance" do
@wrestler = Wrestler.where("name = ?", "Guy2").first
assert_equal 6000, @wrestler.boutByRound(6)
end
test "nine man outright conso finals advance" do
@wrestler = Wrestler.where("name = ?", "Guy8").first
assert_equal 6001, @wrestler.boutByRound(6)
end
end

View File

@@ -75,7 +75,7 @@ class PoolbracketMatchupsTest < ActionDispatch::IntegrationTest
round = 1
if w.totalRounds(matchups) > 5
until round > w.poolRounds(matchups) do
if wr.boutByRound(round, matchups) == "BYE"
if wr.boutByRound(round) == "BYE"
message = "BYE"
end
round += 1