1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-04-05 06:07:20 +00:00

Reducing queries for upcoming matches

This commit is contained in:
2015-03-16 08:06:08 -04:00
parent e8dd332bbc
commit 05c340eb94
4 changed files with 23 additions and 35 deletions

View File

@@ -1,27 +1,23 @@
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|
w.poolNumber = 1
w.save
end
matches = roundRobin(1,tournament,weight_id,matches)
matches = roundRobin(1,tournament,weight,matches,wrestlers)
return matches
end
def twoPools(wrestlers,weight_id,tournament,matches)
def twoPools(wrestlers,weight,tournament,matches)
pool = 1
wrestlers.sort_by{|x|[x.original_seed]}.reverse.each do |w|
if w.original_seed == 3
w.poolNumber = 2
w.save
elsif w.original_seed == 4
w.poolNumber = 1
w.save
else
w.poolNumber = pool
w.save
end
if pool < 2
pool = pool + 1
@@ -29,30 +25,25 @@ class Pool
pool =1
end
end
matches = roundRobin(1,tournament,weight_id,matches)
matches = roundRobin(2,tournament,weight_id,matches)
matches = roundRobin(1,tournament,weight,matches,wrestlers)
matches = roundRobin(2,tournament,weight,matches,wrestlers)
return matches
end
def fourPools(wrestlers,weight_id,tournament,matches)
def fourPools(wrestlers,weight,tournament,matches)
@pool = 1
wrestlers.sort_by{|x|[x.original_seed]}.reverse.each do |w|
if w.original_seed == 3
w.poolNumber = 3
w.save
elsif w.original_seed == 4
w.poolNumber = 4
w.save
elsif w.original_seed == 1
w.poolNumber = 1
w.save
elsif w.original_seed == 2
w.poolNumber = 2
w.save
else
w.poolNumber = @pool
w.save
end
if @pool < 4
@pool = @pool + 1
@@ -60,15 +51,15 @@ class Pool
@pool =1
end
end
matches = roundRobin(1,tournament,weight_id,matches)
matches = roundRobin(2,tournament,weight_id,matches)
matches = roundRobin(3,tournament,weight_id,matches)
matches = roundRobin(4,tournament,weight_id,matches)
matches = roundRobin(1,tournament,weight,matches,wrestlers)
matches = roundRobin(2,tournament,weight,matches,wrestlers)
matches = roundRobin(3,tournament,weight,matches,wrestlers)
matches = roundRobin(4,tournament,weight,matches,wrestlers)
return matches
end
def roundRobin(pool,tournament_id,weight_id,matches)
@wrestlers = Wrestler.where(weight_id: weight_id, poolNumber: pool).to_a
def roundRobin(pool,tournament_id,weight,matches,wrestlers)
@wrestlers = wrestlers.to_a
@poolMatches = RoundRobinTournament.schedule(@wrestlers).reverse
@poolMatches.each_with_index do |b,index|
@bout = b.map
@@ -76,9 +67,11 @@ class Pool
if b[0] != nil and b[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.weight_id = weight.id
@match.round = index + 1
matches << @match
end
end