diff --git a/app/models/poolbracket.rb b/app/models/poolbracket.rb index aa99e24..561b793 100644 --- a/app/models/poolbracket.rb +++ b/app/models/poolbracket.rb @@ -28,6 +28,7 @@ class Poolbracket @round = round + 1 matches = createMatchup(matches,weight,@round,"Winner Pool 1","Winner Pool 2","1/2",1) matches = createMatchup(matches,weight,@round,"Runner Up Pool 1","Runner Up Pool 2","3/4",1) + return matches end def fourPoolsToQuarter(matches,weight,round) diff --git a/app/models/tournament.rb b/app/models/tournament.rb index 3c97ddb..9fe683b 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -5,48 +5,31 @@ class Tournament < ActiveRecord::Base has_many :wrestlers, through: :weights + def tournament_types + ["Pool to bracket"] + end + def matches @matches = Match.where(tournament_id: self.id) end + + def upcomingMatches if matches.nil? return matches else - @matches = generateMatchups - saveMatchups(@matches) - return @matches + generateMatchups + return matches end end def generateMatchups - destroyAllMatches - @matches = [] - self.weights.map.sort_by{|x|[x.max]}.each do |weight| - @matches = weight.generateMatchups(@matches) - end - @matches = assignBouts(@matches) - @matches = Losernamegen.new.assignLoserNames(@matches,self.weights) - return @matches - end - - def assignBouts(matches) - @bouts = Boutgen.new - @matches = @bouts.assignBouts(matches,self.weights) - return @matches - end - - def saveMatchups(matches) - matches.each do |m| - m.tournament_id = self.id - m.save - end + @matches = Tournamentmatchgen.new.genMatches(self) end def destroyAllMatches - matches.each do |m| - m.destroy - end + matches.destroy_all end end diff --git a/app/models/tournamentMatchGen.rb b/app/models/tournamentMatchGen.rb new file mode 100644 index 0000000..b463acb --- /dev/null +++ b/app/models/tournamentMatchGen.rb @@ -0,0 +1,33 @@ +class Tournamentmatchgen + def genMatches(tournament) + if tournament.tournament_type == "Pool to bracket" + @matches = poolToBracket(tournament) + end + return @matches + end + + def poolToBracket(tournament) + tournament.destroyAllMatches + @matches = [] + tournament.weights.sort_by{|x|[x.max]}.each do |w| + @wrestlers = w.wrestlers + @matches = Pool.new.generatePools(w.pools,@wrestlers,w,tournament.id,@matches) + @weight_matches = @matches.select{|m|m.weight_id == w.id} + @last_match = @weight_matches.sort_by{|m| m.round}.last + @highest_round = @last_match.round + @matches = Poolbracket.new.generateBracketMatches(@matches,w,@highest_round) + end + @matches = Boutgen.new.assignBouts(@matches,tournament.weights) + @matches = Losernamegen.new.assignLoserNames(@matches,tournament.weights) + saveMatches(tournament,@matches) + return @matches + end + + def saveMatches(tournament,matches) + matches.each do |m| + m.tournament_id = tournament.id + m.save + end + end +end + diff --git a/app/models/weight.rb b/app/models/weight.rb index 83a3754..0298e8b 100644 --- a/app/models/weight.rb +++ b/app/models/weight.rb @@ -101,18 +101,6 @@ class Weight < ActiveRecord::Base return "fourPoolsToSemi" end end - - def generateMatchups(matches) - @wrestlers = self.wrestlers - @pool = Pool.new - @matches = @pool.generatePools(self.pools,@wrestlers,self,self.tournament_id,matches) - @weight_matches = @matches.select{|m|m.weight_id == self.id} - @last_match = @weight_matches.sort_by{|m| m.round}.last - @highest_round = @last_match.round - @bracket = Poolbracket.new - @matches = @bracket.generateBracketMatches(@matches,self,@highest_round) - return @matches - end def poolRounds(matches) @matchups = matches.select{|m| m.weight_id == self.id} diff --git a/app/views/tournaments/_form.html.erb b/app/views/tournaments/_form.html.erb index 2a463e2..7b22b04 100644 --- a/app/views/tournaments/_form.html.erb +++ b/app/views/tournaments/_form.html.erb @@ -27,6 +27,12 @@ <%= f.label :director_email %>
<%= f.text_field :director_email %> +
+ <%= f.label :tournament_type %>
+ <%= f.select :tournament_type, @tournament.tournament_types %> +
+
+
<%= f.submit %>
diff --git a/db/migrate/20150427163325_add_type_to_tournament.rb b/db/migrate/20150427163325_add_type_to_tournament.rb new file mode 100644 index 0000000..03fe083 --- /dev/null +++ b/db/migrate/20150427163325_add_type_to_tournament.rb @@ -0,0 +1,5 @@ +class AddTypeToTournament < ActiveRecord::Migration + def change + add_column :tournaments, :type, :text + end +end diff --git a/db/migrate/20150427163625_rename_type_to_tournament_type.rb b/db/migrate/20150427163625_rename_type_to_tournament_type.rb new file mode 100644 index 0000000..94faa44 --- /dev/null +++ b/db/migrate/20150427163625_rename_type_to_tournament_type.rb @@ -0,0 +1,4 @@ +class RenameTypeToTournamentType < ActiveRecord::Migration + def change + end +end diff --git a/db/migrate/20150427163818_rename_type_to_tournament_type_for_real.rb b/db/migrate/20150427163818_rename_type_to_tournament_type_for_real.rb new file mode 100644 index 0000000..ade959e --- /dev/null +++ b/db/migrate/20150427163818_rename_type_to_tournament_type_for_real.rb @@ -0,0 +1,5 @@ +class RenameTypeToTournamentTypeForReal < ActiveRecord::Migration + def change + rename_column :tournaments, :type, :tournament_type + end +end diff --git a/db/schema.rb b/db/schema.rb index 4cf1be0..1dd957b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150426195714) do +ActiveRecord::Schema.define(version: 20150427163818) do create_table "matches", force: :cascade do |t| t.integer "w1" @@ -55,6 +55,7 @@ ActiveRecord::Schema.define(version: 20150426195714) do t.string "director_email" t.datetime "created_at" t.datetime "updated_at" + t.text "tournament_type" end create_table "users", force: :cascade do |t| diff --git a/db/seeds.rb b/db/seeds.rb index 0d8e017..7f35e4a 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -7,7 +7,7 @@ # Mayor.create(name: 'Emanuel', city: cities.first) if Rails.env.development? User.create(email: 'test@test.com', password: 'password', password_confirmation: 'password') - Tournament.create(id: 200, name: 'test', address: 'some place', director: 'some guy', director_email: 'hismail@email.com') + Tournament.create(id: 200, name: 'test', address: 'some place', director: 'some guy', director_email: 'hismail@email.com', tournament_type: 'Pool to bracket') School.create(id: 200, name: 'Central Crossing', tournament_id: 200) School.create(id: 201, name: 'Turd Town', tournament_id: 200) School.create(id: 202, name: 'Shit Show', tournament_id: 200) diff --git a/test/fixtures/tournaments.yml b/test/fixtures/tournaments.yml index 24c6945..fca58d5 100644 --- a/test/fixtures/tournaments.yml +++ b/test/fixtures/tournaments.yml @@ -6,7 +6,7 @@ one: address: Some Place director: Jacob Cody Wimer director_email: jacob.wimer@gmail.com - + tournament_type: Pool to bracket diff --git a/test/integration/poolbracket_matchups_test.rb b/test/integration/poolbracket_matchups_test.rb index 8ec7601..2694b5c 100644 --- a/test/integration/poolbracket_matchups_test.rb +++ b/test/integration/poolbracket_matchups_test.rb @@ -12,6 +12,7 @@ class PoolbracketMatchupsTest < ActionDispatch::IntegrationTest @id = 6000 + numberOfWrestlers @tournament3 = Tournament.new @tournament3.id = @id + @tournament3.tournament_type = "Pool to bracket" @tournament3.name = "Something" @tournament3.address = "Some Place" @tournament3.director = "Some Guy"