mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-03-25 01:14:43 +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
|
||||
def onePool(wrestlers,weight_id,tournament)
|
||||
def onePool(wrestlers,weight_id,tournament,matches)
|
||||
wrestlers.sort_by{|x|[x.original_seed]}.each do |w|
|
||||
w.poolNumber = 1
|
||||
w.save
|
||||
end
|
||||
roundRobin(1,tournament,weight_id)
|
||||
matches = roundRobin(1,tournament,weight_id,matches)
|
||||
return matches
|
||||
|
||||
end
|
||||
|
||||
|
||||
def twoPools(wrestlers,weight_id,tournament)
|
||||
def twoPools(wrestlers,weight_id,tournament,matches)
|
||||
pool = 1
|
||||
wrestlers.sort_by{|x|[x.original_seed]}.reverse.each do |w|
|
||||
if w.original_seed == 3
|
||||
@@ -27,12 +29,13 @@ class Pool
|
||||
pool =1
|
||||
end
|
||||
end
|
||||
roundRobin(1,tournament,weight_id)
|
||||
roundRobin(2,tournament,weight_id)
|
||||
matches = roundRobin(1,tournament,weight_id,matches)
|
||||
matches = roundRobin(2,tournament,weight_id,matches)
|
||||
return matches
|
||||
end
|
||||
|
||||
|
||||
def fourPools(wrestlers,weight_id,tournament)
|
||||
def fourPools(wrestlers,weight_id,tournament,matches)
|
||||
@pool = 1
|
||||
wrestlers.sort_by{|x|[x.original_seed]}.reverse.each do |w|
|
||||
if w.original_seed == 3
|
||||
@@ -57,27 +60,29 @@ class Pool
|
||||
@pool =1
|
||||
end
|
||||
end
|
||||
roundRobin(1,tournament,weight_id)
|
||||
roundRobin(2,tournament,weight_id)
|
||||
roundRobin(3,tournament,weight_id)
|
||||
roundRobin(4,tournament,weight_id)
|
||||
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)
|
||||
return matches
|
||||
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
|
||||
@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
|
||||
@match = Match.new
|
||||
@match.r_id = b[0].id
|
||||
@match.g_id = b[1].id
|
||||
@match.tournament_id = tournament_id
|
||||
@match = Matchup.new
|
||||
@match.w1 = b[0].id
|
||||
@match.w2 = b[1].id
|
||||
@match.round = index + 1
|
||||
@match.save
|
||||
|
||||
matches << @match
|
||||
end
|
||||
end
|
||||
end
|
||||
return matches
|
||||
end
|
||||
end
|
||||
@@ -10,9 +10,14 @@ class Tournament < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def upcomingMatches
|
||||
@matches = Match.where(tournament_id: self.id)
|
||||
@matches.sort_by{|x|[x.boutNumber]}
|
||||
# @matches = Match.where(tournament_id: self.id)
|
||||
# @matches.sort_by{|x|[x.boutNumber]}
|
||||
# @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
|
||||
|
||||
|
||||
|
||||
@@ -47,5 +47,21 @@ class Weight < ActiveRecord::Base
|
||||
end
|
||||
self.wrestlers.size
|
||||
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
|
||||
|
||||
@@ -15,12 +15,12 @@
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<% @matches.each do |m| %>
|
||||
<% @matches.each.map do |m| %>
|
||||
<tr>
|
||||
<td>Round <%= m.round %></td>
|
||||
<td>Bout <%= m.boutNumber %></td>
|
||||
<td></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>
|
||||
<% end %>
|
||||
</tbody>
|
||||
|
||||
Reference in New Issue
Block a user