diff --git a/app/controllers/static_pages_controller.rb b/app/controllers/static_pages_controller.rb index 121c1fc..c0562a9 100644 --- a/app/controllers/static_pages_controller.rb +++ b/app/controllers/static_pages_controller.rb @@ -6,7 +6,7 @@ class StaticPagesController < ApplicationController def up_matches if params[:tournament] @tournament = Tournament.find(params[:tournament]) - end + end if @tournament @matches = @tournament.upcomingMatches end @@ -15,7 +15,7 @@ class StaticPagesController < ApplicationController def team_scores if params[:tournament] @tournament = Tournament.find(params[:tournament]) - end + end if @tournament @schools = School.where(tournament_id: @tournament.id) @schools.sort_by{|x|[x.score]} @@ -25,7 +25,7 @@ class StaticPagesController < ApplicationController def results if params[:tournament] @tournament = Tournament.find(params[:tournament]) - end + end if @tournament @matches = Match.where(tournament_id: @tournament.id) end @@ -51,7 +51,7 @@ class StaticPagesController < ApplicationController def weights if params[:tournament] @tournament = Tournament.find(params[:tournament]) - end + end if @tournament @weights = Weight.where(tournament_id: @tournament.id) @weights = @weights.sort_by{|x|[x.max]} diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index 24a8286..f23dd7e 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -11,9 +11,8 @@ class TournamentsController < ApplicationController # GET /tournaments/1.json def show @schools = @tournament.schools - @weights = @tournament.weights + @weights = @tournament.weights.sort_by{|x|[x.max]} @mats = @tournament.mats - @weights = @weights.sort_by{|x|[x.max]} end # GET /tournaments/new diff --git a/app/models/boutgen.rb b/app/models/boutgen.rb new file mode 100644 index 0000000..942ac6c --- /dev/null +++ b/app/models/boutgen.rb @@ -0,0 +1,25 @@ +class Boutgen + def matchesByRound(round, matches) + @matches = matches.select {|m| m.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 * 1000 + i + m.boutNumber = bout + end + return @matches + end + + def assignBouts(matches) + @round = 1 + until matchesByRound(@round, matches).blank? do + @matches = matchesByRound(@round, matches) + giveBout(@matches) + @round += 1 + end + return matches + end +end \ No newline at end of file diff --git a/app/models/match.rb b/app/models/match.rb index 69fbe66..b1d59b8 100644 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -2,19 +2,4 @@ class Match < ActiveRecord::Base belongs_to :tournament WIN_TYPES = ["Decision", "Major", "Tech Fall", "Pin", "Forfeit", "Injury Default", "Default", "DQ"] - def weight_max - @guy = Wrestler.find(self.r_id) - @weight = Weight.find(@guy.weight_id) - return @weight.max - end - - def w1_name - return Wrestler.find(self.r_id).name - end - - def w2_name - return Wrestler.find(self.g_id).name - end - - end diff --git a/app/models/pool.rb b/app/models/pool.rb index 3cb156b..467857b 100644 --- a/app/models/pool.rb +++ b/app/models/pool.rb @@ -4,7 +4,7 @@ class Pool @pool = 1 while @pool <= @pools matches = roundRobin(@pool,wrestlers,weight,tournament,matches) - @pool = @pool +1 + @pool = @pool + 1 end return matches end @@ -14,13 +14,13 @@ class Pool @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 + @bout.each do |bout| + if bout[0] != nil and bout[1] != nil @match = Matchup.new - @match.w1 = b[0].id - @match.w1_name = b[0].name - @match.w2 = b[1].id - @match.w2_name = b[1].name + @match.w1 = bout[0].id + @match.w1_name = bout[0].name + @match.w2 = bout[1].id + @match.w2_name = bout[1].name @match.weight_id = weight.id @match.round = index + 1 @match.weight_max = weight.max diff --git a/app/models/poolbracket.rb b/app/models/poolbracket.rb index 8be5629..28d671a 100644 --- a/app/models/poolbracket.rb +++ b/app/models/poolbracket.rb @@ -100,7 +100,7 @@ class Poolbracket end def assignBouts(matches) - @bouts = Bout.new + @bouts = Boutgen.new @matches = @bouts.assignBouts(matches) return @matches end diff --git a/app/models/tournament.rb b/app/models/tournament.rb index b1fa3e9..cf7d525 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -7,10 +7,6 @@ class Tournament < ActiveRecord::Base serialize :matchups_array - def unfinishedMatches - - end - def upcomingMatches if self.matchups_array return matchupHashesToObjects(self.matchups_array) @@ -18,15 +14,7 @@ class Tournament < ActiveRecord::Base @matches = generateMatchups saveMatchups(@matches) return @matches - end - end - - - def destroyAllMatches - @matches_all = Match.where(tournament_id: self.id) - @matches_all.each do |match| - match.destroy - end + end end def generateMatchups @@ -39,7 +27,7 @@ class Tournament < ActiveRecord::Base end def assignBouts(matches) - @bouts = Bout.new + @bouts = Boutgen.new @matches = @bouts.assignBouts(matches) return @matches end diff --git a/app/models/wrestler.rb b/app/models/wrestler.rb index 2641579..af41d55 100644 --- a/app/models/wrestler.rb +++ b/app/models/wrestler.rb @@ -11,10 +11,7 @@ class Wrestler < ActiveRecord::Base 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 @gMatches.blank? and @rMatches.blank? + if allMatches(self.tournament.upcomingMatches).blank? return false else return true @@ -27,8 +24,7 @@ class Wrestler < ActiveRecord::Base end def boutByRound(round,matches) - @matches = matches.select{|m| m.w1 == self.id || m.w2 == self.id} - @match = @matches.select{|m| m.round == round}.first + @match = allMatches(matches).select{|m| m.round == round}.first if @match.blank? return "BYE" else @@ -56,5 +52,4 @@ class Wrestler < ActiveRecord::Base return 0 end end - end diff --git a/app/views/weights/show.html.erb b/app/views/weights/show.html.erb index 11a22d4..931a44e 100644 --- a/app/views/weights/show.html.erb +++ b/app/views/weights/show.html.erb @@ -53,7 +53,9 @@ <% end %> - <%= submit_tag "Save"%> + <% if user_signed_in? %> + <%= submit_tag "Save"%> + <% end %> <% end %>