mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-04-13 16:40:48 +00:00
Reducing queries for upcoming matches
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
class Matchup
|
class Matchup
|
||||||
attr_accessor :w1, :w2, :round, :weight_id, :boutNumber
|
attr_accessor :w1, :w2, :round, :weight_id, :boutNumber, :w1_name, :w2_name
|
||||||
|
|
||||||
# def w1
|
# def w1
|
||||||
# end
|
# end
|
||||||
@@ -14,13 +14,8 @@ class Matchup
|
|||||||
# end
|
# end
|
||||||
|
|
||||||
def weight_max
|
def weight_max
|
||||||
@wrestler = Wrestler.find(self.w1)
|
@weight = Weight.find(self.weight_id)
|
||||||
@weight = Weight.find(@wrestler.weight_id)
|
|
||||||
return @weight.max
|
return @weight.max
|
||||||
end
|
end
|
||||||
|
|
||||||
def w_name(id)
|
|
||||||
@wrestler = Wrestler.find(id)
|
|
||||||
return @wrestler.name
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
@@ -1,27 +1,23 @@
|
|||||||
class Pool
|
class Pool
|
||||||
def onePool(wrestlers,weight_id,tournament,matches)
|
def onePool(wrestlers,weight,tournament,matches)
|
||||||
wrestlers.sort_by{|x|[x.original_seed]}.each do |w|
|
wrestlers.sort_by{|x|[x.original_seed]}.each do |w|
|
||||||
w.poolNumber = 1
|
w.poolNumber = 1
|
||||||
w.save
|
|
||||||
end
|
end
|
||||||
matches = roundRobin(1,tournament,weight_id,matches)
|
matches = roundRobin(1,tournament,weight,matches,wrestlers)
|
||||||
return matches
|
return matches
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def twoPools(wrestlers,weight_id,tournament,matches)
|
def twoPools(wrestlers,weight,tournament,matches)
|
||||||
pool = 1
|
pool = 1
|
||||||
wrestlers.sort_by{|x|[x.original_seed]}.reverse.each do |w|
|
wrestlers.sort_by{|x|[x.original_seed]}.reverse.each do |w|
|
||||||
if w.original_seed == 3
|
if w.original_seed == 3
|
||||||
w.poolNumber = 2
|
w.poolNumber = 2
|
||||||
w.save
|
|
||||||
elsif w.original_seed == 4
|
elsif w.original_seed == 4
|
||||||
w.poolNumber = 1
|
w.poolNumber = 1
|
||||||
w.save
|
|
||||||
else
|
else
|
||||||
w.poolNumber = pool
|
w.poolNumber = pool
|
||||||
w.save
|
|
||||||
end
|
end
|
||||||
if pool < 2
|
if pool < 2
|
||||||
pool = pool + 1
|
pool = pool + 1
|
||||||
@@ -29,30 +25,25 @@ class Pool
|
|||||||
pool =1
|
pool =1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
matches = roundRobin(1,tournament,weight_id,matches)
|
matches = roundRobin(1,tournament,weight,matches,wrestlers)
|
||||||
matches = roundRobin(2,tournament,weight_id,matches)
|
matches = roundRobin(2,tournament,weight,matches,wrestlers)
|
||||||
return matches
|
return matches
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def fourPools(wrestlers,weight_id,tournament,matches)
|
def fourPools(wrestlers,weight,tournament,matches)
|
||||||
@pool = 1
|
@pool = 1
|
||||||
wrestlers.sort_by{|x|[x.original_seed]}.reverse.each do |w|
|
wrestlers.sort_by{|x|[x.original_seed]}.reverse.each do |w|
|
||||||
if w.original_seed == 3
|
if w.original_seed == 3
|
||||||
w.poolNumber = 3
|
w.poolNumber = 3
|
||||||
w.save
|
|
||||||
elsif w.original_seed == 4
|
elsif w.original_seed == 4
|
||||||
w.poolNumber = 4
|
w.poolNumber = 4
|
||||||
w.save
|
|
||||||
elsif w.original_seed == 1
|
elsif w.original_seed == 1
|
||||||
w.poolNumber = 1
|
w.poolNumber = 1
|
||||||
w.save
|
|
||||||
elsif w.original_seed == 2
|
elsif w.original_seed == 2
|
||||||
w.poolNumber = 2
|
w.poolNumber = 2
|
||||||
w.save
|
|
||||||
else
|
else
|
||||||
w.poolNumber = @pool
|
w.poolNumber = @pool
|
||||||
w.save
|
|
||||||
end
|
end
|
||||||
if @pool < 4
|
if @pool < 4
|
||||||
@pool = @pool + 1
|
@pool = @pool + 1
|
||||||
@@ -60,15 +51,15 @@ class Pool
|
|||||||
@pool =1
|
@pool =1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
matches = roundRobin(1,tournament,weight_id,matches)
|
matches = roundRobin(1,tournament,weight,matches,wrestlers)
|
||||||
matches = roundRobin(2,tournament,weight_id,matches)
|
matches = roundRobin(2,tournament,weight,matches,wrestlers)
|
||||||
matches = roundRobin(3,tournament,weight_id,matches)
|
matches = roundRobin(3,tournament,weight,matches,wrestlers)
|
||||||
matches = roundRobin(4,tournament,weight_id,matches)
|
matches = roundRobin(4,tournament,weight,matches,wrestlers)
|
||||||
return matches
|
return matches
|
||||||
end
|
end
|
||||||
|
|
||||||
def roundRobin(pool,tournament_id,weight_id,matches)
|
def roundRobin(pool,tournament_id,weight,matches,wrestlers)
|
||||||
@wrestlers = Wrestler.where(weight_id: weight_id, poolNumber: pool).to_a
|
@wrestlers = wrestlers.to_a
|
||||||
@poolMatches = RoundRobinTournament.schedule(@wrestlers).reverse
|
@poolMatches = RoundRobinTournament.schedule(@wrestlers).reverse
|
||||||
@poolMatches.each_with_index do |b,index|
|
@poolMatches.each_with_index do |b,index|
|
||||||
@bout = b.map
|
@bout = b.map
|
||||||
@@ -76,9 +67,11 @@ class Pool
|
|||||||
if b[0] != nil and b[1] != nil
|
if b[0] != nil and b[1] != nil
|
||||||
@match = Matchup.new
|
@match = Matchup.new
|
||||||
@match.w1 = b[0].id
|
@match.w1 = b[0].id
|
||||||
|
@match.w1_name = b[0].name
|
||||||
@match.w2 = b[1].id
|
@match.w2 = b[1].id
|
||||||
|
@match.w2_name = b[1].name
|
||||||
|
@match.weight_id = weight.id
|
||||||
@match.round = index + 1
|
@match.round = index + 1
|
||||||
|
|
||||||
matches << @match
|
matches << @match
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ class Weight < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def pools
|
def pools
|
||||||
@wrestlers = Wrestler.where(weight_id: self.id)
|
@wrestlers = self.wrestlers
|
||||||
if @wrestlers.size <= 6
|
if @wrestlers.size <= 6
|
||||||
self.pools = 1
|
self.pools = 1
|
||||||
elsif (@wrestlers.size > 6) && (@wrestlers.size <= 10)
|
elsif (@wrestlers.size > 6) && (@wrestlers.size <= 10)
|
||||||
@@ -49,17 +49,17 @@ class Weight < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def generateMatchups(matches)
|
def generateMatchups(matches)
|
||||||
@wrestlers = Wrestler.where(weight_id: self.id)
|
@wrestlers = self.wrestlers
|
||||||
#@wrestlers.sort_by{|w| [w.original_seed]}
|
#@wrestlers.sort_by{|w| [w.original_seed]}
|
||||||
if self.pools == 1
|
if self.pools == 1
|
||||||
@pool = Pool.new
|
@pool = Pool.new
|
||||||
@matches = @pool.onePool(@wrestlers,self.id,self.tournament_id,matches)
|
@matches = @pool.onePool(@wrestlers,self,self.tournament_id,matches)
|
||||||
elsif self.pools == 2
|
elsif self.pools == 2
|
||||||
@pool = Pool.new
|
@pool = Pool.new
|
||||||
@matches = @pool.twoPools(@wrestlers,self.id,self.tournament_id,matches)
|
@matches = @pool.twoPools(@wrestlers,self,self.tournament_id,matches)
|
||||||
elsif self.pools == 4
|
elsif self.pools == 4
|
||||||
@pool = Pool.new
|
@pool = Pool.new
|
||||||
@matches = @pool.fourPools(@wrestlers,self.id,self.tournament_id,matches)
|
@matches = @pool.fourPools(@wrestlers,self,self.tournament_id,matches)
|
||||||
end
|
end
|
||||||
return @matches
|
return @matches
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
<td>Round <%= m.round %></td>
|
<td>Round <%= m.round %></td>
|
||||||
<td><%= m.boutNumber %></td>
|
<td><%= m.boutNumber %></td>
|
||||||
<td><%= m.weight_max %> lbs</td>
|
<td><%= m.weight_max %> lbs</td>
|
||||||
<td><%= m.w_name(m.w1) %> vs. <%= m.w_name(m.w2) %></td>
|
<td><%= m.w1_name %> vs. <%= m.w2_name %></td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
Reference in New Issue
Block a user