From 7ea80b2997c42bf5fdfbc6693bdf9e02171c3909 Mon Sep 17 00:00:00 2001 From: Jacob Cody Wimer Date: Mon, 2 Feb 2015 15:45:46 -0500 Subject: [PATCH] Working on generating rounds in tournament model --- .project | 24 +++++++++++++++ app/models/bout.rb | 3 ++ app/models/match.rb | 2 +- app/models/pool.rb | 1 - app/models/tournament.rb | 30 +++++++++++++++++++ app/models/wrestler.rb | 19 ++++++++---- ...20150202180900_add_bout_number_to_match.rb | 5 ++++ db/schema.rb | 3 +- 8 files changed, 78 insertions(+), 9 deletions(-) create mode 100644 .project create mode 100644 app/models/bout.rb create mode 100644 db/migrate/20150202180900_add_bout_number_to_match.rb diff --git a/.project b/.project new file mode 100644 index 0000000..6cfbe13 --- /dev/null +++ b/.project @@ -0,0 +1,24 @@ + + + wrestling + + + + + + org.rubypeople.rdt.core.rubybuilder + + + + + com.aptana.ide.core.unifiedBuilder + + + + + + com.aptana.ide.project.nature.web + org.rubypeople.rdt.core.rubynature + org.radrails.rails.core.railsnature + + diff --git a/app/models/bout.rb b/app/models/bout.rb new file mode 100644 index 0000000..3c739f0 --- /dev/null +++ b/app/models/bout.rb @@ -0,0 +1,3 @@ +class Bout + +end \ No newline at end of file diff --git a/app/models/match.rb b/app/models/match.rb index 7bca276..524c9d4 100644 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -1,6 +1,6 @@ class Match < ActiveRecord::Base belongs_to :tournament WIN_TYPES = ["Decision", "Major", "Tech Fall", "Pin", "Forfeit", "Injury Default", "Default"] - + end diff --git a/app/models/pool.rb b/app/models/pool.rb index 29e377b..7321477 100644 --- a/app/models/pool.rb +++ b/app/models/pool.rb @@ -65,7 +65,6 @@ class Pool @match.g_id = w2 @match.tournament_id = tournament @match.save - puts @match.inspect end end \ No newline at end of file diff --git a/app/models/tournament.rb b/app/models/tournament.rb index 6f67795..fd17f05 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -10,6 +10,7 @@ class Tournament < ActiveRecord::Base puts weight.inspect weight.generatePool end + assignRound end def destroyAllMatches @@ -19,4 +20,33 @@ class Tournament < ActiveRecord::Base end end + def assignRound + @matches = Match.where(tournament_id: self.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 + end + match.round = @round + match.save + end + end + + def checkRound(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 + end + end end + +#@weights.sort_by{|x|[x.max]} + + diff --git a/app/models/wrestler.rb b/app/models/wrestler.rb index a97d4a4..0194656 100644 --- a/app/models/wrestler.rb +++ b/app/models/wrestler.rb @@ -1,16 +1,23 @@ class Wrestler < ActiveRecord::Base belongs_to :school belongs_to :weight - has_many :matches + attr_accessor :matches_all, :isWrestlingThisRound - def isWrestlingThisRound?(round) - @r = Match.where(r_id: self.id, round: round) - @g = Match.where(g_id: self.id, round: round) - if @r or @g + def isWrestlingThisRound(round) + @gMatches = Match.where(g_id: self.id, round: round) + @rMatches = Match.where(r_id: self.id, round: round) + @allMatches = @gMatches + @rMatches + if @allMatches == nil return true else return false - end + end + end + + def matches_all + @gMatches = Match.where(g_id: self.id) + @rMatches = Match.where(r_id: self.id) + return @gMatches + @rMatches end end diff --git a/db/migrate/20150202180900_add_bout_number_to_match.rb b/db/migrate/20150202180900_add_bout_number_to_match.rb new file mode 100644 index 0000000..4db5814 --- /dev/null +++ b/db/migrate/20150202180900_add_bout_number_to_match.rb @@ -0,0 +1,5 @@ +class AddBoutNumberToMatch < ActiveRecord::Migration + def change + add_column :matches, :boutNumber, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 5e72049..b56cce8 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: 20141226133941) do +ActiveRecord::Schema.define(version: 20150202180900) do create_table "matches", force: true do |t| t.integer "r_id" @@ -26,6 +26,7 @@ ActiveRecord::Schema.define(version: 20141226133941) do t.integer "tournament_id" t.integer "round" t.integer "finished" + t.integer "boutNumber" end create_table "mats", force: true do |t|