diff --git a/app/controllers/static_pages_controller.rb b/app/controllers/static_pages_controller.rb index e94c456..e9265c6 100644 --- a/app/controllers/static_pages_controller.rb +++ b/app/controllers/static_pages_controller.rb @@ -8,7 +8,7 @@ class StaticPagesController < ApplicationController @tournament = Tournament.find(params[:tournament]) end if @tournament - @matches = Match.where(tournament_id: @tournament.id) + @matches = @tournament.upcomingMatches end end def results diff --git a/app/models/bout.rb b/app/models/bout.rb index 3c739f0..8206dbb 100644 --- a/app/models/bout.rb +++ b/app/models/bout.rb @@ -1,3 +1,24 @@ class Bout - + def assignBouts(tournament_id) + @round = 1 + until matchesByRound(@round, tournament_id).blank? do + @matches = matchesByRound(@round, tournament_id) + giveBout(@matches) + @round += 1 + end + end + + def matchesByRound(round, tournament_id) + @matches = Match.where(tournament_id: tournament_id, round: round) + return @matches + end + + def giveBout(matches) + @matches = matches.sort_by{|x|[x.weight_max]} + @matches.each_with_index do |m, i| + bout = m.round * 100 + i + m.boutNumber = bout + m.save + end + end end \ No newline at end of file diff --git a/app/models/match.rb b/app/models/match.rb index 524c9d4..3b89890 100644 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -1,6 +1,11 @@ class Match < ActiveRecord::Base belongs_to :tournament WIN_TYPES = ["Decision", "Major", "Tech Fall", "Pin", "Forfeit", "Injury Default", "Default"] - - + attr_accessor :weight_max + + def weight_max + @guy = Wrestler.find(self.r_id) + @weight = Weight.find(@guy.weight_id) + return @weight.max + end end diff --git a/app/models/pool.rb b/app/models/pool.rb index 7321477..9b88d94 100644 --- a/app/models/pool.rb +++ b/app/models/pool.rb @@ -46,7 +46,8 @@ class Pool end def roundRobin(pool,tournament,weight_id) - @wrestlers = Wrestler.where(weight_id: weight_id, poolNumber: pool).to_a + @wrestlers = Wrestler.where(weight_id: weight_id, poolNumber: pool) + @wrestlers.sort_by{|x|[x.original_seed]}.to_a @wrestlers.each_with_index do |w,index| next_guy_index = index+1 while index < @wrestlers.length && next_guy_index < @wrestlers.length diff --git a/app/models/tournament.rb b/app/models/tournament.rb index fd17f05..ac2aca0 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -3,14 +3,22 @@ class Tournament < ActiveRecord::Base has_many :weights, dependent: :destroy has_many :matches, dependent: :destroy has_many :mats, dependent: :destroy + attr_accessor :upcomingMatches + + def upcomingMatches + @matches = Match.where(tournament_id: self.id) + @matches.sort_by{|x|[x.boutNumber]} + # @matches.sort_by{|x|[x.round,x.weight.max]} + end + def generateMatches destroyAllMatches self.weights.each do |weight| - puts weight.inspect weight.generatePool end assignRound + assignBouts end def destroyAllMatches @@ -22,31 +30,33 @@ class Tournament < ActiveRecord::Base def assignRound @matches = Match.where(tournament_id: self.id) + @matches.sort_by{|x|[x.id]} @matches.each do |match| @round = 1 @w1 = Wrestler.find(match.r_id) @w2 = Wrestler.find(match.g_id) - checkRound(@w1,@w2,@round) - while checkRound(@w1,@w2,@round) == false - @round = @round + 1 + until wrestlingThisRound(@w1,@w2,@round) == false do + @round += 1 end match.round = @round match.save end end - def checkRound(w1,w2,round) + def assignBouts + @bouts = Bout.new + @bouts.assignBouts(self.id) + end + + def wrestlingThisRound(w1,w2,round) if w1.isWrestlingThisRound(round) == true or w2.isWrestlingThisRound(round) == true - puts "They wrestle this round" - return false - else - puts "They do not wrestle this round" return true + else + return false end end end -#@weights.sort_by{|x|[x.max]} diff --git a/app/models/weight.rb b/app/models/weight.rb index a892a9b..af41ced 100644 --- a/app/models/weight.rb +++ b/app/models/weight.rb @@ -20,9 +20,9 @@ class Weight < ActiveRecord::Base def pools @wrestlers = Wrestler.where(weight_id: self.id) - if @wrestlers.size <= 5 + if @wrestlers.size <= 6 self.pools = 1 - elsif (@wrestlers.size > 5) && (@wrestlers.size <= 8) + elsif (@wrestlers.size > 6) && (@wrestlers.size <= 8) self.pools = 2 elsif (@wrestlers.size > 8) && (@wrestlers.size <= 16) self.pools = 4 diff --git a/app/models/wrestler.rb b/app/models/wrestler.rb index 0194656..4613daf 100644 --- a/app/models/wrestler.rb +++ b/app/models/wrestler.rb @@ -3,14 +3,15 @@ class Wrestler < ActiveRecord::Base belongs_to :weight attr_accessor :matches_all, :isWrestlingThisRound - def isWrestlingThisRound(round) - @gMatches = Match.where(g_id: self.id, round: round) - @rMatches = Match.where(r_id: self.id, round: round) + def isWrestlingThisRound(matchRound) + @gMatches = Match.where(g_id: self.id, round: matchRound) + @rMatches = Match.where(r_id: self.id, round: matchRound) @allMatches = @gMatches + @rMatches - if @allMatches == nil - return true - else + if @gMatches.blank? and @rMatches.blank? return false + else + puts "He does wrestle this round" + return true end end diff --git a/app/views/static_pages/up_matches.html.erb b/app/views/static_pages/up_matches.html.erb index 456ac23..3b1c266 100644 --- a/app/views/static_pages/up_matches.html.erb +++ b/app/views/static_pages/up_matches.html.erb @@ -3,6 +3,6 @@

Upcoming Matches

<% @matches.each do |m| %> - <%= Wrestler.find(m.r_id).weight.max %> Lbs <%= Wrestler.find(m.r_id).name %> vs. <%= Wrestler.find(m.g_id).weight.max %> Lbs <%= Wrestler.find(m.g_id).name %> + Round <%= m.round %> Bout <%= m.boutNumber %> <%= Wrestler.find(m.r_id).weight.max %> Lbs <%= Wrestler.find(m.r_id).name %> vs. <%= Wrestler.find(m.g_id).weight.max %> Lbs <%= Wrestler.find(m.g_id).name %>
<% end %>