From 90b96bb218a8b8f12986022615c414d5d07a504e Mon Sep 17 00:00:00 2001 From: Jacob Cody Wimer Date: Thu, 18 Dec 2014 10:45:49 -0500 Subject: [PATCH] Making progress on generating matches. --- app/controllers/static_pages_controller.rb | 348 +-------------------- app/models/bout.rb | 11 - app/models/pool.rb | 30 -- app/models/tournament.rb | 19 +- app/models/weight.rb | 29 +- 5 files changed, 43 insertions(+), 394 deletions(-) delete mode 100644 app/models/bout.rb delete mode 100644 app/models/pool.rb diff --git a/app/controllers/static_pages_controller.rb b/app/controllers/static_pages_controller.rb index e60c5b0..77ac531 100644 --- a/app/controllers/static_pages_controller.rb +++ b/app/controllers/static_pages_controller.rb @@ -66,353 +66,7 @@ class StaticPagesController < ApplicationController @tournament = Tournament.find(params[:tournament]) end if @tournament - @matches_all = Match.where(tournament_id: @tournament.id) - @matches_all.each do |match| - match.destroy - end - @weights = Weight.where(tournament_id: @tournament.id) - #ROUND 1 - @weights.order("id asc").each do |weight| - @seed1 = Wrestler.where(weight_id: weight.id, original_seed: 1).first - @seed10 = Wrestler.where(weight_id: weight.id, original_seed: 10).first - @seed7 = Wrestler.where(weight_id: weight.id, original_seed: 7).first - @seed5 = Wrestler.where(weight_id: weight.id, original_seed: 5).first - @seed4 = Wrestler.where(weight_id: weight.id, original_seed: 4).first - @seed2 = Wrestler.where(weight_id: weight.id, original_seed: 2).first - @seed9 = Wrestler.where(weight_id: weight.id, original_seed: 9).first - @seed6 = Wrestler.where(weight_id: weight.id, original_seed: 6).first - @seed8 = Wrestler.where(weight_id: weight.id, original_seed: 8).first - @seed3 = Wrestler.where(weight_id: weight.id, original_seed: 3).first - @seed11 = Wrestler.where(weight_id: weight.id, original_seed: 11).first - @seed12 = Wrestler.where(weight_id: weight.id, original_seed: 12).first - @seed13 = Wrestler.where(weight_id: weight.id, original_seed: 13).first - @seed14 = Wrestler.where(weight_id: weight.id, original_seed: 14).first - @seed15 = Wrestler.where(weight_id: weight.id, original_seed: 15).first - @seed16 = Wrestler.where(weight_id: weight.id, original_seed: 16).first - @bracket_size = Wrestler.where(weight_id: weight.id).count - def createMatch(r_id,g_id,tournament) - @match = Match.new - @match.r_id = r_id - @match.g_id = g_id - @match.tournament_id = tournament - @match.round = 1 - @match.save - end - if @bracket_size == 16 - createMatch(@seed1.id,@seed16.id,@tournament.id) - createMatch(@seed12.id,@seed8.id,@tournament.id) - createMatch(@seed2.id,@seed15.id,@tournament.id) - createMatch(@seed11.id,@seed7.id,@tournament.id) - createMatch(@seed3.id,@seed14.id,@tournament.id) - createMatch(@seed10.id,@seed6.id,@tournament.id) - createMatch(@seed4.id,@seed13.id,@tournament.id) - createMatch(@seed9.id,@seed5.id,@tournament.id) - elsif @bracket_size == 15 - createMatch(@seed1.id,@seed15.id,@tournament.id) - createMatch(@seed12.id,@seed8.id,@tournament.id) - createMatch(@seed2.id,@seed14.id,@tournament.id) - createMatch(@seed11.id,@seed7.id,@tournament.id) - createMatch(@seed3.id,@seed13.id,@tournament.id) - createMatch(@seed10.id,@seed6.id,@tournament.id) - createMatch(@seed9.id,@seed5.id,@tournament.id) - elsif @bracket_size == 14 - createMatch(@seed1.id,@seed14.id,@tournament.id) - createMatch(@seed12.id,@seed8.id,@tournament.id) - createMatch(@seed2.id,@seed13.id,@tournament.id) - createMatch(@seed11.id,@seed7.id,@tournament.id) - createMatch(@seed10.id,@seed6.id,@tournament.id) - createMatch(@seed9.id,@seed5.id,@tournament.id) - elsif @bracket_size == 13 - createMatch(@seed1.id,@seed13.id,@tournament.id) - createMatch(@seed12.id,@seed8.id,@tournament.id) - createMatch(@seed11.id,@seed7.id,@tournament.id) - createMatch(@seed10.id,@seed6.id,@tournament.id) - createMatch(@seed9.id,@seed5.id,@tournament.id) - elsif @bracket_size == 12 - createMatch(@seed12.id,@seed8.id,@tournament.id) - createMatch(@seed11.id,@seed7.id,@tournament.id) - createMatch(@seed10.id,@seed6.id,@tournament.id) - createMatch(@seed9.id,@seed5.id,@tournament.id) - elsif @bracket_size == 11 - createMatch(@seed11.id,@seed8.id,@tournament.id) - createMatch(@seed10.id,@seed7.id,@tournament.id) - createMatch(@seed9.id,@seed6.id,@tournament.id) - elsif @bracket_size == 10 - createMatch(@seed1.id,@seed10.id,@tournament.id) - createMatch(@seed5.id,@seed7.id,@tournament.id) - createMatch(@seed2.id,@seed9.id,@tournament.id) - createMatch(@seed6.id,@seed8.id,@tournament.id) - elsif @bracket_size == 9 - createMatch(@seed1.id,@seed9.id,@tournament.id) - createMatch(@seed5.id,@seed7.id,@tournament.id) - createMatch(@seed6.id,@seed8.id,@tournament.id) - elsif @bracket_size == 8 - createMatch(@seed5.id,@seed7.id,@tournament.id) - createMatch(@seed6.id,@seed8.id,@tournament.id) - elsif @bracket_size == 7 - createMatch(@seed5.id,@seed7.id,@tournament.id) - end - - end - #ROUND 2 - @weights.order("id asc").each do |weight| - @seed1 = Wrestler.where(weight_id: weight.id, original_seed: 1).first - @seed10 = Wrestler.where(weight_id: weight.id, original_seed: 10).first - @seed7 = Wrestler.where(weight_id: weight.id, original_seed: 7).first - @seed5 = Wrestler.where(weight_id: weight.id, original_seed: 5).first - @seed4 = Wrestler.where(weight_id: weight.id, original_seed: 4).first - @seed2 = Wrestler.where(weight_id: weight.id, original_seed: 2).first - @seed9 = Wrestler.where(weight_id: weight.id, original_seed: 9).first - @seed6 = Wrestler.where(weight_id: weight.id, original_seed: 6).first - @seed8 = Wrestler.where(weight_id: weight.id, original_seed: 8).first - @seed3 = Wrestler.where(weight_id: weight.id, original_seed: 3).first - @seed12 = Wrestler.where(weight_id: weight.id, original_seed: 12).first - @seed13 = Wrestler.where(weight_id: weight.id, original_seed: 13).first - @seed14 = Wrestler.where(weight_id: weight.id, original_seed: 14).first - @seed15 = Wrestler.where(weight_id: weight.id, original_seed: 15).first - @seed16 = Wrestler.where(weight_id: weight.id, original_seed: 16).first - @seed11 = Wrestler.where(weight_id: weight.id, original_seed: 11).first - @bracket_size = Wrestler.where(weight_id: weight.id).count - def createMatch(r_id,g_id,tournament) - @match = Match.new - @match.r_id = r_id - @match.g_id = g_id - @match.tournament_id = tournament - @match.round = 2 - @match.save - end - if @bracket_size == 16 - createMatch(@seed1.id,@seed12.id,@tournament.id) - createMatch(@seed16.id,@seed8.id,@tournament.id) - createMatch(@seed2.id,@seed11.id,@tournament.id) - createMatch(@seed15.id,@seed7.id,@tournament.id) - createMatch(@seed3.id,@seed10.id,@tournament.id) - createMatch(@seed14.id,@seed6.id,@tournament.id) - createMatch(@seed4.id,@seed9.id,@tournament.id) - createMatch(@seed13.id,@seed5.id,@tournament.id) - elsif @bracket_size == 15 - createMatch(@seed1.id,@seed12.id,@tournament.id) - createMatch(@seed15.id,@seed8.id,@tournament.id) - createMatch(@seed2.id,@seed11.id,@tournament.id) - createMatch(@seed14.id,@seed7.id,@tournament.id) - createMatch(@seed3.id,@seed10.id,@tournament.id) - createMatch(@seed13.id,@seed6.id,@tournament.id) - createMatch(@seed4.id,@seed9.id,@tournament.id) - elsif @bracket_size == 14 - createMatch(@seed1.id,@seed12.id,@tournament.id) - createMatch(@seed14.id,@seed8.id,@tournament.id) - createMatch(@seed2.id,@seed11.id,@tournament.id) - createMatch(@seed13.id,@seed7.id,@tournament.id) - createMatch(@seed3.id,@seed10.id,@tournament.id) - createMatch(@seed9.id,@seed4.id,@tournament.id) - elsif @bracket_size == 13 - createMatch(@seed1.id,@seed12.id,@tournament.id) - createMatch(@seed13.id,@seed8.id,@tournament.id) - createMatch(@seed2.id,@seed11.id,@tournament.id) - createMatch(@seed3.id,@seed10.id,@tournament.id) - createMatch(@seed4.id,@seed9.id,@tournament.id) - elsif @bracket_size == 12 - createMatch(@seed1.id,@seed12.id,@tournament.id) - createMatch(@seed2.id,@seed11.id,@tournament.id) - createMatch(@seed3.id,@seed10.id,@tournament.id) - createMatch(@seed4.id,@seed9.id,@tournament.id) - elsif @bracket_size == 11 - createMatch(@seed1.id,@seed11.id,@tournament.id) - createMatch(@seed2.id,@seed10.id,@tournament.id) - createMatch(@seed3.id,@seed9.id,@tournament.id) - elsif @bracket_size == 10 - createMatch(@seed1.id,@seed5.id,@tournament.id) - createMatch(@seed10.id,@seed4.id,@tournament.id) - createMatch(@seed2.id,@seed6.id,@tournament.id) - createMatch(@seed9.id,@seed3.id,@tournament.id) - elsif @bracket_size == 9 - createMatch(@seed1.id,@seed5.id,@tournament.id) - createMatch(@seed9.id,@seed4.id,@tournament.id) - createMatch(@seed2.id,@seed6.id,@tournament.id) - elsif @bracket_size == 8 - createMatch(@seed1.id,@seed5.id,@tournament.id) - createMatch(@seed2.id,@seed6.id,@tournament.id) - elsif @bracket_size == 7 - createMatch(@seed1.id,@seed5.id,@tournament.id) - createMatch(@seed2.id,@seed6.id,@tournament.id) - elsif @bracket_size == 6 - createMatch(@seed1.id,@seed5.id,@tournament.id) - createMatch(@seed2.id,@seed6.id,@tournament.id) - end - - end - #ROUND 3 - @weights.order("id asc").each do |weight| - @seed1 = Wrestler.where(weight_id: weight.id, original_seed: 1).first - @seed10 = Wrestler.where(weight_id: weight.id, original_seed: 10).first - @seed7 = Wrestler.where(weight_id: weight.id, original_seed: 7).first - @seed5 = Wrestler.where(weight_id: weight.id, original_seed: 5).first - @seed4 = Wrestler.where(weight_id: weight.id, original_seed: 4).first - @seed2 = Wrestler.where(weight_id: weight.id, original_seed: 2).first - @seed9 = Wrestler.where(weight_id: weight.id, original_seed: 9).first - @seed6 = Wrestler.where(weight_id: weight.id, original_seed: 6).first - @seed8 = Wrestler.where(weight_id: weight.id, original_seed: 8).first - @seed3 = Wrestler.where(weight_id: weight.id, original_seed: 3).first - @seed12 = Wrestler.where(weight_id: weight.id, original_seed: 12).first - @seed13 = Wrestler.where(weight_id: weight.id, original_seed: 13).first - @seed14 = Wrestler.where(weight_id: weight.id, original_seed: 14).first - @seed15 = Wrestler.where(weight_id: weight.id, original_seed: 15).first - @seed16 = Wrestler.where(weight_id: weight.id, original_seed: 16).first - @seed11 = Wrestler.where(weight_id: weight.id, original_seed: 11).first - @bracket_size = Wrestler.where(weight_id: weight.id).count - def createMatch(r_id,g_id,tournament) - @match = Match.new - @match.r_id = r_id - @match.g_id = g_id - @match.tournament_id = tournament - @match.round = 3 - @match.save - end - if @bracket_size == 16 - createMatch(@seed1.id,@seed8.id,@tournament.id) - createMatch(@seed12.id,@seed16.id,@tournament.id) - createMatch(@seed2.id,@seed7.id,@tournament.id) - createMatch(@seed11.id,@seed15.id,@tournament.id) - createMatch(@seed3.id,@seed6.id,@tournament.id) - createMatch(@seed10.id,@seed14.id,@tournament.id) - createMatch(@seed4.id,@seed5.id,@tournament.id) - createMatch(@seed9.id,@seed13.id,@tournament.id) - elsif @bracket_size == 15 - createMatch(@seed1.id,@seed8.id,@tournament.id) - createMatch(@seed15.id,@seed12.id,@tournament.id) - createMatch(@seed2.id,@seed7.id,@tournament.id) - createMatch(@seed11.id,@seed14.id,@tournament.id) - createMatch(@seed3.id,@seed6.id,@tournament.id) - createMatch(@seed13.id,@seed10.id,@tournament.id) - createMatch(@seed4.id,@seed5.id,@tournament.id) - elsif @bracket_size == 14 - createMatch(@seed1.id,@seed8.id,@tournament.id) - createMatch(@seed14.id,@seed12.id,@tournament.id) - createMatch(@seed2.id,@seed7.id,@tournament.id) - createMatch(@seed13.id,@seed11.id,@tournament.id) - createMatch(@seed3.id,@seed6.id,@tournament.id) - createMatch(@seed4.id,@seed5.id,@tournament.id) - elsif @bracket_size == 13 - createMatch(@seed1.id,@seed8.id,@tournament.id) - createMatch(@seed13.id,@seed12.id,@tournament.id) - createMatch(@seed2.id,@seed7.id,@tournament.id) - createMatch(@seed3.id,@seed6.id,@tournament.id) - createMatch(@seed4.id,@seed5.id,@tournament.id) - elsif @bracket_size == 12 - createMatch(@seed1.id,@seed8.id,@tournament.id) - createMatch(@seed2.id,@seed7.id,@tournament.id) - createMatch(@seed3.id,@seed6.id,@tournament.id) - createMatch(@seed4.id,@seed5.id,@tournament.id) - elsif @bracket_size == 11 - createMatch(@seed1.id,@seed8.id,@tournament.id) - createMatch(@seed2.id,@seed7.id,@tournament.id) - createMatch(@seed3.id,@seed6.id,@tournament.id) - createMatch(@seed4.id,@seed5.id,@tournament.id) - elsif @bracket_size == 10 - createMatch(@seed1.id,@seed4.id,@tournament.id) - createMatch(@seed10.id,@seed7.id,@tournament.id) - createMatch(@seed2.id,@seed3.id,@tournament.id) - createMatch(@seed8.id,@seed9.id,@tournament.id) - elsif @bracket_size == 9 - createMatch(@seed1.id,@seed4.id,@tournament.id) - createMatch(@seed9.id,@seed7.id,@tournament.id) - createMatch(@seed2.id,@seed3.id,@tournament.id) - elsif @bracket_size == 8 - createMatch(@seed1.id,@seed4.id,@tournament.id) - createMatch(@seed2.id,@seed3.id,@tournament.id) - elsif @bracket_size == 7 - createMatch(@seed1.id,@seed4.id,@tournament.id) - createMatch(@seed2.id,@seed3.id,@tournament.id) - elsif @bracket_size == 6 - createMatch(@seed1.id,@seed4.id,@tournament.id) - createMatch(@seed2.id,@seed3.id,@tournament.id) - end - - end - #ROUND 4 - @weights.order("id asc").each do |weight| - @seed1 = Wrestler.where(weight_id: weight.id, original_seed: 1).first - @seed10 = Wrestler.where(weight_id: weight.id, original_seed: 10).first - @seed7 = Wrestler.where(weight_id: weight.id, original_seed: 7).first - @seed5 = Wrestler.where(weight_id: weight.id, original_seed: 5).first - @seed4 = Wrestler.where(weight_id: weight.id, original_seed: 4).first - @seed2 = Wrestler.where(weight_id: weight.id, original_seed: 2).first - @seed9 = Wrestler.where(weight_id: weight.id, original_seed: 9).first - @seed6 = Wrestler.where(weight_id: weight.id, original_seed: 6).first - @seed8 = Wrestler.where(weight_id: weight.id, original_seed: 8).first - @seed3 = Wrestler.where(weight_id: weight.id, original_seed: 3).first - @bracket_size = Wrestler.where(weight_id: weight.id).count - def createMatch(r_id,g_id,tournament) - @match = Match.new - @match.r_id = r_id - @match.g_id = g_id - @match.tournament_id = tournament - @match.round = 4 - @match.save - end - if @bracket_size == 10 - createMatch(@seed1.id,@seed7.id,@tournament.id) - createMatch(@seed5.id,@seed4.id,@tournament.id) - createMatch(@seed2.id,@seed8.id,@tournament.id) - createMatch(@seed6.id,@seed3.id,@tournament.id) - elsif @bracket_size == 9 - createMatch(@seed1.id,@seed7.id,@tournament.id) - createMatch(@seed5.id,@seed4.id,@tournament.id) - createMatch(@seed2.id,@seed8.id,@tournament.id) - createMatch(@seed6.id,@seed3.id,@tournament.id) - elsif @bracket_size == 8 - createMatch(@seed1.id,@seed7.id,@tournament.id) - createMatch(@seed5.id,@seed4.id,@tournament.id) - createMatch(@seed2.id,@seed8.id,@tournament.id) - createMatch(@seed6.id,@seed3.id,@tournament.id) - elsif @bracket_size == 7 - createMatch(@seed1.id,@seed7.id,@tournament.id) - createMatch(@seed5.id,@seed4.id,@tournament.id) - createMatch(@seed6.id,@seed3.id,@tournament.id) - elsif @bracket_size == 6 - createMatch(@seed5.id,@seed4.id,@tournament.id) - createMatch(@seed6.id,@seed3.id,@tournament.id) - end - - end - #ROUND 5 - @weights.order("id asc").each do |weight| - @seed1 = Wrestler.where(weight_id: weight.id, original_seed: 1).first - @seed10 = Wrestler.where(weight_id: weight.id, original_seed: 10).first - @seed7 = Wrestler.where(weight_id: weight.id, original_seed: 7).first - @seed5 = Wrestler.where(weight_id: weight.id, original_seed: 5).first - @seed4 = Wrestler.where(weight_id: weight.id, original_seed: 4).first - @seed2 = Wrestler.where(weight_id: weight.id, original_seed: 2).first - @seed9 = Wrestler.where(weight_id: weight.id, original_seed: 9).first - @seed6 = Wrestler.where(weight_id: weight.id, original_seed: 6).first - @seed8 = Wrestler.where(weight_id: weight.id, original_seed: 8).first - @seed3 = Wrestler.where(weight_id: weight.id, original_seed: 3).first - @bracket_size = Wrestler.where(weight_id: weight.id).count - def createMatch(r_id,g_id,tournament) - @match = Match.new - @match.r_id = r_id - @match.g_id = g_id - @match.tournament_id = tournament - @match.round = 5 - @match.save - end - if @bracket_size == 10 - createMatch(@seed10.id,@seed5.id,@tournament.id) - createMatch(@seed7.id,@seed4.id,@tournament.id) - createMatch(@seed9.id,@seed6.id,@tournament.id) - createMatch(@seed8.id,@seed3.id,@tournament.id) - elsif @bracket_size == 9 - createMatch(@seed7.id,@seed4.id,@tournament.id) - createMatch(@seed9.id,@seed5.id,@tournament.id) - createMatch(@seed8.id,@seed3.id,@tournament.id) - elsif @bracket_size == 8 - createMatch(@seed7.id,@seed4.id,@tournament.id) - createMatch(@seed8.id,@seed3.id,@tournament.id) - elsif @bracket_size == 7 - createMatch(@seed7.id,@seed4.id,@tournament.id) - end - - end + @tournament.generateMatches end end diff --git a/app/models/bout.rb b/app/models/bout.rb deleted file mode 100644 index 8a0a4b3..0000000 --- a/app/models/bout.rb +++ /dev/null @@ -1,11 +0,0 @@ -class Bout - attr_accessor :w1, :w2, :tournament_id - def self.all - ObjectSpace.each_object(self).to_a - end - - def self.count - all.count - end - -end \ No newline at end of file diff --git a/app/models/pool.rb b/app/models/pool.rb deleted file mode 100644 index 322ac55..0000000 --- a/app/models/pool.rb +++ /dev/null @@ -1,30 +0,0 @@ -class Pool - def createPool(tournament) - @weights = Weight.where(tournament_id: tournament) - @weights.each do |weight| - roundRobin(weight,tournament) - end - end - - def createBout(wrestler,tournament) - @bout = Bout.new - @bout.w1 = wrestler.id - @bout.tournament_id = tournament - end - - def roundRobin(weight,tournament) - @wrestlers = Wrestler.where(weight_id: weight) - @wrestlers.each do |wrestler| - createBout(wrestler,tournament) - end - end - - def self.all - ObjectSpace.each_object(self).to_a - end - - def self.count - all.count - end - -end \ No newline at end of file diff --git a/app/models/tournament.rb b/app/models/tournament.rb index cbb3a97..6f67795 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -4,10 +4,19 @@ class Tournament < ActiveRecord::Base has_many :matches, dependent: :destroy has_many :mats, dependent: :destroy - def bouts - @pool = Pool.new - @pool.createPool(self.id) - @bouts = Bout.all - return @bouts + def generateMatches + destroyAllMatches + self.weights.each do |weight| + puts weight.inspect + weight.generatePool + end end + + def destroyAllMatches + @matches_all = Match.where(tournament_id: self.id) + @matches_all.each do |match| + match.destroy + end + end + end diff --git a/app/models/weight.rb b/app/models/weight.rb index 263ba88..452063f 100644 --- a/app/models/weight.rb +++ b/app/models/weight.rb @@ -2,5 +2,32 @@ class Weight < ActiveRecord::Base belongs_to :tournament has_many :wrestlers, dependent: :destroy - + attr_accessor :pools + + def generatePool + @wrestlers = Wrestler.where(weight_id: self.id) + poolNumber(@wrestlers) + @wrestlers.each do |wrestler| + puts wrestler.inspect + + end + puts 'Pool size:' + puts self.pools + end + + def poolNumber(wrestlers) + if wrestlers.size <= 5 + self.pools = 1 + elsif (wrestlers.size > 5) && (wrestlers.size <= 8) + self.pools = 2 + elsif (wrestlers.size > 8) && (wrestlers.size <= 16) + self.pools = 4 + end + end + + def fourPool + + end + + end