mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-03-25 01:14:43 +00:00
Cleaned up a bunch of shit. Depricated model methods and controller methods.
This commit is contained in:
25
app/models/boutgen.rb
Normal file
25
app/models/boutgen.rb
Normal file
@@ -0,0 +1,25 @@
|
||||
class Boutgen
|
||||
def matchesByRound(round, matches)
|
||||
@matches = matches.select {|m| m.round == round}
|
||||
return @matches
|
||||
end
|
||||
|
||||
def giveBout(matches)
|
||||
@matches = matches.sort_by{|x|[x.weight_max]}
|
||||
@matches.each_with_index do |m, i|
|
||||
bout = m.round * 1000 + i
|
||||
m.boutNumber = bout
|
||||
end
|
||||
return @matches
|
||||
end
|
||||
|
||||
def assignBouts(matches)
|
||||
@round = 1
|
||||
until matchesByRound(@round, matches).blank? do
|
||||
@matches = matchesByRound(@round, matches)
|
||||
giveBout(@matches)
|
||||
@round += 1
|
||||
end
|
||||
return matches
|
||||
end
|
||||
end
|
||||
@@ -2,19 +2,4 @@ class Match < ActiveRecord::Base
|
||||
belongs_to :tournament
|
||||
WIN_TYPES = ["Decision", "Major", "Tech Fall", "Pin", "Forfeit", "Injury Default", "Default", "DQ"]
|
||||
|
||||
def weight_max
|
||||
@guy = Wrestler.find(self.r_id)
|
||||
@weight = Weight.find(@guy.weight_id)
|
||||
return @weight.max
|
||||
end
|
||||
|
||||
def w1_name
|
||||
return Wrestler.find(self.r_id).name
|
||||
end
|
||||
|
||||
def w2_name
|
||||
return Wrestler.find(self.g_id).name
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
@@ -4,7 +4,7 @@ class Pool
|
||||
@pool = 1
|
||||
while @pool <= @pools
|
||||
matches = roundRobin(@pool,wrestlers,weight,tournament,matches)
|
||||
@pool = @pool +1
|
||||
@pool = @pool + 1
|
||||
end
|
||||
return matches
|
||||
end
|
||||
@@ -14,13 +14,13 @@ class Pool
|
||||
@poolMatches = RoundRobinTournament.schedule(@wrestlers).reverse
|
||||
@poolMatches.each_with_index do |b,index|
|
||||
@bout = b.map
|
||||
@bout.each do |b|
|
||||
if b[0] != nil and b[1] != nil
|
||||
@bout.each do |bout|
|
||||
if bout[0] != nil and bout[1] != nil
|
||||
@match = Matchup.new
|
||||
@match.w1 = b[0].id
|
||||
@match.w1_name = b[0].name
|
||||
@match.w2 = b[1].id
|
||||
@match.w2_name = b[1].name
|
||||
@match.w1 = bout[0].id
|
||||
@match.w1_name = bout[0].name
|
||||
@match.w2 = bout[1].id
|
||||
@match.w2_name = bout[1].name
|
||||
@match.weight_id = weight.id
|
||||
@match.round = index + 1
|
||||
@match.weight_max = weight.max
|
||||
|
||||
@@ -100,7 +100,7 @@ class Poolbracket
|
||||
end
|
||||
|
||||
def assignBouts(matches)
|
||||
@bouts = Bout.new
|
||||
@bouts = Boutgen.new
|
||||
@matches = @bouts.assignBouts(matches)
|
||||
return @matches
|
||||
end
|
||||
|
||||
@@ -7,10 +7,6 @@ class Tournament < ActiveRecord::Base
|
||||
|
||||
serialize :matchups_array
|
||||
|
||||
def unfinishedMatches
|
||||
|
||||
end
|
||||
|
||||
def upcomingMatches
|
||||
if self.matchups_array
|
||||
return matchupHashesToObjects(self.matchups_array)
|
||||
@@ -18,15 +14,7 @@ class Tournament < ActiveRecord::Base
|
||||
@matches = generateMatchups
|
||||
saveMatchups(@matches)
|
||||
return @matches
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def destroyAllMatches
|
||||
@matches_all = Match.where(tournament_id: self.id)
|
||||
@matches_all.each do |match|
|
||||
match.destroy
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def generateMatchups
|
||||
@@ -39,7 +27,7 @@ class Tournament < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def assignBouts(matches)
|
||||
@bouts = Bout.new
|
||||
@bouts = Boutgen.new
|
||||
@matches = @bouts.assignBouts(matches)
|
||||
return @matches
|
||||
end
|
||||
|
||||
@@ -11,10 +11,7 @@ class Wrestler < ActiveRecord::Base
|
||||
|
||||
|
||||
def isWrestlingThisRound(matchRound)
|
||||
@gMatches = Match.where(g_id: self.id, round: matchRound)
|
||||
@rMatches = Match.where(r_id: self.id, round: matchRound)
|
||||
@allMatches = @gMatches + @rMatches
|
||||
if @gMatches.blank? and @rMatches.blank?
|
||||
if allMatches(self.tournament.upcomingMatches).blank?
|
||||
return false
|
||||
else
|
||||
return true
|
||||
@@ -27,8 +24,7 @@ class Wrestler < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def boutByRound(round,matches)
|
||||
@matches = matches.select{|m| m.w1 == self.id || m.w2 == self.id}
|
||||
@match = @matches.select{|m| m.round == round}.first
|
||||
@match = allMatches(matches).select{|m| m.round == round}.first
|
||||
if @match.blank?
|
||||
return "BYE"
|
||||
else
|
||||
@@ -56,5 +52,4 @@ class Wrestler < ActiveRecord::Base
|
||||
return 0
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user