mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-04-14 08:58:29 +00:00
Still moving logic out of the models
This commit is contained in:
@@ -32,9 +32,7 @@ class Match < ActiveRecord::Base
|
|||||||
wrestler2.school.calcScore
|
wrestler2.school.calcScore
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if Rails.env.production?
|
|
||||||
handle_asynchronously :calcSchoolPoints
|
|
||||||
end
|
|
||||||
|
|
||||||
def mat_assigned
|
def mat_assigned
|
||||||
if self.mat
|
if self.mat
|
||||||
@@ -57,15 +55,11 @@ class Match < ActiveRecord::Base
|
|||||||
|
|
||||||
def advance_wrestlers
|
def advance_wrestlers
|
||||||
if self.w1 && self.w2
|
if self.w1 && self.w2
|
||||||
@w1 = wrestler1
|
AdvanceWrestler.new(wrestler1).advance
|
||||||
@w2 = wrestler2
|
AdvanceWrestler.new(wrestler2).advance
|
||||||
@w1.advanceInBracket(self)
|
|
||||||
@w2.advanceInBracket(self)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if Rails.env.production?
|
|
||||||
handle_asynchronously :advance_wrestlers
|
|
||||||
end
|
|
||||||
|
|
||||||
def bracketScore
|
def bracketScore
|
||||||
if self.finished != 1
|
if self.finished != 1
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ class School < ActiveRecord::Base
|
|||||||
self.score = newScore
|
self.score = newScore
|
||||||
self.save
|
self.save
|
||||||
end
|
end
|
||||||
|
if Rails.env.production?
|
||||||
|
handle_asynchronously :calcScore
|
||||||
|
end
|
||||||
|
|
||||||
def totalWrestlerPoints
|
def totalWrestlerPoints
|
||||||
points = 0
|
points = 0
|
||||||
|
|||||||
@@ -14,15 +14,11 @@ class Teampointadjust < ActiveRecord::Base
|
|||||||
#Team score needs calculated
|
#Team score needs calculated
|
||||||
if self.wrestler_id != nil
|
if self.wrestler_id != nil
|
||||||
#In case this affects pool order
|
#In case this affects pool order
|
||||||
if self.wrestler.lastFinishedMatch
|
AdvanceWrestler.new(self.wrestler).advance
|
||||||
self.wrestler.lastFinishedMatch.advance_wrestlers
|
|
||||||
end
|
|
||||||
self.wrestler.school.calcScore
|
self.wrestler.school.calcScore
|
||||||
elsif self.school_id != nil
|
elsif self.school_id != nil
|
||||||
self.school.calcScore
|
self.school.calcScore
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if Rails.env.production?
|
|
||||||
handle_asynchronously :advance_wrestlers_and_calc_team_score
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -22,28 +22,19 @@ class Wrestler < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def totalTeamPoints
|
def totalTeamPoints
|
||||||
if self.extra
|
CalculateWrestlerTeamScore.new(self).totalScore
|
||||||
return 0
|
|
||||||
else
|
|
||||||
teamPointsEarned - totalDeductedPoints
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def teamPointsEarned
|
def teamPointsEarned
|
||||||
points = 0.0
|
CalculateWrestlerTeamScore.new(self).earnedPoints
|
||||||
points = points + (poolWins.size * 2) + (championshipAdvancementWins.size * 2) + (consoAdvancementWins.size * 1) + (pinWins.size * 2) + (techWins.size * 1.5) + (majorWins.size * 1) + placementPoints
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def placementPoints
|
def placementPoints
|
||||||
PoolBracketPlacementPoints.new(self).calcPoints
|
CalculateWrestlerTeamScore.new(self).placementPoints
|
||||||
end
|
end
|
||||||
|
|
||||||
def totalDeductedPoints
|
def totalDeductedPoints
|
||||||
points = 0
|
CalculateWrestlerTeamScore.new(self).deductedPoints
|
||||||
self.deductedPoints.each do |d|
|
|
||||||
points = points + d.points
|
|
||||||
end
|
|
||||||
points
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def nextMatch
|
def nextMatch
|
||||||
@@ -88,15 +79,15 @@ class Wrestler < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def resultByBout(bout)
|
def resultByBout(bout)
|
||||||
@match = allMatches.select{|m| m.bout_number == bout and m.finished == 1}
|
bout_match = allMatches.select{|m| m.bout_number == bout and m.finished == 1}
|
||||||
if @match.size == 0
|
if bout_match.size == 0
|
||||||
return ""
|
return ""
|
||||||
end
|
end
|
||||||
if @match.first.winner_id == self.id
|
if bout_match.first.winner_id == self.id
|
||||||
return "W #{@match.first.bracketScore}"
|
return "W #{bout_match.first.bracketScore}"
|
||||||
end
|
end
|
||||||
if @match.first.winner_id != self.id
|
if bout_match.first.winner_id != self.id
|
||||||
return "L #{@match.first.bracketScore}"
|
return "L #{bout_match.first.bracketScore}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -113,26 +104,25 @@ class Wrestler < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def generatePoolNumber
|
def generatePoolNumber
|
||||||
@pool = self.weight.returnPoolNumber(self)
|
self.weight.returnPoolNumber(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
def boutByRound(round)
|
def boutByRound(round)
|
||||||
@match = allMatches.select{|m| m.round == round}.first
|
round_match = allMatches.select{|m| m.round == round}.first
|
||||||
if @match.blank?
|
if round_match.blank?
|
||||||
return "BYE"
|
return "BYE"
|
||||||
else
|
else
|
||||||
return @match.bout_number
|
return round_match.bout_number
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def allMatches
|
def allMatches
|
||||||
@matches = matches.select{|m| m.w1 == self.id or m.w2 == self.id}
|
return matches.select{|m| m.w1 == self.id or m.w2 == self.id}
|
||||||
return @matches
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def poolMatches
|
def poolMatches
|
||||||
@poolMatches = allMatches.select{|m| m.bracket_position == "Pool"}
|
pool_matches = allMatches.select{|m| m.bracket_position == "Pool"}
|
||||||
@poolMatches.select{|m| m.poolNumber == self.generatePoolNumber}
|
pool_matches.select{|m| m.poolNumber == self.generatePoolNumber}
|
||||||
end
|
end
|
||||||
|
|
||||||
def championshipAdvancementWins
|
def championshipAdvancementWins
|
||||||
@@ -213,7 +203,4 @@ class Wrestler < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def advanceInBracket(match)
|
|
||||||
PoolAdvance.new(self,match).advanceWrestler
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
14
app/services/bracket_advancement/advance_wrestler.rb
Normal file
14
app/services/bracket_advancement/advance_wrestler.rb
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
class AdvanceWrestler
|
||||||
|
def initialize( wrestler )
|
||||||
|
@wrestler = wrestler
|
||||||
|
@tournament = @wrestler.tournament
|
||||||
|
end
|
||||||
|
|
||||||
|
def advance
|
||||||
|
PoolAdvance.new(@wrestler,@wrestler.lastMatch).advanceWrestler if @tournament.tournament_type == "Pool to bracket"
|
||||||
|
end
|
||||||
|
if Rails.env.production?
|
||||||
|
handle_asynchronously :advance
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
@@ -9,6 +9,9 @@ class GenerateTournamentMatches
|
|||||||
postMatchCreationActions
|
postMatchCreationActions
|
||||||
PoolToBracketMatchGeneration.new(@tournament).assignLoserNames if @tournament.tournament_type == "Pool to bracket"
|
PoolToBracketMatchGeneration.new(@tournament).assignLoserNames if @tournament.tournament_type == "Pool to bracket"
|
||||||
end
|
end
|
||||||
|
if Rails.env.production?
|
||||||
|
handle_asynchronously :generate
|
||||||
|
end
|
||||||
|
|
||||||
def standardStartingActions
|
def standardStartingActions
|
||||||
@tournament.curently_generating_matches = 1
|
@tournament.curently_generating_matches = 1
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
class CalculateWrestlerTeamScore
|
||||||
|
def initialize( wrestler )
|
||||||
|
@wrestler = wrestler
|
||||||
|
@tournament = @wrestler.tournament
|
||||||
|
end
|
||||||
|
|
||||||
|
def totalScore
|
||||||
|
if @wrestler.extra
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
earnedPoints - deductedPoints
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def earnedPoints
|
||||||
|
return poolPoints + bracketPoints + placementPoints + bonusWinPoints
|
||||||
|
end
|
||||||
|
|
||||||
|
def deductedPoints
|
||||||
|
points = 0
|
||||||
|
@wrestler.deductedPoints.each do |d|
|
||||||
|
points = points + d.points
|
||||||
|
end
|
||||||
|
points
|
||||||
|
end
|
||||||
|
|
||||||
|
def placementPoints
|
||||||
|
PoolBracketPlacementPoints.new(@wrestler).calcPoints if @tournament.tournament_type == "Pool to bracket"
|
||||||
|
end
|
||||||
|
|
||||||
|
def bracketPoints
|
||||||
|
(@wrestler.championshipAdvancementWins.size * 2) + (@wrestler.consoAdvancementWins.size * 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
def poolPoints
|
||||||
|
if @tournament.tournament_type == "Pool to bracket"
|
||||||
|
(@wrestler.poolWins.size * 2)
|
||||||
|
else
|
||||||
|
0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def bonusWinPoints
|
||||||
|
(@wrestler.pinWins.size * 2) + (@wrestler.techWins.size * 1.5) + (@wrestler.majorWins.size * 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user