mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-04-12 08:18:44 +00:00
Calculate matchups for pools. This breaks generating matches.
This commit is contained in:
26
app/models/matchup.rb
Normal file
26
app/models/matchup.rb
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
class Matchup
|
||||||
|
attr_accessor :w1, :w2, :round, :weight_id
|
||||||
|
|
||||||
|
# def w1
|
||||||
|
# end
|
||||||
|
|
||||||
|
# def w2
|
||||||
|
# end
|
||||||
|
|
||||||
|
# def round
|
||||||
|
# end
|
||||||
|
|
||||||
|
# def weight_id
|
||||||
|
# end
|
||||||
|
|
||||||
|
def weight_max
|
||||||
|
@wrestler = Wrestler.find(self.w1)
|
||||||
|
@weight = Weight.find(@wrestler.weight_id)
|
||||||
|
return @weight.max
|
||||||
|
end
|
||||||
|
|
||||||
|
def w_name(id)
|
||||||
|
@wrestler = Wrestler.find(id)
|
||||||
|
return @wrestler.name
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1,14 +1,16 @@
|
|||||||
class Pool
|
class Pool
|
||||||
def onePool(wrestlers,weight_id,tournament)
|
def onePool(wrestlers,weight_id,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
|
w.save
|
||||||
end
|
end
|
||||||
roundRobin(1,tournament,weight_id)
|
matches = roundRobin(1,tournament,weight_id,matches)
|
||||||
|
return matches
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def twoPools(wrestlers,weight_id,tournament)
|
def twoPools(wrestlers,weight_id,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
|
||||||
@@ -27,12 +29,13 @@ class Pool
|
|||||||
pool =1
|
pool =1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
roundRobin(1,tournament,weight_id)
|
matches = roundRobin(1,tournament,weight_id,matches)
|
||||||
roundRobin(2,tournament,weight_id)
|
matches = roundRobin(2,tournament,weight_id,matches)
|
||||||
|
return matches
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def fourPools(wrestlers,weight_id,tournament)
|
def fourPools(wrestlers,weight_id,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
|
||||||
@@ -57,27 +60,29 @@ class Pool
|
|||||||
@pool =1
|
@pool =1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
roundRobin(1,tournament,weight_id)
|
matches = roundRobin(1,tournament,weight_id,matches)
|
||||||
roundRobin(2,tournament,weight_id)
|
matches = roundRobin(2,tournament,weight_id,matches)
|
||||||
roundRobin(3,tournament,weight_id)
|
matches = roundRobin(3,tournament,weight_id,matches)
|
||||||
roundRobin(4,tournament,weight_id)
|
matches = roundRobin(4,tournament,weight_id,matches)
|
||||||
|
return matches
|
||||||
end
|
end
|
||||||
|
|
||||||
def roundRobin(pool,tournament_id,weight_id)
|
def roundRobin(pool,tournament_id,weight_id,matches)
|
||||||
@wrestlers = Wrestler.where(weight_id: weight_id, poolNumber: pool).to_a
|
@wrestlers = Wrestler.where(weight_id: weight_id, poolNumber: pool).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
|
||||||
@bout.each do |b|
|
@bout.each do |b|
|
||||||
if b[0] != nil and b[1] != nil
|
if b[0] != nil and b[1] != nil
|
||||||
@match = Match.new
|
@match = Matchup.new
|
||||||
@match.r_id = b[0].id
|
@match.w1 = b[0].id
|
||||||
@match.g_id = b[1].id
|
@match.w2 = b[1].id
|
||||||
@match.tournament_id = tournament_id
|
|
||||||
@match.round = index + 1
|
@match.round = index + 1
|
||||||
@match.save
|
|
||||||
|
matches << @match
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
return matches
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -10,9 +10,14 @@ class Tournament < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def upcomingMatches
|
def upcomingMatches
|
||||||
@matches = Match.where(tournament_id: self.id)
|
# @matches = Match.where(tournament_id: self.id)
|
||||||
@matches.sort_by{|x|[x.boutNumber]}
|
# @matches.sort_by{|x|[x.boutNumber]}
|
||||||
# @matches.sort_by{|x|[x.round,x.weight.max]}
|
# @matches.sort_by{|x|[x.round,x.weight.max]}
|
||||||
|
@matches = []
|
||||||
|
self.weights.sort_by{|x|[x.max]}.each do |weight|
|
||||||
|
@upcomingMatches = weight.generateMatchups(@matches)
|
||||||
|
end
|
||||||
|
return @upcomingMatches
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -48,4 +48,20 @@ class Weight < ActiveRecord::Base
|
|||||||
self.wrestlers.size
|
self.wrestlers.size
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def generateMatchups(matches)
|
||||||
|
@wrestlers = Wrestler.where(weight_id: self.id)
|
||||||
|
#@wrestlers.sort_by{|w| [w.original_seed]}
|
||||||
|
if self.pools == 1
|
||||||
|
@pool = Pool.new
|
||||||
|
@matches = @pool.onePool(@wrestlers,self.id,self.tournament_id,matches)
|
||||||
|
elsif self.pools == 2
|
||||||
|
@pool = Pool.new
|
||||||
|
@matches = @pool.twoPools(@wrestlers,self.id,self.tournament_id,matches)
|
||||||
|
elsif self.pools == 4
|
||||||
|
@pool = Pool.new
|
||||||
|
@matches = @pool.fourPools(@wrestlers,self.id,self.tournament_id,matches)
|
||||||
|
end
|
||||||
|
return @matches
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -15,12 +15,12 @@
|
|||||||
</thead>
|
</thead>
|
||||||
|
|
||||||
<tbody>
|
<tbody>
|
||||||
<% @matches.each do |m| %>
|
<% @matches.each.map do |m| %>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Round <%= m.round %></td>
|
<td>Round <%= m.round %></td>
|
||||||
<td>Bout <%= m.boutNumber %></td>
|
<td></td>
|
||||||
<td><%= m.weight_max %> lbs</td>
|
<td><%= m.weight_max %> lbs</td>
|
||||||
<td><%= m.w1_name %> vs. <%= m.w2_name %></td>
|
<td><%= m.w_name(m.w1) %> vs. <%= m.w_name(m.w2) %></td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
Reference in New Issue
Block a user