diff --git a/app/models/matchup.rb b/app/models/matchup.rb new file mode 100644 index 0000000..aa763e9 --- /dev/null +++ b/app/models/matchup.rb @@ -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 \ No newline at end of file diff --git a/app/models/pool.rb b/app/models/pool.rb index 7d47e96..af6b1c7 100644 --- a/app/models/pool.rb +++ b/app/models/pool.rb @@ -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 \ No newline at end of file diff --git a/app/models/tournament.rb b/app/models/tournament.rb index bb88907..3702066 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -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 diff --git a/app/models/weight.rb b/app/models/weight.rb index 89d9cd7..2c106ae 100644 --- a/app/models/weight.rb +++ b/app/models/weight.rb @@ -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 diff --git a/app/views/static_pages/up_matches.html.erb b/app/views/static_pages/up_matches.html.erb index 8fe6e2d..17cc1af 100644 --- a/app/views/static_pages/up_matches.html.erb +++ b/app/views/static_pages/up_matches.html.erb @@ -15,12 +15,12 @@
- <% @matches.each do |m| %> + <% @matches.each.map do |m| %>