mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-04-17 13:24:36 +00:00
Added head to head pool winner and tests
This commit is contained in:
46
app/models/poolorder.rb
Normal file
46
app/models/poolorder.rb
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
class Poolorder
|
||||||
|
def initialize(wrestlers)
|
||||||
|
@wrestlers = wrestlers
|
||||||
|
end
|
||||||
|
attr_accessor :wrestlersWithSamePoints
|
||||||
|
|
||||||
|
def getPoolOrder
|
||||||
|
setOriginalPoints
|
||||||
|
until checkForTieBreakers == false
|
||||||
|
breakTie
|
||||||
|
end
|
||||||
|
@wrestlers.sort_by{|w| w.poolAdvancePoints}.reverse!
|
||||||
|
end
|
||||||
|
|
||||||
|
def setOriginalPoints
|
||||||
|
@wrestlers.each do |w|
|
||||||
|
w.poolAdvancePoints = w.poolWins.size
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def checkForTieBreakers
|
||||||
|
@wrestlers.each do |w|
|
||||||
|
self.wrestlersWithSamePoints = @wrestlers.select{|wr| wr.poolAdvancePoints == w.poolAdvancePoints}
|
||||||
|
if self.wrestlersWithSamePoints.size > 1
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
def breakTie
|
||||||
|
headToHead
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def headToHead
|
||||||
|
self.wrestlersWithSamePoints.each do |wr|
|
||||||
|
@otherWrestlers = self.wrestlersWithSamePoints.select{|w| w.id != wr.id}
|
||||||
|
@otherWrestlers.each do |ow|
|
||||||
|
if wr.matchAgainst(ow).first.winner_id == wr.id
|
||||||
|
wr.poolAdvancePoints = wr.poolAdvancePoints + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -139,7 +139,6 @@ class Weight < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def poolOrder(pool)
|
def poolOrder(pool)
|
||||||
@wrestlers = wrestlersForPool(pool)
|
Poolorder.new(wrestlersForPool(pool)).getPoolOrder
|
||||||
@wrestlers.sort_by{|w| w.poolWins.size}.reverse!
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ class Wrestler < ActiveRecord::Base
|
|||||||
belongs_to :weight
|
belongs_to :weight
|
||||||
has_one :tournament, through: :weight
|
has_one :tournament, through: :weight
|
||||||
has_many :matches, through: :weight
|
has_many :matches, through: :weight
|
||||||
attr_accessor :poolNumber
|
attr_accessor :poolNumber, :poolAdvancePoints
|
||||||
|
|
||||||
before_save do
|
before_save do
|
||||||
self.tournament.destroyAllMatches
|
self.tournament.destroyAllMatches
|
||||||
@@ -22,6 +22,9 @@ class Wrestler < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def matchAgainst(opponent)
|
||||||
|
allMatches.select{|m| m.w1 == opponent.id or m.w2 == opponent.id}
|
||||||
|
end
|
||||||
|
|
||||||
def isWrestlingThisRound(matchRound)
|
def isWrestlingThisRound(matchRound)
|
||||||
if allMatches.blank?
|
if allMatches.blank?
|
||||||
|
|||||||
@@ -5,10 +5,16 @@ class PoolAdvancementTest < ActionDispatch::IntegrationTest
|
|||||||
def setup
|
def setup
|
||||||
@tournament = Tournament.find(1)
|
@tournament = Tournament.find(1)
|
||||||
@tournament.generateMatchups
|
@tournament.generateMatchups
|
||||||
nineManBracketPoolOne
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def nineManBracketPoolOne
|
def showNineManWeightThreePoolTwoMatches
|
||||||
|
@matches = @tournament.matches.select{|m| m.weight_id == 3 && m.bracket_position == "Pool" && m.poolNumber == 2}
|
||||||
|
@matches.each do |m|
|
||||||
|
puts "Bout: #{m.bout_number} #{m.w1_name} vs #{m.w2_name} Pool: #{m.poolNumber}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def nineManBracketPoolOneOutrightWinner
|
||||||
@matches = @tournament.matches.select{|m| m.weight_id == 3 && m.bracket_position == "Pool"}
|
@matches = @tournament.matches.select{|m| m.weight_id == 3 && m.bracket_position == "Pool"}
|
||||||
endMatch(1002,"Guy8",@matches)
|
endMatch(1002,"Guy8",@matches)
|
||||||
endMatch(1003,"Guy10",@matches)
|
endMatch(1003,"Guy10",@matches)
|
||||||
@@ -22,6 +28,26 @@ class PoolAdvancementTest < ActionDispatch::IntegrationTest
|
|||||||
endMatch(3002,"Guy5",@matches)
|
endMatch(3002,"Guy5",@matches)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def nineManBracketPoolTwoGuyNineHeadToHead
|
||||||
|
@matches = @tournament.matches.select{|m| m.weight_id == 3 && m.bracket_position == "Pool"}
|
||||||
|
endMatch(1004,"Guy4",@matches)
|
||||||
|
endMatch(1005,"Guy3",@matches)
|
||||||
|
endMatch(2004,"Guy3",@matches)
|
||||||
|
endMatch(2005,"Guy9",@matches)
|
||||||
|
endMatch(3004,"Guy7",@matches)
|
||||||
|
endMatch(3005,"Guy9",@matches)
|
||||||
|
end
|
||||||
|
|
||||||
|
def nineManBracketPoolTwoGuyThreeHeadToHead
|
||||||
|
@matches = @tournament.matches.select{|m| m.weight_id == 3 && m.bracket_position == "Pool"}
|
||||||
|
endMatch(1004,"Guy9",@matches)
|
||||||
|
endMatch(1005,"Guy3",@matches)
|
||||||
|
endMatch(2004,"Guy4",@matches)
|
||||||
|
endMatch(2005,"Guy9",@matches)
|
||||||
|
endMatch(3004,"Guy7",@matches)
|
||||||
|
endMatch(3005,"Guy3",@matches)
|
||||||
|
end
|
||||||
|
|
||||||
def endMatch(bout,winner,matches)
|
def endMatch(bout,winner,matches)
|
||||||
@match = matches.select{|m| m.bout_number == bout}.first
|
@match = matches.select{|m| m.bout_number == bout}.first
|
||||||
@match.finished = 1
|
@match.finished = 1
|
||||||
@@ -37,15 +63,42 @@ class PoolAdvancementTest < ActionDispatch::IntegrationTest
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "nine man outright finals advance" do
|
test "nine man outright finals advance" do
|
||||||
|
nineManBracketPoolOneOutrightWinner
|
||||||
@wrestler = Wrestler.where("name = ?", "Guy2").first
|
@wrestler = Wrestler.where("name = ?", "Guy2").first
|
||||||
@match = Match.where("bout_number = ?",6000).first
|
@match = Match.where("bout_number = ?",6000).first
|
||||||
assert_equal 6000, @wrestler.boutByRound(6)
|
assert_equal 6000, @wrestler.boutByRound(6)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "nine man outright conso finals advance" do
|
test "nine man outright conso finals advance" do
|
||||||
|
nineManBracketPoolOneOutrightWinner
|
||||||
@wrestler = Wrestler.where("name = ?", "Guy8").first
|
@wrestler = Wrestler.where("name = ?", "Guy8").first
|
||||||
assert_equal 6001, @wrestler.boutByRound(6)
|
assert_equal 6001, @wrestler.boutByRound(6)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "nine man pool 2 man to man tie breaker finalist guy 9" do
|
||||||
|
@wrestler = Wrestler.where("name = ?", "Guy9").first
|
||||||
|
nineManBracketPoolTwoGuyNineHeadToHead
|
||||||
|
@match = Match.where("bout_number = ?",6000).first
|
||||||
|
assert_equal 6000, @wrestler.boutByRound(6)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "nine man pool 2 man to man tie breaker finalist guy 3" do
|
||||||
|
@wrestler = Wrestler.where("name = ?", "Guy3").first
|
||||||
|
nineManBracketPoolTwoGuyThreeHeadToHead
|
||||||
|
@match = Match.where("bout_number = ?",6000).first
|
||||||
|
assert_equal 6000, @wrestler.boutByRound(6)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "nine man outright conso finals man to man tie breaker guy 3" do
|
||||||
|
nineManBracketPoolTwoGuyNineHeadToHead
|
||||||
|
@wrestler = Wrestler.where("name = ?", "Guy3").first
|
||||||
|
assert_equal 6001, @wrestler.boutByRound(6)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "nine man outright conso finals man to man tie breaker guy 9" do
|
||||||
|
nineManBracketPoolTwoGuyThreeHeadToHead
|
||||||
|
@wrestler = Wrestler.where("name = ?", "Guy9").first
|
||||||
|
assert_equal 6001, @wrestler.boutByRound(6)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user