1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-04-04 05:43:47 +00:00

Refactored names of methods and some db column

This commit is contained in:
2018-11-13 14:14:48 +00:00
parent 93be525832
commit d67a8f2b42
44 changed files with 350 additions and 350 deletions

View File

@@ -6,21 +6,21 @@ class Mat < ActiveRecord::Base
before_destroy do
if tournament.matches.size > 0
tournament.resetMats
tournament.reset_mats
matsToAssign = tournament.mats.select{|m| m.id != self.id}
tournament.assignMats(matsToAssign)
tournament.assign_mats(matsToAssign)
end
end
after_create do
if tournament.matches.size > 0
tournament.resetMats
tournament.reset_mats
matsToAssign = tournament.mats
tournament.assignMats(matsToAssign)
tournament.assign_mats(matsToAssign)
end
end
def assignNextMatch
def assign_next_match
t_matches = tournament.matches.select{|m| m.mat_id == nil && m.finished != 1 && m.bout_number != nil}
if t_matches.size > 0
match = t_matches.sort_by{|m| m.bout_number}.first
@@ -29,7 +29,7 @@ class Mat < ActiveRecord::Base
end
end
def unfinishedMatches
def unfinished_matches
matches.select{|m| m.finished != 1}.sort_by{|m| m.bout_number}
end

View File

@@ -13,19 +13,19 @@ class Match < ActiveRecord::Base
wrestler2.touch
end
if self.mat
self.mat.assignNextMatch
self.mat.assign_next_match
end
advance_wrestlers
calcSchoolPoints
calculate_school_points
end
end
WIN_TYPES = ["Decision", "Major", "Tech Fall", "Pin", "Forfeit", "Injury Default", "Default", "DQ"]
def calcSchoolPoints
def calculate_school_points
if self.w1 && self.w2
wrestler1.school.calcScore
wrestler2.school.calcScore
wrestler1.school.calculate_score
wrestler2.school.calculate_score
end
end
@@ -38,12 +38,12 @@ class Match < ActiveRecord::Base
end
end
def pinTime
def pin_time_in_seconds
if self.win_type == "Pin"
time = self.score.delete("")
minInSeconds = time.partition(':').first.to_i * 60
minutes_in_seconds = time.partition(':').first.to_i * 60
sec = time.partition(':').last.to_i
return minInSeconds + sec
return minutes_in_seconds + sec
else
nil
end
@@ -57,7 +57,7 @@ class Match < ActiveRecord::Base
end
def bracketScore
def bracket_score_string
if self.finished != 1
return ""
end
@@ -99,7 +99,7 @@ class Match < ActiveRecord::Base
self.loser2_name
end
end
def winnerName
def winner_name
if self.finished != 1
return ""
end
@@ -114,17 +114,17 @@ class Match < ActiveRecord::Base
self.weight.max
end
def replaceLoserNameWithWrestler(w,loserName)
if self.loser1_name == loserName
def replace_loser_name_with_wrestler(w,loser_name)
if self.loser1_name == loser_name
self.w1 = w.id
self.save
end
if self.loser2_name == loserName
if self.loser2_name == loser_name
self.w2 = w.id
self.save
end
end
def poolNumber
def pool_number
if self.w1?
wrestler1.pool
end

View File

@@ -7,11 +7,11 @@ class School < ActiveRecord::Base
validates :name, presence: true
before_destroy do
self.tournament.destroyAllMatches
self.tournament.destroy_all_matches
end
#calculate score here
def pageScore
def page_score_string
if self.score == nil
return 0.0
else
@@ -19,26 +19,26 @@ class School < ActiveRecord::Base
end
end
def calcScore
newScore = totalWrestlerPoints - totalDeductedPoints
def calculate_score
newScore = total_points_scored_by_wrestlers - total_points_deducted
self.score = newScore
self.save
end
if Rails.env.production?
handle_asynchronously :calcScore
handle_asynchronously :calculate_score
end
def totalWrestlerPoints
def total_points_scored_by_wrestlers
points = 0
self.wrestlers.each do |w|
if w.extra != true
points = points + w.totalTeamPoints
points = points + w.total_team_points
end
end
points
end
def totalDeductedPoints
def total_points_deducted
points = 0
deductedPoints.each do |d|
points = points + d.points

View File

@@ -15,9 +15,9 @@ class Teampointadjust < ActiveRecord::Base
if self.wrestler_id != nil
#In case this affects pool order
AdvanceWrestler.new(self.wrestler).advance
self.wrestler.school.calcScore
self.wrestler.school.calculate_score
elsif self.school_id != nil
self.school.calcScore
self.school.calculate_score
end
end

View File

@@ -14,7 +14,7 @@ class Tournament < ActiveRecord::Base
where("date LIKE ? or name LIKE ?", "%#{search}%", "%#{search}%")
end
def daysUntil
def days_until_start
time = (Date.today - self.date).to_i
if time < 0
time = time * -1
@@ -26,7 +26,7 @@ class Tournament < ActiveRecord::Base
["Pool to bracket"]
end
def createCustomWeights(value)
def create_pre_defined_weights(value)
weights.destroy_all
if value == 'hs'
Weight::HS_WEIGHT_CLASSES.each do |w|
@@ -37,32 +37,32 @@ class Tournament < ActiveRecord::Base
end
end
def destroyAllMatches
def destroy_all_matches
matches.destroy_all
end
def matchesByRound(round)
def matches_by_round(round)
matches.joins(:weight).where(round: round).order("weights.max")
end
def totalRounds
def total_rounds
self.matches.sort_by{|m| m.round}.last.round
end
def assignMats(matsToAssign)
if matsToAssign.count > 0
until matsToAssign.sort_by{|m| m.id}.last.matches.count == 4
matsToAssign.sort_by{|m| m.id}.each do |m|
m.assignNextMatch
def assign_mats(mats_to_assign)
if mats_to_assign.count > 0
until mats_to_assign.sort_by{|m| m.id}.last.matches.count == 4
mats_to_assign.sort_by{|m| m.id}.each do |m|
m.assign_next_match
end
end
end
end
def resetMats
matchesToReset = matches.select{|m| m.mat_id != nil}
# matchesToReset.update_all( {:mat_id => nil } )
matchesToReset.each do |m|
def reset_mats
matches_to_reset = matches.select{|m| m.mat_id != nil}
# matches_to_reset.update_all( {:mat_id => nil } )
matches_to_reset.each do |m|
m.mat_id = nil
m.save
end
@@ -83,7 +83,7 @@ class Tournament < ActiveRecord::Base
point_adjustments
end
def removeSchoolDelegations
def remove_school_delegations
self.schools.each do |s|
s.delegates.each do |d|
d.destroy
@@ -91,7 +91,7 @@ class Tournament < ActiveRecord::Base
end
end
def poolToBracketWeightsWithTooManyWrestlers
def pool_to_bracket_weights_with_too_many_wrestlers
if self.tournament_type == "Pool to bracket"
weightsWithTooManyWrestlers = weights.select{|w| w.wrestlers.size > 16}
if weightsWithTooManyWrestlers.size < 1
@@ -104,11 +104,11 @@ class Tournament < ActiveRecord::Base
end
end
def tournamentMatchGenerationError
def match_generation_error
errorString = "There is a tournament error."
if poolToBracketWeightsWithTooManyWrestlers != nil
if pool_to_bracket_weights_with_too_many_wrestlers != nil
errorString = errorString + " The following weights have too many wrestlers "
poolToBracketWeightsWithTooManyWrestlers.each do |w|
pool_to_bracket_weights_with_too_many_wrestlers.each do |w|
errorString = errorString + "#{w.max} "
end
return errorString

View File

@@ -10,18 +10,18 @@ class Weight < ActiveRecord::Base
HS_WEIGHT_CLASSES = [106,113,120,126,132,138,145,152,160,170,182,195,220,285]
before_destroy do
self.tournament.destroyAllMatches
self.tournament.destroy_all_matches
end
before_save do
# self.tournament.destroyAllMatches
# self.tournament.destroy_all_matches
end
def pools_with_bye
pool = 1
pools_with_a_bye = []
until pool > self.pools do
if wrestlersForPool(pool).first.hasAPoolBye
if wrestlers_in_pool(pool).first.has_a_pool_bye
pools_with_a_bye << pool
end
pool = pool + 1
@@ -29,19 +29,19 @@ class Weight < ActiveRecord::Base
pools_with_a_bye
end
def wrestlersForPool(poolNumber)
def wrestlers_in_pool(pool_number)
#For some reason this does not work
# wrestlers.select{|w| w.pool == poolNumber}
# wrestlers.select{|w| w.pool == pool_number}
#This does...
weightWrestlers = Wrestler.where(:weight_id => self.id)
weightWrestlers.select{|w| w.pool == poolNumber}
weight_wrestlers = Wrestler.where(:weight_id => self.id)
weight_wrestlers.select{|w| w.pool == pool_number}
end
def allPoolMatchesFinished(pool)
@wrestlers = wrestlersForPool(pool)
def all_pool_matches_finished(pool)
@wrestlers = wrestlers_in_pool(pool)
@wrestlers.each do |w|
if w.poolMatches.size != w.finishedPoolMatches.size
if w.pool_matches.size != w.finished_pool_matches.size
return false
end
end
@@ -59,14 +59,14 @@ class Weight < ActiveRecord::Base
end
end
def poolSeedOrder(pool)
# wrestlersForPool(pool).sort_by{|w| [w.original_seed ? 0 : 1, w.original_seed || 0]}
return wrestlersForPool(pool).sort_by{|w|w.bracket_line}
def pool_wrestlers_sorted_by_bracket_line(pool)
# wrestlers_in_pool(pool).sort_by{|w| [w.original_seed ? 0 : 1, w.original_seed || 0]}
return wrestlers_in_pool(pool).sort_by{|w|w.bracket_line}
end
def swapWrestlers(wrestler1_id,wrestler2_id)
SwapWrestlers.new.swapWrestlers(wrestler1_id,wrestler2_id)
def swap_wrestlers_bracket_lines(wrestler1_id,wrestler2_id)
SwapWrestlers.new.swap_wrestlers_bracket_lines(wrestler1_id,wrestler2_id)
end
@@ -86,13 +86,13 @@ class Weight < ActiveRecord::Base
end
end
def poolRounds(matches)
@matchups = matches.select{|m| m.weight_id == self.id}
@poolMatches = @matchups.select{|m| m.bracket_position == "Pool"}
return @poolMatches.sort_by{|m| m.round}.last.round
def pool_rounds(matches)
matchups = matches.select{|m| m.weight_id == self.id}
pool_matches = matchups.select{|m| m.bracket_position == "Pool"}
return pool_matches.sort_by{|m| m.round}.last.round
end
def totalRounds(matches)
def total_rounds(matches)
@matchups = matches.select{|m| m.weight_id == self.id}
@lastRound = matches.sort_by{|m| m.round}.last.round
count = 0
@@ -106,11 +106,11 @@ class Weight < ActiveRecord::Base
return count
end
def poolOrder(pool)
PoolOrder.new(wrestlersForPool(pool)).getPoolOrder
def pool_placement_order(pool)
PoolOrder.new(wrestlers_in_pool(pool)).getPoolOrder
end
def wrestlersWithoutPool
def wrestlers_without_pool_assignment
wrestlers.select{|w| w.pool == nil}
end

View File

@@ -9,102 +9,102 @@ class Wrestler < ActiveRecord::Base
validates :name, :weight_id, :school_id, presence: true
before_destroy do
# self.tournament.destroyAllMatches
# self.tournament.destroy_all_matches
end
before_create do
# self.tournament.destroyAllMatches
# self.tournament.destroy_all_matches
end
def lastFinishedMatch
allMatches.select{|m| m.finished == 1}.sort_by{|m| m.bout_number}.last
def last_finished_match
all_matches.select{|m| m.finished == 1}.sort_by{|m| m.bout_number}.last
end
def totalTeamPoints
def total_team_points
CalculateWrestlerTeamScore.new(self).totalScore
end
def teamPointsEarned
def team_points_earned
CalculateWrestlerTeamScore.new(self).earnedPoints
end
def placementPoints
CalculateWrestlerTeamScore.new(self).placementPoints
def placement_points
CalculateWrestlerTeamScore.new(self).placement_points
end
def totalDeductedPoints
def total_points_deducted
CalculateWrestlerTeamScore.new(self).deductedPoints
end
def nextMatch
unfinishedMatches.first
def next_match
unfinished_matches.first
end
def nextMatchPositionNumber
pos = lastMatch.bracket_position_number
def next_match_position_number
pos = last_match.bracket_position_number
return (pos/2.0)
end
def lastMatch
finishedMatches.sort_by{|m| m.round}.reverse.first
def last_match
finished_matches.sort_by{|m| m.round}.reverse.first
end
def winnerOfLastMatch?
if lastMatch.winner_id == self.id
def winner_of_last_match?
if last_match.winner_id == self.id
return true
else
return false
end
end
def nextMatchBoutNumber
if nextMatch
nextMatch.bout_number
def next_match_bout_number
if next_match
next_match.bout_number
else
""
end
end
def nextMatchMatName
if nextMatch
nextMatch.mat_assigned
def next_match_mat_name
if next_match
next_match.mat_assigned
else
""
end
end
def unfinishedMatches
allMatches.select{|m| m.finished != 1}.sort_by{|m| m.bout_number}
def unfinished_matches
all_matches.select{|m| m.finished != 1}.sort_by{|m| m.bout_number}
end
def resultByBout(bout)
bout_match = allMatches.select{|m| m.bout_number == bout and m.finished == 1}
def result_by_bout(bout)
bout_match = all_matches.select{|m| m.bout_number == bout and m.finished == 1}
if bout_match.size == 0
return ""
end
if bout_match.first.winner_id == self.id
return "W #{bout_match.first.bracketScore}"
return "W #{bout_match.first.bracket_score_string}"
end
if bout_match.first.winner_id != self.id
return "L #{bout_match.first.bracketScore}"
return "L #{bout_match.first.bracket_score_string}"
end
end
def matchAgainst(opponent)
allMatches.select{|m| m.w1 == opponent.id or m.w2 == opponent.id}
def match_against(opponent)
all_matches.select{|m| m.w1 == opponent.id or m.w2 == opponent.id}
end
def isWrestlingThisRound(matchRound)
if allMatches.blank?
def is_wrestling_this_round(matchRound)
if all_matches.blank?
return false
else
return true
end
end
def boutByRound(round)
round_match = allMatches.select{|m| m.round == round}.first
def bout_by_round(round)
round_match = all_matches.select{|m| m.round == round}.first
if round_match.blank?
return "BYE"
else
@@ -112,93 +112,93 @@ class Wrestler < ActiveRecord::Base
end
end
def allMatches
def all_matches
return matches.select{|m| m.w1 == self.id or m.w2 == self.id}
end
def poolMatches
pool_matches = allMatches.select{|m| m.bracket_position == "Pool"}
pool_matches.select{|m| m.poolNumber == self.pool}
def pool_matches
all_weight_pool_matches = all_matches.select{|m| m.bracket_position == "Pool"}
all_weight_pool_matches.select{|m| m.pool_number == self.pool}
end
def hasAPoolBye
if weight.poolRounds(matches) > poolMatches.size
def has_a_pool_bye
if weight.pool_rounds(matches) > pool_matches.size
return true
else
return false
end
end
def championshipAdvancementWins
matchesWon.select{|m| m.bracket_position == "Quarter" or m.bracket_position == "Semis"}
def championship_advancement_wins
matches_won.select{|m| m.bracket_position == "Quarter" or m.bracket_position == "Semis"}
end
def consoAdvancementWins
matchesWon.select{|m| m.bracket_position == "Conso Semis"}
def consolation_advancement_wins
matches_won.select{|m| m.bracket_position == "Conso Semis"}
end
def finishedMatches
allMatches.select{|m| m.finished == 1}
def finished_matches
all_matches.select{|m| m.finished == 1}
end
def finishedBracketMatches
finishedMatches.select{|m| m.bracket_position != "Pool"}
def finished_bracket_matches
finished_matches.select{|m| m.bracket_position != "Pool"}
end
def finishedPoolMatches
finishedMatches.select{|m| m.bracket_position == "Pool"}
def finished_pool_matches
finished_matches.select{|m| m.bracket_position == "Pool"}
end
def matchesWon
allMatches.select{|m| m.winner_id == self.id}
def matches_won
all_matches.select{|m| m.winner_id == self.id}
end
def poolWins
matchesWon.select{|m| m.bracket_position == "Pool"}
def pool_wins
matches_won.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"}
def pin_wins
matches_won.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" }
def tech_wins
matches_won.select{|m| m.win_type == "Tech Fall" }
end
def majorWins
matchesWon.select{|m| m.win_type == "Major" }
def major_wins
matches_won.select{|m| m.win_type == "Major" }
end
def decisionWins
matchesWon.select{|m| m.win_type == "Decision" }
def decision_wins
matches_won.select{|m| m.win_type == "Decision" }
end
def decisionPointsScored
pointsScored = 0
decisionWins.each do |m|
scoreOfMatch = m.score.delete(" ")
scoreOne = scoreOfMatch.partition('-').first.to_i
scoreTwo = scoreOfMatch.partition('-').last.to_i
if scoreOne > scoreTwo
pointsScored = pointsScored + scoreOne
elsif scoreTwo > scoreOne
pointsScored = pointsScored + scoreTwo
def decision_points_scored
points_scored = 0
decision_wins.each do |m|
score_of_match = m.score.delete(" ")
score_one = score_of_match.partition('-').first.to_i
score_two = score_of_match.partition('-').last.to_i
if score_one > score_two
points_scored = points_scored + score_one
elsif score_two > score_one
points_scored = points_scored + score_two
end
end
pointsScored
points_scored
end
def fastestPin
pinWins.sort_by{|m| m.pinTime}.first
def fastest_pin
pin_wins.sort_by{|m| m.pin_time_in_seconds}.first
end
def seasonWinPercentage
def season_win_percentage
win = self.season_win.to_f
loss = self.season_loss.to_f
if win > 0 and loss != nil
matchTotal = win + loss
percentageDec = win / matchTotal
percentage = percentageDec * 100
match_total = win + loss
percentage_dec = win / match_total
percentage = percentage_dec * 100
return percentage.to_i
elsif self.season_win == 0
return 0