1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-04-03 05:27:25 +00:00

Deducted points pool tie breaker added

This commit is contained in:
2015-11-16 13:31:27 +00:00
parent 34a04be4bf
commit 934ccc28ee
9 changed files with 199 additions and 26 deletions

View File

@@ -2,11 +2,10 @@ class Poolorder
def initialize(wrestlers)
@wrestlers = wrestlers
end
attr_accessor :wrestlersWithSamePoints
def getPoolOrder
setOriginalPoints
until checkForTieBreakers == false
while checkForTieBreakers == true
breakTie
end
@wrestlers.sort_by{|w| w.poolAdvancePoints}.reverse!
@@ -19,28 +18,67 @@ class Poolorder
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
if wrestlersWithSamePoints.size > 1
return true
end
return false
end
def wrestlersWithSamePoints
@wrestlers.each do |w|
wrestlersWithSamePoints = @wrestlers.select{|wr| wr.poolAdvancePoints == w.poolAdvancePoints}
if wrestlersWithSamePoints.size > 0
return wrestlersWithSamePoints
end
end
end
def ifWrestlersWithSamePointsIsSameAsOriginal(originalTieSize)
if wrestlersWithSamePoints.size == originalTieSize
yield
end
end
def breakTie
headToHead
originalTieSize = wrestlersWithSamePoints.size
if originalTieSize == 2
ifWrestlersWithSamePointsIsSameAsOriginal(originalTieSize) { headToHead }
end
ifWrestlersWithSamePointsIsSameAsOriginal(originalTieSize) { deductedPoints }
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
wrestlersWithSamePoints.each do |wr|
otherWrestler = wrestlersWithSamePoints.select{|w| w.id != wr.id}.first
if wr.matchAgainst(otherWrestler).first.winner_id == wr.id
addPointsToWrestlersAhead(wr)
addPoints(wr)
end
end
end
def addPoints(wrestler)
wrestler.poolAdvancePoints = wrestler.poolAdvancePoints + 1
end
def addPointsToWrestlersAhead(wrestler)
wrestlersAhead = @wrestlers.select{|w| w.poolAdvancePoints > wrestler.poolAdvancePoints}
wrestlersAhead.each do |wr|
wr.poolAdvancePoints = wr.poolAdvancePoints + 1
end
end
def deductedPoints
pointsArray = []
wrestlersWithSamePoints.each do |w|
pointsArray << w.totalDeductedPoints
end
leastPoints = pointsArray.min
wrestlersWithLeastDeductedPoints = wrestlersWithSamePoints.select{|w| w.totalDeductedPoints == leastPoints}
addPointsToWrestlersAhead(wrestlersWithLeastDeductedPoints.first)
wrestlersWithLeastDeductedPoints.each do |wr|
addPoints(wr)
end
end
end

View File

@@ -1,6 +1,7 @@
class School < ActiveRecord::Base
belongs_to :tournament
has_many :wrestlers, dependent: :destroy
has_many :deductedPoints, through: :wrestlers
#calculate score here
@@ -8,4 +9,60 @@ class School < ActiveRecord::Base
#Add score per wrestler. Calculate score in wrestler model.
return 0
end
def calcScore
#calc and save score
end
def totalDeductedPoints
points = 0
self.deductedPoints.each do |d|
points = points + d.points
end
points
end
def poolWins
end
def pinDefaultDqWins
end
def techFallWins
end
def majorWins
end
def firstPlace
end
def secondPlace
end
def thirdPlace
end
def fourthPlace
end
def fifthPlace
end
def sixthPlace
end
def seventhPlace
end
end

View File

@@ -0,0 +1,3 @@
class Teampointadjust < ActiveRecord::Base
belongs_to :wrestler
end

View File

@@ -3,14 +3,23 @@ class Wrestler < ActiveRecord::Base
belongs_to :weight
has_one :tournament, through: :weight
has_many :matches, through: :weight
has_many :deductedPoints, class_name: "Teampointadjust"
attr_accessor :poolNumber, :poolAdvancePoints
before_save do
self.tournament.destroyAllMatches
end
def totalDeductedPoints
points = 0
self.deductedPoints.each do |d|
points = points + d.points
end
points
end
def resultByBout(bout)
@match = Match.where("bout_number = ? AND finished = ?",bout,1)
@match = allMatches.select{|m| m.bout_number == bout and m.finished == 1}
if @match.size == 0
return ""
end