mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-04-06 14:36:59 +00:00
Still moving logic out of the models
This commit is contained in:
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
|
||||
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
|
||||
|
||||
@@ -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