mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-04-17 13:24:36 +00:00
Got stuff working with matches being saved individually.
This commit is contained in:
@@ -20,61 +20,8 @@ class Boutgen
|
|||||||
giveBout(@matches)
|
giveBout(@matches)
|
||||||
@round += 1
|
@round += 1
|
||||||
end
|
end
|
||||||
assignLoserNames(matches,weights)
|
|
||||||
return matches
|
return matches
|
||||||
end
|
end
|
||||||
|
|
||||||
def assignLoserNames(matches,weights)
|
|
||||||
weights.each do |w|
|
|
||||||
@matches = matches.select{|m| m.weight_id == w.id}
|
|
||||||
if w.pool_bracket_type == "twoPoolsToSemi"
|
|
||||||
twoPoolsToSemiLoser(@matches)
|
|
||||||
elsif w.pool_bracket_type == "fourPoolsToQuarter"
|
|
||||||
fourPoolsToQuarterLoser(@matches)
|
|
||||||
elsif w.pool_bracket_type == "fourPoolsToSemi"
|
|
||||||
fourPoolsToSemiLoser(@matches)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def twoPoolsToSemiLoser(matches)
|
|
||||||
@match1 = matches.select{|m| m.w1_name == "Winner Pool 1"}.first
|
|
||||||
@match2 = matches.select{|m| m.w1_name == "Winner Pool 2"}.first
|
|
||||||
@matchChange = matches.select{|m| m.bracket_position == "3/4"}.first
|
|
||||||
@matchChange.w1_name = "Loser of #{@match1.boutNumber}"
|
|
||||||
@matchChange.w2_name = "Loser of #{@match2.boutNumber}"
|
|
||||||
end
|
|
||||||
|
|
||||||
def fourPoolsToQuarterLoser(matches)
|
|
||||||
@quarters = matches.select{|m| m.bracket_position == "Quarter"}
|
|
||||||
@consoSemis = matches.select{|m| m.bracket_position == "Conso Semis"}
|
|
||||||
@semis = matches.select{|m| m.bracket_position == "Semis"}
|
|
||||||
@thirdFourth = matches.select{|m| m.bracket_position == "3/4"}.first
|
|
||||||
@seventhEighth = matches.select{|m| m.bracket_position == "7/8"}.first
|
|
||||||
@consoSemis.each do |match|
|
|
||||||
if match.bracket_position_number == 1
|
|
||||||
match.w1_name = "Loser of #{@quarters.select{|m| m.bracket_position_number == 1}.first.boutNumber}"
|
|
||||||
match.w2_name = "Loser of #{@quarters.select{|m| m.bracket_position_number == 2}.first.boutNumber}"
|
|
||||||
elsif match.bracket_position_number == 2
|
|
||||||
match.w1_name = "Loser of #{@quarters.select{|m| m.bracket_position_number == 3}.first.boutNumber}"
|
|
||||||
match.w2_name = "Loser of #{@quarters.select{|m| m.bracket_position_number == 4}.first.boutNumber}"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@thirdFourth.w1_name = "Loser of #{@semis.select{|m| m.bracket_position_number == 1}.first.boutNumber}"
|
|
||||||
@thirdFourth.w2_name = "Loser of #{@semis.select{|m| m.bracket_position_number == 2}.first.boutNumber}"
|
|
||||||
@consoSemis = matches.select{|m| m.bracket_position == "Conso Semis"}
|
|
||||||
@seventhEighth.w1_name = "Loser of #{@consoSemis.select{|m| m.bracket_position_number == 1}.first.boutNumber}"
|
|
||||||
@seventhEighth.w2_name = "Loser of #{@consoSemis.select{|m| m.bracket_position_number == 2}.first.boutNumber}"
|
|
||||||
end
|
|
||||||
|
|
||||||
def fourPoolsToSemiLoser(matches)
|
|
||||||
@semis = matches.select{|m| m.bracket_position == "Semis"}
|
|
||||||
@thirdFourth = matches.select{|m| m.bracket_position == "3/4"}.first
|
|
||||||
@consoSemis = matches.select{|m| m.bracket_position == "Conso Semis"}
|
|
||||||
@seventhEighth = matches.select{|m| m.bracket_position == "7/8"}.first
|
|
||||||
@thirdFourth.w1_name = "Loser of #{@semis.select{|m| m.bracket_position_number == 1}.first.boutNumber}"
|
|
||||||
@thirdFourth.w2_name = "Loser of #{@semis.select{|m| m.bracket_position_number == 2}.first.boutNumber}"
|
|
||||||
@seventhEighth.w1_name = "Loser of #{@consoSemis.select{|m| m.bracket_position_number == 1}.first.boutNumber}"
|
|
||||||
@seventhEighth.w2_name = "Loser of #{@consoSemis.select{|m| m.bracket_position_number == 2}.first.boutNumber}"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
56
app/models/losernamegen.rb
Normal file
56
app/models/losernamegen.rb
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
class Losernamegen
|
||||||
|
def assignLoserNames(matches,weights)
|
||||||
|
weights.each do |w|
|
||||||
|
@matches = matches.select{|m| m.weight_id == w.id}
|
||||||
|
if w.pool_bracket_type == "twoPoolsToSemi"
|
||||||
|
twoPoolsToSemiLoser(@matches)
|
||||||
|
elsif w.pool_bracket_type == "fourPoolsToQuarter"
|
||||||
|
fourPoolsToQuarterLoser(@matches)
|
||||||
|
elsif w.pool_bracket_type == "fourPoolsToSemi"
|
||||||
|
fourPoolsToSemiLoser(@matches)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return matches
|
||||||
|
end
|
||||||
|
|
||||||
|
def twoPoolsToSemiLoser(matches)
|
||||||
|
@match1 = matches.select{|m| m.loser1_name == "Winner Pool 1"}.first
|
||||||
|
@match2 = matches.select{|m| m.loser1_name == "Winner Pool 2"}.first
|
||||||
|
@matchChange = matches.select{|m| m.bracket_position == "3/4"}.first
|
||||||
|
@matchChange.loser1_name = "Loser of #{@match1.boutNumber}"
|
||||||
|
@matchChange.loser2_name = "Loser of #{@match2.boutNumber}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def fourPoolsToQuarterLoser(matches)
|
||||||
|
@quarters = matches.select{|m| m.bracket_position == "Quarter"}
|
||||||
|
@consoSemis = matches.select{|m| m.bracket_position == "Conso Semis"}
|
||||||
|
@semis = matches.select{|m| m.bracket_position == "Semis"}
|
||||||
|
@thirdFourth = matches.select{|m| m.bracket_position == "3/4"}.first
|
||||||
|
@seventhEighth = matches.select{|m| m.bracket_position == "7/8"}.first
|
||||||
|
@consoSemis.each do |match|
|
||||||
|
if match.bracket_position_number == 1
|
||||||
|
match.loser1_name = "Loser of #{@quarters.select{|m| m.bracket_position_number == 1}.first.boutNumber}"
|
||||||
|
match.loser2_name = "Loser of #{@quarters.select{|m| m.bracket_position_number == 2}.first.boutNumber}"
|
||||||
|
elsif match.bracket_position_number == 2
|
||||||
|
match.loser1_name = "Loser of #{@quarters.select{|m| m.bracket_position_number == 3}.first.boutNumber}"
|
||||||
|
match.loser2_name = "Loser of #{@quarters.select{|m| m.bracket_position_number == 4}.first.boutNumber}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
@thirdFourth.loser1_name = "Loser of #{@semis.select{|m| m.bracket_position_number == 1}.first.boutNumber}"
|
||||||
|
@thirdFourth.loser2_name = "Loser of #{@semis.select{|m| m.bracket_position_number == 2}.first.boutNumber}"
|
||||||
|
@consoSemis = matches.select{|m| m.bracket_position == "Conso Semis"}
|
||||||
|
@seventhEighth.loser1_name = "Loser of #{@consoSemis.select{|m| m.bracket_position_number == 1}.first.boutNumber}"
|
||||||
|
@seventhEighth.loser2_name = "Loser of #{@consoSemis.select{|m| m.bracket_position_number == 2}.first.boutNumber}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def fourPoolsToSemiLoser(matches)
|
||||||
|
@semis = matches.select{|m| m.bracket_position == "Semis"}
|
||||||
|
@thirdFourth = matches.select{|m| m.bracket_position == "3/4"}.first
|
||||||
|
@consoSemis = matches.select{|m| m.bracket_position == "Conso Semis"}
|
||||||
|
@seventhEighth = matches.select{|m| m.bracket_position == "7/8"}.first
|
||||||
|
@thirdFourth.loser1_name = "Loser of #{@semis.select{|m| m.bracket_position_number == 1}.first.boutNumber}"
|
||||||
|
@thirdFourth.loser2_name = "Loser of #{@semis.select{|m| m.bracket_position_number == 2}.first.boutNumber}"
|
||||||
|
@seventhEighth.loser1_name = "Loser of #{@consoSemis.select{|m| m.bracket_position_number == 1}.first.boutNumber}"
|
||||||
|
@seventhEighth.loser2_name = "Loser of #{@consoSemis.select{|m| m.bracket_position_number == 2}.first.boutNumber}"
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -4,11 +4,23 @@ class Match < ActiveRecord::Base
|
|||||||
|
|
||||||
|
|
||||||
def w1_name
|
def w1_name
|
||||||
Wrestler.find(self.w1).name
|
if self.w1
|
||||||
|
Wrestler.find(self.w1).name
|
||||||
|
else
|
||||||
|
self.loser1_name
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def w2_name
|
def w2_name
|
||||||
Wrestler.find(self.w2).name
|
if self.w2
|
||||||
|
Wrestler.find(self.w2).name
|
||||||
|
else
|
||||||
|
self.loser2_name
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def weight_max
|
||||||
|
Weight.find(self.weight_id).max
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
class Matchup
|
|
||||||
attr_accessor :w1, :w2, :round, :weight_id, :boutNumber, :w1_name, :w2_name, :bracket_position, :bracket_position_number, :weight_max
|
|
||||||
|
|
||||||
def to_hash
|
|
||||||
hash = {}
|
|
||||||
instance_variables.each {|var| hash[var.to_s.delete("@")] = instance_variable_get(var) }
|
|
||||||
hash
|
|
||||||
end
|
|
||||||
|
|
||||||
def convert_to_obj(h)
|
|
||||||
h.each do |k,v|
|
|
||||||
self.class.send(:attr_accessor, k)
|
|
||||||
instance_variable_set("@#{k}", v)
|
|
||||||
convert_to_obj(v) if v.is_a? Hash
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
end
|
|
||||||
@@ -16,14 +16,11 @@ class Pool
|
|||||||
@bout = b.map
|
@bout = b.map
|
||||||
@bout.each do |bout|
|
@bout.each do |bout|
|
||||||
if bout[0] != nil and bout[1] != nil
|
if bout[0] != nil and bout[1] != nil
|
||||||
@match = Matchup.new
|
@match = Match.new
|
||||||
@match.w1 = bout[0].id
|
@match.w1 = bout[0].id
|
||||||
@match.w1_name = bout[0].name
|
|
||||||
@match.w2 = bout[1].id
|
@match.w2 = bout[1].id
|
||||||
@match.w2_name = bout[1].name
|
|
||||||
@match.weight_id = weight.id
|
@match.weight_id = weight.id
|
||||||
@match.round = index + 1
|
@match.round = index + 1
|
||||||
@match.weight_max = weight.max
|
|
||||||
matches << @match
|
matches << @match
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -64,14 +64,13 @@ class Poolbracket
|
|||||||
end
|
end
|
||||||
|
|
||||||
def createMatchup(matches,weight,round,w1_name,w2_name,bracket_position,bracket_position_number)
|
def createMatchup(matches,weight,round,w1_name,w2_name,bracket_position,bracket_position_number)
|
||||||
@match = Matchup.new
|
@match = Match.new
|
||||||
@match.w1_name = w1_name
|
@match.loser1_name = w1_name
|
||||||
@match.w2_name = w2_name
|
@match.loser2_name = w2_name
|
||||||
@match.weight_id = weight.id
|
@match.weight_id = weight.id
|
||||||
@match.round = round
|
@match.round = round
|
||||||
@match.bracket_position = bracket_position
|
@match.bracket_position = bracket_position
|
||||||
@match.bracket_position_number = bracket_position_number
|
@match.bracket_position_number = bracket_position_number
|
||||||
@match.weight_max = weight.max
|
|
||||||
matches << @match
|
matches << @match
|
||||||
return matches
|
return matches
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -8,12 +8,10 @@ class Tournament < ActiveRecord::Base
|
|||||||
serialize :matchups_array
|
serialize :matchups_array
|
||||||
|
|
||||||
def upcomingMatches
|
def upcomingMatches
|
||||||
# @matches = generateMatchups
|
|
||||||
if self.matches.nil?
|
if self.matches.nil?
|
||||||
return self.matches
|
return self.matches
|
||||||
else
|
else
|
||||||
@matches = generateMatchups
|
@matches = generateMatchups
|
||||||
puts @matches.inspect
|
|
||||||
saveMatchups(@matches)
|
saveMatchups(@matches)
|
||||||
return @matches
|
return @matches
|
||||||
end
|
end
|
||||||
@@ -25,6 +23,7 @@ class Tournament < ActiveRecord::Base
|
|||||||
@matches = weight.generateMatchups(@matches)
|
@matches = weight.generateMatchups(@matches)
|
||||||
end
|
end
|
||||||
@matches = assignBouts(@matches)
|
@matches = assignBouts(@matches)
|
||||||
|
@matches = Losernamegen.new.assignLoserNames(@matches,self.weights)
|
||||||
return @matches
|
return @matches
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -36,39 +35,10 @@ class Tournament < ActiveRecord::Base
|
|||||||
|
|
||||||
def saveMatchups(matches)
|
def saveMatchups(matches)
|
||||||
matches.each do |m|
|
matches.each do |m|
|
||||||
@match = Match.new
|
m.save
|
||||||
@match.w1 = m.w1
|
|
||||||
@match.w2 = m.w2
|
|
||||||
@match.round = m.round
|
|
||||||
@match.boutNumber = m.boutNumber
|
|
||||||
@match.bracket_position = m.bracket_position
|
|
||||||
@match.bracket_position_number = m.bracket_position_number
|
|
||||||
@match.tournament_id = self.id
|
|
||||||
puts @match.inspect
|
|
||||||
@match.save
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def matchupObjectsToHash(matches)
|
|
||||||
array_of_hashes = []
|
|
||||||
matches.each do |m|
|
|
||||||
@matchHash = m.to_hash
|
|
||||||
array_of_hashes << @matchHash
|
|
||||||
end
|
|
||||||
return array_of_hashes
|
|
||||||
end
|
|
||||||
|
|
||||||
def matchupHashesToObjects(matches)
|
|
||||||
array_of_objects = []
|
|
||||||
matches.each do |m|
|
|
||||||
@match = Matchup.new
|
|
||||||
@match.convert_to_obj(m)
|
|
||||||
array_of_objects << @match
|
|
||||||
end
|
|
||||||
return array_of_objects
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ class Wrestler < ActiveRecord::Base
|
|||||||
|
|
||||||
|
|
||||||
def isWrestlingThisRound(matchRound)
|
def isWrestlingThisRound(matchRound)
|
||||||
if allMatches(self.tournament.upcomingMatches).blank?
|
if allMatches.blank?
|
||||||
return false
|
return false
|
||||||
else
|
else
|
||||||
return true
|
return true
|
||||||
@@ -24,7 +24,7 @@ class Wrestler < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def boutByRound(round,matches)
|
def boutByRound(round,matches)
|
||||||
@match = allMatches(matches).select{|m| m.round == round}.first
|
@match = allMatches.select{|m| m.round == round}.first
|
||||||
if @match.blank?
|
if @match.blank?
|
||||||
return "BYE"
|
return "BYE"
|
||||||
else
|
else
|
||||||
@@ -32,8 +32,8 @@ class Wrestler < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def allMatches(matches)
|
def allMatches
|
||||||
@matches = matches.select{|m| m.w1 == self.id || m.w2 == self.id}
|
@matches = Match.where("w1 = ? or w2 = ?",self.id,self.id)
|
||||||
return @matches
|
return @matches
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
6
db/migrate/20150426190405_add_w_names_to_match.rb
Normal file
6
db/migrate/20150426190405_add_w_names_to_match.rb
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
class AddWNamesToMatch < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :matches, :w1_name, :string
|
||||||
|
add_column :matches, :w2_name, :string
|
||||||
|
end
|
||||||
|
end
|
||||||
6
db/migrate/20150426191006_change_w_name_to_loser_name.rb
Normal file
6
db/migrate/20150426191006_change_w_name_to_loser_name.rb
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
class ChangeWNameToLoserName < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
rename_column :matches, :w1_name, :loser1_name
|
||||||
|
rename_column :matches, :w2_name, :loser2_name
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20150425173224) do
|
ActiveRecord::Schema.define(version: 20150426191006) do
|
||||||
|
|
||||||
create_table "matches", force: :cascade do |t|
|
create_table "matches", force: :cascade do |t|
|
||||||
t.integer "w1"
|
t.integer "w1"
|
||||||
@@ -30,6 +30,8 @@ ActiveRecord::Schema.define(version: 20150425173224) do
|
|||||||
t.integer "weight_id"
|
t.integer "weight_id"
|
||||||
t.string "bracket_position"
|
t.string "bracket_position"
|
||||||
t.integer "bracket_position_number"
|
t.integer "bracket_position_number"
|
||||||
|
t.string "loser1_name"
|
||||||
|
t.string "loser2_name"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "mats", force: :cascade do |t|
|
create_table "mats", force: :cascade do |t|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ class PoolbracketMatchupsTest < ActionDispatch::IntegrationTest
|
|||||||
def setup
|
def setup
|
||||||
@tournament = Tournament.find(1)
|
@tournament = Tournament.find(1)
|
||||||
@tournament.upcomingMatches
|
@tournament.upcomingMatches
|
||||||
@genMatchups = @tournament.generateMatchups
|
@genMatchups = @tournament.upcomingMatches
|
||||||
end
|
end
|
||||||
|
|
||||||
def createTournament(numberOfWrestlers)
|
def createTournament(numberOfWrestlers)
|
||||||
@@ -24,7 +24,6 @@ class PoolbracketMatchupsTest < ActionDispatch::IntegrationTest
|
|||||||
@school3.save
|
@school3.save
|
||||||
@weight3 = Weight.new
|
@weight3 = Weight.new
|
||||||
@weight3.id = @id
|
@weight3.id = @id
|
||||||
@weight3.max = 350
|
|
||||||
@weight3.tournament_id = @id
|
@weight3.tournament_id = @id
|
||||||
@weight3.save
|
@weight3.save
|
||||||
until @count > numberOfWrestlers do
|
until @count > numberOfWrestlers do
|
||||||
@@ -106,12 +105,6 @@ class PoolbracketMatchupsTest < ActionDispatch::IntegrationTest
|
|||||||
assert_equal 32, @twentysix_matches.length
|
assert_equal 32, @twentysix_matches.length
|
||||||
end
|
end
|
||||||
|
|
||||||
test "tests serialization for matchups" do
|
|
||||||
@tournament_saved = Tournament.find(1)
|
|
||||||
@genMatchup = @genMatchups.select{|m| m.boutNumber == 4000}.first
|
|
||||||
@matchup = @tournament_saved.upcomingMatches.select{|m| m.boutNumber == 4000}.first
|
|
||||||
assert_equal @genMatchup.w1_name, @matchup.w1_name
|
|
||||||
end
|
|
||||||
|
|
||||||
test "test if a wrestler can exceed five matches" do
|
test "test if a wrestler can exceed five matches" do
|
||||||
@count = 5
|
@count = 5
|
||||||
|
|||||||
Reference in New Issue
Block a user