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

Tie breaker for team score

This commit is contained in:
2015-11-16 16:59:08 +00:00
parent 6436551f34
commit 328898f1e8
4 changed files with 83 additions and 49 deletions

View File

@@ -45,6 +45,7 @@ class Poolorder
ifWrestlersWithSamePointsIsSameAsOriginal(originalTieSize) { headToHead }
end
ifWrestlersWithSamePointsIsSameAsOriginal(originalTieSize) { deductedPoints }
ifWrestlersWithSamePointsIsSameAsOriginal(originalTieSize) { teamPoints }
ifWrestlersWithSamePointsIsSameAsOriginal(originalTieSize) { coinFlip }
end
@@ -83,6 +84,19 @@ class Poolorder
end
end
def teamPoints
pointsArray = []
wrestlersWithSamePoints.each do |w|
pointsArray << w.totalTeamPoints
end
mostPoints = pointsArray.max
wrestlersWithLeastDeductedPoints = wrestlersWithSamePoints.select{|w| w.totalTeamPoints == mostPoints}
addPointsToWrestlersAhead(wrestlersWithLeastDeductedPoints.first)
wrestlersWithLeastDeductedPoints.each do |wr|
addPoints(wr)
end
end
def coinFlip
wrestler = wrestlersWithSamePoints.sample
addPointsToWrestlersAhead(wrestler)

View File

@@ -6,14 +6,21 @@ class School < ActiveRecord::Base
#calculate score here
def score
#Add score per wrestler. Calculate score in wrestler model.
return 0
calcScore
end
def calcScore
#calc and save score
totalWrestlerPoints - totalDeductedPoints
end
def totalWrestlerPoints
points = 0
self.wrestlers.each do |w|
points = points + w.totalTeamPoints
end
points
end
def totalDeductedPoints
points = 0
self.deductedPoints.each do |d|
@@ -21,48 +28,4 @@ class School < ActiveRecord::Base
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

@@ -14,6 +14,11 @@ class Wrestler < ActiveRecord::Base
allMatches.select{|m| m.finished == 1}.sort_by{|m| m.bout_number}.last
end
def totalTeamPoints
points = 0.0
points = points + (poolWins.size * 1) + (pinWins.size * 2) + (techWins.size * 1.5) + (majorWins.size * 1)
end
def totalDeductedPoints
points = 0
self.deductedPoints.each do |d|
@@ -81,9 +86,27 @@ class Wrestler < ActiveRecord::Base
def finishedPoolMatches
finishedMatches.select{|m| m.bracket_position == "Pool"}
end
def poolWins
allMatches.select{|m| m.winner_id == self.id && m.bracket_position == "Pool"}
def matchesWon
allMatches.select{|m| m.winner_id == self.id}
end
def poolWins
matchesWon.select{|m| m.bracket_position == "Pool"}
end
def pinWins
matchesWon.select{|m| m.win_type == "Pin" || m.win_type == "Forfeit" || m.win_type == "Injury Default" || m.win_type == "Default" || m.win_type == "DQ"}
end
def techWins
matchesWon.select{|m| m.win_type == "Tech Fall" }
end
def majorWins
matchesWon.select{|m| m.win_type == "Major" }
end
def seasonWinPercentage
@win = self.season_win.to_f
@loss = self.season_loss.to_f

View File

@@ -67,6 +67,16 @@ class PoolAdvancementTest < ActionDispatch::IntegrationTest
deduct.save
end
def nineManBracketPoolTwoGuyThreeTeamPoints
matches = @tournament.matches.select{|m| m.weight_id == 3 && m.bracket_position == "Pool"}
endMatch(1004,"Guy9",matches)
endMatch(1005,"Guy7",matches)
endMatchWithMajor(2004,"Guy3",matches)
endMatch(2005,"Guy9",matches)
endMatch(3004,"Guy7",matches)
endMatch(3005,"Guy3",matches)
end
def endMatch(bout,winner,matches)
match = matches.select{|m| m.bout_number == bout}.first
match.finished = 1
@@ -77,6 +87,18 @@ class PoolAdvancementTest < ActionDispatch::IntegrationTest
match.mat_id = mat.id
match.save
end
def endMatchWithMajor(bout,winner,matches)
match = matches.select{|m| m.bout_number == bout}.first
match.finished = 1
match.winner_id = translateNameToId(winner)
match.win_type = "Major"
#Need to manually assign mat_id because thise weight class is not currently assigned a mat
mat = @tournament.mats.first
match.mat_id = mat.id
match.save
end
def translateNameToId(wrestler)
Wrestler.where("name = ?", wrestler).first.id
end
@@ -128,4 +150,16 @@ class PoolAdvancementTest < ActionDispatch::IntegrationTest
wrestler = Wrestler.where("name = ?", "Guy9").first
assert_equal 6001, wrestler.boutByRound(6)
end
test "nine man pool 2 teamPoints tie breaker finalist guy 3" do
wrestler = Wrestler.where("name = ?", "Guy3").first
nineManBracketPoolTwoGuyThreeTeamPoints
assert_equal 6000, wrestler.boutByRound(6)
end
test "nine man conso finals teamPoints tie breaker guy 9" do
nineManBracketPoolTwoGuyThreeTeamPoints
wrestler = Wrestler.where("name = ?", "Guy9").first
assert_equal 6001, wrestler.boutByRound(6)
end
end