1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-03-24 17:04:43 +00:00

Working on generating rounds in tournament model

This commit is contained in:
2015-02-02 15:45:46 -05:00
parent 9de0215a5e
commit 7ea80b2997
8 changed files with 78 additions and 9 deletions

24
.project Normal file
View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>wrestling</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.rubypeople.rdt.core.rubybuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.aptana.ide.core.unifiedBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.aptana.ide.project.nature.web</nature>
<nature>org.rubypeople.rdt.core.rubynature</nature>
<nature>org.radrails.rails.core.railsnature</nature>
</natures>
</projectDescription>

3
app/models/bout.rb Normal file
View File

@@ -0,0 +1,3 @@
class Bout
end

View File

@@ -1,6 +1,6 @@
class Match < ActiveRecord::Base
belongs_to :tournament
WIN_TYPES = ["Decision", "Major", "Tech Fall", "Pin", "Forfeit", "Injury Default", "Default"]
end

View File

@@ -65,7 +65,6 @@ class Pool
@match.g_id = w2
@match.tournament_id = tournament
@match.save
puts @match.inspect
end
end

View File

@@ -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]}

View File

@@ -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

View File

@@ -0,0 +1,5 @@
class AddBoutNumberToMatch < ActiveRecord::Migration
def change
add_column :matches, :boutNumber, :integer
end
end

View File

@@ -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|