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

Still moving logic out of the models

This commit is contained in:
2016-05-26 01:04:51 +00:00
parent 44464722a3
commit 4f15c2b8a3
7 changed files with 90 additions and 46 deletions

View File

@@ -32,9 +32,7 @@ class Match < ActiveRecord::Base
wrestler2.school.calcScore
end
end
if Rails.env.production?
handle_asynchronously :calcSchoolPoints
end
def mat_assigned
if self.mat
@@ -57,15 +55,11 @@ class Match < ActiveRecord::Base
def advance_wrestlers
if self.w1 && self.w2
@w1 = wrestler1
@w2 = wrestler2
@w1.advanceInBracket(self)
@w2.advanceInBracket(self)
AdvanceWrestler.new(wrestler1).advance
AdvanceWrestler.new(wrestler2).advance
end
end
if Rails.env.production?
handle_asynchronously :advance_wrestlers
end
def bracketScore
if self.finished != 1

View File

@@ -24,6 +24,9 @@ class School < ActiveRecord::Base
self.score = newScore
self.save
end
if Rails.env.production?
handle_asynchronously :calcScore
end
def totalWrestlerPoints
points = 0

View File

@@ -14,15 +14,11 @@ class Teampointadjust < ActiveRecord::Base
#Team score needs calculated
if self.wrestler_id != nil
#In case this affects pool order
if self.wrestler.lastFinishedMatch
self.wrestler.lastFinishedMatch.advance_wrestlers
end
AdvanceWrestler.new(self.wrestler).advance
self.wrestler.school.calcScore
elsif self.school_id != nil
self.school.calcScore
end
end
if Rails.env.production?
handle_asynchronously :advance_wrestlers_and_calc_team_score
end
end

View File

@@ -22,28 +22,19 @@ class Wrestler < ActiveRecord::Base
end
def totalTeamPoints
if self.extra
return 0
else
teamPointsEarned - totalDeductedPoints
end
CalculateWrestlerTeamScore.new(self).totalScore
end
def teamPointsEarned
points = 0.0
points = points + (poolWins.size * 2) + (championshipAdvancementWins.size * 2) + (consoAdvancementWins.size * 1) + (pinWins.size * 2) + (techWins.size * 1.5) + (majorWins.size * 1) + placementPoints
CalculateWrestlerTeamScore.new(self).earnedPoints
end
def placementPoints
PoolBracketPlacementPoints.new(self).calcPoints
CalculateWrestlerTeamScore.new(self).placementPoints
end
def totalDeductedPoints
points = 0
self.deductedPoints.each do |d|
points = points + d.points
end
points
CalculateWrestlerTeamScore.new(self).deductedPoints
end
def nextMatch
@@ -88,15 +79,15 @@ class Wrestler < ActiveRecord::Base
end
def resultByBout(bout)
@match = allMatches.select{|m| m.bout_number == bout and m.finished == 1}
if @match.size == 0
bout_match = allMatches.select{|m| m.bout_number == bout and m.finished == 1}
if bout_match.size == 0
return ""
end
if @match.first.winner_id == self.id
return "W #{@match.first.bracketScore}"
if bout_match.first.winner_id == self.id
return "W #{bout_match.first.bracketScore}"
end
if @match.first.winner_id != self.id
return "L #{@match.first.bracketScore}"
if bout_match.first.winner_id != self.id
return "L #{bout_match.first.bracketScore}"
end
end
@@ -113,26 +104,25 @@ class Wrestler < ActiveRecord::Base
end
def generatePoolNumber
@pool = self.weight.returnPoolNumber(self)
self.weight.returnPoolNumber(self)
end
def boutByRound(round)
@match = allMatches.select{|m| m.round == round}.first
if @match.blank?
round_match = allMatches.select{|m| m.round == round}.first
if round_match.blank?
return "BYE"
else
return @match.bout_number
return round_match.bout_number
end
end
def allMatches
@matches = matches.select{|m| m.w1 == self.id or m.w2 == self.id}
return @matches
return matches.select{|m| m.w1 == self.id or m.w2 == self.id}
end
def poolMatches
@poolMatches = allMatches.select{|m| m.bracket_position == "Pool"}
@poolMatches.select{|m| m.poolNumber == self.generatePoolNumber}
pool_matches = allMatches.select{|m| m.bracket_position == "Pool"}
pool_matches.select{|m| m.poolNumber == self.generatePoolNumber}
end
def championshipAdvancementWins
@@ -213,7 +203,4 @@ class Wrestler < ActiveRecord::Base
end
end
def advanceInBracket(match)
PoolAdvance.new(self,match).advanceWrestler
end
end

View 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

View File

@@ -9,6 +9,9 @@ class GenerateTournamentMatches
postMatchCreationActions
PoolToBracketMatchGeneration.new(@tournament).assignLoserNames if @tournament.tournament_type == "Pool to bracket"
end
if Rails.env.production?
handle_asynchronously :generate
end
def standardStartingActions
@tournament.curently_generating_matches = 1

View File

@@ -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