1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-03-25 01:14:43 +00:00

Got stuff working with matches being saved individually.

This commit is contained in:
2015-04-26 15:49:13 -04:00
parent 391e523b2e
commit dd44efa869
12 changed files with 97 additions and 128 deletions

View File

@@ -20,61 +20,8 @@ class Boutgen
giveBout(@matches)
@round += 1
end
assignLoserNames(matches,weights)
return matches
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

View 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

View File

@@ -4,11 +4,23 @@ class Match < ActiveRecord::Base
def w1_name
Wrestler.find(self.w1).name
if self.w1
Wrestler.find(self.w1).name
else
self.loser1_name
end
end
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

View File

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

View File

@@ -16,14 +16,11 @@ class Pool
@bout = b.map
@bout.each do |bout|
if bout[0] != nil and bout[1] != nil
@match = Matchup.new
@match = Match.new
@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
matches << @match
end
end

View File

@@ -64,14 +64,13 @@ class Poolbracket
end
def createMatchup(matches,weight,round,w1_name,w2_name,bracket_position,bracket_position_number)
@match = Matchup.new
@match.w1_name = w1_name
@match.w2_name = w2_name
@match = Match.new
@match.loser1_name = w1_name
@match.loser2_name = w2_name
@match.weight_id = weight.id
@match.round = round
@match.bracket_position = bracket_position
@match.bracket_position_number = bracket_position_number
@match.weight_max = weight.max
matches << @match
return matches
end

View File

@@ -8,12 +8,10 @@ class Tournament < ActiveRecord::Base
serialize :matchups_array
def upcomingMatches
# @matches = generateMatchups
if self.matches.nil?
return self.matches
else
@matches = generateMatchups
puts @matches.inspect
saveMatchups(@matches)
return @matches
end
@@ -25,6 +23,7 @@ class Tournament < ActiveRecord::Base
@matches = weight.generateMatchups(@matches)
end
@matches = assignBouts(@matches)
@matches = Losernamegen.new.assignLoserNames(@matches,self.weights)
return @matches
end
@@ -36,38 +35,9 @@ class Tournament < ActiveRecord::Base
def saveMatchups(matches)
matches.each do |m|
@match = Match.new
@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
m.save
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

View File

@@ -11,7 +11,7 @@ class Wrestler < ActiveRecord::Base
def isWrestlingThisRound(matchRound)
if allMatches(self.tournament.upcomingMatches).blank?
if allMatches.blank?
return false
else
return true
@@ -24,7 +24,7 @@ class Wrestler < ActiveRecord::Base
end
def boutByRound(round,matches)
@match = allMatches(matches).select{|m| m.round == round}.first
@match = allMatches.select{|m| m.round == round}.first
if @match.blank?
return "BYE"
else
@@ -32,8 +32,8 @@ class Wrestler < ActiveRecord::Base
end
end
def allMatches(matches)
@matches = matches.select{|m| m.w1 == self.id || m.w2 == self.id}
def allMatches
@matches = Match.where("w1 = ? or w2 = ?",self.id,self.id)
return @matches
end

View 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

View 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

View File

@@ -11,7 +11,7 @@
#
# 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|
t.integer "w1"
@@ -30,6 +30,8 @@ ActiveRecord::Schema.define(version: 20150425173224) do
t.integer "weight_id"
t.string "bracket_position"
t.integer "bracket_position_number"
t.string "loser1_name"
t.string "loser2_name"
end
create_table "mats", force: :cascade do |t|

View File

@@ -4,7 +4,7 @@ class PoolbracketMatchupsTest < ActionDispatch::IntegrationTest
def setup
@tournament = Tournament.find(1)
@tournament.upcomingMatches
@genMatchups = @tournament.generateMatchups
@genMatchups = @tournament.upcomingMatches
end
def createTournament(numberOfWrestlers)
@@ -24,7 +24,6 @@ class PoolbracketMatchupsTest < ActionDispatch::IntegrationTest
@school3.save
@weight3 = Weight.new
@weight3.id = @id
@weight3.max = 350
@weight3.tournament_id = @id
@weight3.save
until @count > numberOfWrestlers do
@@ -105,13 +104,7 @@ class PoolbracketMatchupsTest < ActionDispatch::IntegrationTest
@twentysix_matches = @genMatchups.select{|m| m.weight_max == 132}
assert_equal 32, @twentysix_matches.length
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
@count = 5