1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-04-20 06:02:39 +00:00

Speeding up tests and renaming a few methods in generateMatchups

This commit is contained in:
2016-03-26 03:54:31 +00:00
parent f66725d750
commit ddcf2d807e
17 changed files with 2814 additions and 729 deletions

View File

@@ -60,3 +60,4 @@ gem 'spring', :group => :development
#gem 'bullet' #gem 'bullet'
end end

View File

@@ -8,7 +8,6 @@ module GeneratesTournamentMatches
poolToBracket() if tournament_type == "Pool to bracket" poolToBracket() if tournament_type == "Pool to bracket"
self.curently_generating_matches = nil self.curently_generating_matches = nil
self.save self.save
matches
end end
if Rails.env.production? if Rails.env.production?
handle_asynchronously :generateMatchups handle_asynchronously :generateMatchups
@@ -16,13 +15,11 @@ module GeneratesTournamentMatches
def poolToBracket def poolToBracket
destroyAllMatches destroyAllMatches
buildTournamentWeights generatePoolToBracketMatches
generateMatches poolToBracketPostMatchCreation
# This is not working for pool order and I cannot get tests working
movePoolSeedsToFinalPoolRound
end end
def buildTournamentWeights def generatePoolToBracketMatches
weights.order(:max).each do |weight| weights.order(:max).each do |weight|
Pool.new(weight).generatePools() Pool.new(weight).generatePools()
last_match = matches.where(weight: weight).order(round: :desc).limit(1).first last_match = matches.where(weight: weight).order(round: :desc).limit(1).first
@@ -31,11 +28,12 @@ module GeneratesTournamentMatches
end end
end end
def generateMatches def poolToBracketPostMatchCreation
moveFinalsMatchesToLastRound moveFinalsMatchesToLastRound
assignBouts assignBouts
assignLoserNames assignLoserNames
assignFirstMatchesToMats assignFirstMatchesToMats
movePoolSeedsToFinalPoolRound
end end
def moveFinalsMatchesToLastRound def moveFinalsMatchesToLastRound

View File

@@ -7,6 +7,10 @@ class Match < ActiveRecord::Base
after_update do after_update do
after_update_actions
end
def after_update_actions
if self.finished == 1 && self.winner_id != nil if self.finished == 1 && self.winner_id != nil
if self.w1 && self.w2 if self.w1 && self.w2
wrestler1.touch wrestler1.touch

View File

@@ -6,17 +6,14 @@ class Pool
end end
def generatePools def generatePools
matches = []
pools = @weight.pools pools = @weight.pools
while @pool <= pools while @pool <= pools
matches += roundRobin() roundRobin
@pool += 1 @pool += 1
end end
return matches
end end
def roundRobin def roundRobin
matches = []
wrestlers = @weight.wrestlersForPool(@pool) wrestlers = @weight.wrestlersForPool(@pool)
poolMatches = RoundRobinTournament.schedule(wrestlers).reverse poolMatches = RoundRobinTournament.schedule(wrestlers).reverse
poolMatches.each_with_index do |b, index| poolMatches.each_with_index do |b, index|
@@ -24,16 +21,14 @@ class Pool
bouts = b.map bouts = b.map
bouts.each do |bout| bouts.each do |bout|
if bout[0] != nil and bout[1] != nil if bout[0] != nil and bout[1] != nil
match = @tournament.matches.create( @tournament.matches.create(
w1: bout[0].id, w1: bout[0].id,
w2: bout[1].id, w2: bout[1].id,
weight_id: @weight.id, weight_id: @weight.id,
bracket_position: "Pool", bracket_position: "Pool",
round: round) round: round)
matches << match
end end
end end
end end
matches
end end
end end

View File

@@ -14,7 +14,7 @@ class Weight < ActiveRecord::Base
end end
before_save do before_save do
self.tournament.destroyAllMatches # self.tournament.destroyAllMatches
end end
def wrestlersForPool(pool) def wrestlersForPool(pool)

View File

@@ -5,12 +5,12 @@ class MatchesControllerTest < ActionController::TestCase
setup do setup do
@tournament = Tournament.find(1) @tournament = Tournament.find(1)
@tournament.generateMatchups # @tournament.generateMatchups
@match = @tournament.matches.first @match = Match.where("tournament_id = ? and mat_id = ?",1,1).first
end end
def post_update def post_update
patch :update, id: @match.id, match: {w1: @match.w1, w2: @match.w2} patch :update, id: @match.id, match: {tournament_id: 1, mat_id: 1}
end end
def get_edit def get_edit

View File

@@ -5,7 +5,7 @@ class MatsControllerTest < ActionController::TestCase
setup do setup do
@tournament = Tournament.find(1) @tournament = Tournament.find(1)
@tournament.generateMatchups # @tournament.generateMatchups
@mat = mats(:one) @mat = mats(:one)
end end

View File

@@ -5,7 +5,7 @@ class SchoolsControllerTest < ActionController::TestCase
setup do setup do
@tournament = Tournament.find(1) @tournament = Tournament.find(1)
@tournament.generateMatchups # @tournament.generateMatchups
@school = @tournament.schools.first @school = @tournament.schools.first
end end

View File

@@ -5,7 +5,7 @@ class StaticPagesControllerTest < ActionController::TestCase
setup do setup do
@tournament = Tournament.find(1) @tournament = Tournament.find(1)
@tournament.generateMatchups # @tournament.generateMatchups
@school = @tournament.schools.first @school = @tournament.schools.first
end end

View File

@@ -5,7 +5,7 @@ include Devise::TestHelpers
setup do setup do
@tournament = Tournament.find(1) @tournament = Tournament.find(1)
@tournament.generateMatchups # @tournament.generateMatchups
@school = @tournament.schools.first @school = @tournament.schools.first
@wrestlers = @tournament.weights.first.wrestlers @wrestlers = @tournament.weights.first.wrestlers
@adjust = Teampointadjust.find(1) @adjust = Teampointadjust.find(1)

View File

@@ -5,7 +5,7 @@ class WeightsControllerTest < ActionController::TestCase
setup do setup do
@tournament = Tournament.find(1) @tournament = Tournament.find(1)
@tournament.generateMatchups # @tournament.generateMatchups
@weight = @tournament.weights.first @weight = @tournament.weights.first
end end

View File

@@ -5,7 +5,7 @@ class WrestlersControllerTest < ActionController::TestCase
setup do setup do
@tournament = Tournament.find(1) @tournament = Tournament.find(1)
@tournament.generateMatchups # @tournament.generateMatchups
@school = @tournament.schools.first @school = @tournament.schools.first
@wrestler = @school.wrestlers.first @wrestler = @school.wrestlers.first
end end

File diff suppressed because it is too large Load Diff

View File

@@ -1,24 +1,7 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one: wrestler1:
name: Zach Collins id: 1
school_id: 1
weight_id: 1
original_seed: 4
season_loss: 8
season_win: 30
criteria: DP 5th
two:
name: Jaden Mattox
school_id: 1
weight_id: 1
original_seed: 1
season_loss: 3
season_win: 49
criteria: SP 2nd
three:
name: Jackson Lakso name: Jackson Lakso
school_id: 1 school_id: 1
weight_id: 1 weight_id: 1
@@ -27,7 +10,8 @@ three:
season_win: 30 season_win: 30
criteria: SQ criteria: SQ
four: wrestler2:
id: 2
name: JD Woods name: JD Woods
school_id: 1 school_id: 1
weight_id: 1 weight_id: 1
@@ -36,7 +20,28 @@ four:
season_win: 30 season_win: 30
criteria: DP 6th criteria: DP 6th
five: wrestler3:
id: 3
name: Jaden Mattox
school_id: 1
weight_id: 1
original_seed: 1
season_loss: 3
season_win: 49
criteria: SP 2nd
wrestler4:
id: 4
name: Zach Collins
school_id: 1
weight_id: 1
original_seed: 4
season_loss: 8
season_win: 30
criteria: DP 5th
wrestler5:
id: 5
name: James Wimer name: James Wimer
school_id: 1 school_id: 1
weight_id: 1 weight_id: 1
@@ -45,7 +50,8 @@ five:
season_win: 49 season_win: 49
criteria: SP 5th criteria: SP 5th
six: wrestler6:
id: 6
name: Derek Wurzauf name: Derek Wurzauf
school_id: 1 school_id: 1
weight_id: 2 weight_id: 2
@@ -54,7 +60,8 @@ six:
season_win: 16 season_win: 16
criteria: criteria:
seven: wrestler7:
id: 7
name: Casey Davis name: Casey Davis
school_id: 1 school_id: 1
weight_id: 2 weight_id: 2
@@ -63,34 +70,8 @@ seven:
season_win: 16 season_win: 16
criteria: DQ criteria: DQ
eight: wrestler8:
name: Ethan Leapley id: 8
school_id: 1
weight_id: 2
original_seed: 4
season_loss: 15
season_win: 20
criteria: DP 6th
nine:
name: Clayton Ray
school_id: 1
weight_id: 2
original_seed: 1
season_loss: 4
season_win: 30
criteria: SP 7th
ten:
name: Robbie Fusner
school_id: 1
weight_id: 2
original_seed: 3
season_loss: 5
season_win: 40
criteria: SQ
eleven:
name: Kameron Teacher name: Kameron Teacher
school_id: 1 school_id: 1
weight_id: 2 weight_id: 2
@@ -99,7 +80,18 @@ eleven:
season_win: 50 season_win: 50
criteria: SQ criteria: SQ
twelve: wrestler9:
id: 9
name: Robbie Fusner
school_id: 1
weight_id: 2
original_seed: 3
season_loss: 5
season_win: 40
criteria: SQ
wrestler10:
id: 10
name: Guy1 name: Guy1
school_id: 1 school_id: 1
weight_id: 2 weight_id: 2
@@ -108,7 +100,28 @@ twelve:
season_win: 50 season_win: 50
criteria: criteria:
thirteen: wrestler11:
id: 11
name: Ethan Leapley
school_id: 1
weight_id: 2
original_seed: 4
season_loss: 15
season_win: 20
criteria: DP 6th
wrestler12:
id: 12
name: Clayton Ray
school_id: 1
weight_id: 2
original_seed: 1
season_loss: 4
season_win: 30
criteria: SP 7th
wrestler13:
id: 13
name: Guy2 name: Guy2
school_id: 1 school_id: 1
weight_id: 3 weight_id: 3
@@ -117,61 +130,8 @@ thirteen:
season_win: 50 season_win: 50
criteria: criteria:
fourteen: wrestler14:
name: Guy3 id: 14
school_id: 1
weight_id: 3
original_seed: 2
season_loss: 2
season_win: 50
criteria:
fifteen:
name: Guy4
school_id: 1
weight_id: 3
original_seed: 3
season_loss: 2
season_win: 50
criteria:
sixteen:
name: Guy5
school_id: 1
weight_id: 3
original_seed: 4
season_loss: 2
season_win: 50
criteria:
seventeen:
name: Guy6
school_id: 1
weight_id: 3
original_seed: 5
season_loss: 2
season_win: 50
criteria:
eighteen:
name: Guy7
school_id: 1
weight_id: 3
original_seed: 6
season_loss: 2
season_win: 50
criteria:
ninteen:
name: Guy8
school_id: 1
weight_id: 3
original_seed: 7
season_loss: 2
season_win: 50
criteria:
twenty:
name: Guy9 name: Guy9
school_id: 1 school_id: 1
weight_id: 3 weight_id: 3
@@ -180,7 +140,48 @@ twenty:
season_win: 50 season_win: 50
criteria: criteria:
twentyone: wrestler15:
id: 15
name: Guy7
school_id: 1
weight_id: 3
original_seed: 6
season_loss: 2
season_win: 50
criteria:
wrestler16:
id: 16
name: Guy3
school_id: 1
weight_id: 3
original_seed: 2
season_loss: 2
season_win: 50
criteria:
wrestler17:
id: 17
name: Guy4
school_id: 1
weight_id: 3
original_seed: 3
season_loss: 2
season_win: 50
criteria:
wrestler18:
id: 18
name: Guy8
school_id: 1
weight_id: 3
original_seed: 7
season_loss: 2
season_win: 50
criteria:
wrestler19:
id: 19
name: Guy10 name: Guy10
school_id: 1 school_id: 1
weight_id: 3 weight_id: 3
@@ -189,88 +190,28 @@ twentyone:
season_win: 50 season_win: 50
criteria: criteria:
twentytwo: wrestler20:
name: Guy11 id: 20
name: Guy6
school_id: 1 school_id: 1
weight_id: 4 weight_id: 3
original_seed: 1
season_loss: 2
season_win: 50
criteria:
twentythree:
name: Guy12
school_id: 1
weight_id: 4
original_seed: 2
season_loss: 2
season_win: 50
criteria:
twentyfour:
name: Guy13
school_id: 1
weight_id: 4
original_seed: 3
season_loss: 2
season_win: 50
criteria:
twentyfive:
name: Guy14
school_id: 1
weight_id: 4
original_seed: 4
season_loss: 2
season_win: 50
criteria:
twentysix:
name: Guy15
school_id: 1
weight_id: 4
original_seed: 5 original_seed: 5
season_loss: 2 season_loss: 2
season_win: 50 season_win: 50
criteria: criteria:
twnetyseven: wrestler21:
name: Guy16 id: 21
name: Guy5
school_id: 1 school_id: 1
weight_id: 4 weight_id: 3
original_seed: 6 original_seed: 4
season_loss: 2 season_loss: 2
season_win: 50 season_win: 50
criteria: criteria:
twentyeight: wrestler22:
name: Guy17 id: 22
school_id: 1
weight_id: 4
original_seed: 7
season_loss: 2
season_win: 50
criteria:
twentynine:
name: Guy18
school_id: 1
weight_id: 4
original_seed: 8
season_loss: 2
season_win: 50
criteria:
thirty:
name: Guy19
school_id: 1
weight_id: 4
original_seed: 9
season_loss: 2
season_win: 50
criteria:
thrityone:
name: Guy20 name: Guy20
school_id: 1 school_id: 1
weight_id: 4 weight_id: 4
@@ -279,7 +220,48 @@ thrityone:
season_win: 50 season_win: 50
criteria: criteria:
thirtytwo: wrestler23:
id: 23
name: Guy12
school_id: 1
weight_id: 4
original_seed: 2
season_loss: 2
season_win: 50
criteria:
wrestler24:
id: 24
name: Guy16
school_id: 1
weight_id: 4
original_seed: 6
season_loss: 2
season_win: 50
criteria:
wrestler25:
id: 25
name: Guy13
school_id: 1
weight_id: 4
original_seed: 3
season_loss: 2
season_win: 50
criteria:
wrestler26:
id: 26
name: Guy15
school_id: 1
weight_id: 4
original_seed: 5
season_loss: 2
season_win: 50
criteria:
wrestler27:
id: 27
name: Guy21 name: Guy21
school_id: 1 school_id: 1
weight_id: 4 weight_id: 4
@@ -288,133 +270,58 @@ thirtytwo:
season_win: 50 season_win: 50
criteria: criteria:
thirtythree: wrestler28:
name: Guy22 id: 28
name: Guy11
school_id: 1 school_id: 1
weight_id: 5 weight_id: 4
original_seed: 1 original_seed: 1
season_loss: 2 season_loss: 2
season_win: 50 season_win: 50
criteria: criteria:
thirtyfour: wrestler29:
name: Guy23 id: 29
name: Guy14
school_id: 1 school_id: 1
weight_id: 5 weight_id: 4
original_seed: 2
season_loss: 2
season_win: 50
criteria:
thirtyfive:
name: Guy24
school_id: 1
weight_id: 5
original_seed: 3
season_loss: 2
season_win: 50
criteria:
thirtysix:
name: Guy25
school_id: 1
weight_id: 5
original_seed: 4 original_seed: 4
season_loss: 2 season_loss: 2
season_win: 50 season_win: 50
criteria: criteria:
thirtyseven: wrestler30:
name: Guy26 id: 30
name: Guy18
school_id: 1 school_id: 1
weight_id: 5 weight_id: 4
original_seed: 5
season_loss: 2
season_win: 50
criteria:
thirtyeight:
name: Guy27
school_id: 1
weight_id: 5
original_seed: 6
season_loss: 2
season_win: 50
criteria:
thirtynine:
name: Guy28
school_id: 1
weight_id: 5
original_seed: 7
season_loss: 2
season_win: 50
criteria:
fourty:
name: Guy29
school_id: 1
weight_id: 5
original_seed: 8 original_seed: 8
season_loss: 2 season_loss: 2
season_win: 50 season_win: 50
criteria: criteria:
fourtyone: wrestler31:
name: Guy30 id: 31
name: Guy17
school_id: 1 school_id: 1
weight_id: 5 weight_id: 4
original_seed: 7
season_loss: 2
season_win: 50
criteria:
wrestler32:
id: 32
name: Guy19
school_id: 1
weight_id: 4
original_seed: 9 original_seed: 9
season_loss: 2 season_loss: 2
season_win: 50 season_win: 50
criteria: criteria:
fourtytwo: wrestler33:
name: Guy31 id: 33
school_id: 1
weight_id: 5
original_seed: 10
season_loss: 2
season_win: 50
criteria:
fourtythree:
name: Guy32
school_id: 1
weight_id: 5
original_seed: 11
season_loss: 2
season_win: 50
criteria:
fourtyfour:
name: Guy33
school_id: 1
weight_id: 5
original_seed: 12
season_loss: 2
season_win: 50
criteria:
fourtyfive:
name: Guy34
school_id: 1
weight_id: 5
original_seed: 13
season_loss: 2
season_win: 50
criteria:
fourtysix:
name: Guy35
school_id: 1
weight_id: 5
original_seed: 14
season_loss: 2
season_win: 50
criteria:
fourtyseven:
name: Guy36 name: Guy36
school_id: 1 school_id: 1
weight_id: 5 weight_id: 5
@@ -423,7 +330,118 @@ fourtyseven:
season_win: 50 season_win: 50
criteria: criteria:
fourtyeight: wrestler34:
id: 34
name: Guy31
school_id: 1
weight_id: 5
original_seed: 10
season_loss: 2
season_win: 50
criteria:
wrestler35:
id: 35
name: Guy22
school_id: 1
weight_id: 5
original_seed: 1
season_loss: 2
season_win: 50
criteria:
wrestler36:
id: 36
name: Guy32
school_id: 1
weight_id: 5
original_seed: 11
season_loss: 2
season_win: 50
criteria:
wrestler37:
id: 37
name: Guy23
school_id: 1
weight_id: 5
original_seed: 2
season_loss: 2
season_win: 50
criteria:
wrestler38:
id: 38
name: Guy34
school_id: 1
weight_id: 5
original_seed: 13
season_loss: 2
season_win: 50
criteria:
wrestler39:
id: 39
name: Guy29
school_id: 1
weight_id: 5
original_seed: 8
season_loss: 2
season_win: 50
criteria:
wrestler40:
id: 40
name: Guy26
school_id: 1
weight_id: 5
original_seed: 5
season_loss: 2
season_win: 50
criteria:
wrestler41:
id: 41
name: Guy35
school_id: 1
weight_id: 5
original_seed: 14
season_loss: 2
season_win: 50
criteria:
wrestler42:
id: 42
name: Guy30
school_id: 1
weight_id: 5
original_seed: 9
season_loss: 2
season_win: 50
criteria:
wrestler43:
id: 43
name: Guy27
school_id: 1
weight_id: 5
original_seed: 6
season_loss: 2
season_win: 50
criteria:
wrestler44:
id: 44
name: Guy28
school_id: 1
weight_id: 5
original_seed: 7
season_loss: 2
season_win: 50
criteria:
wrestler45:
id: 45
name: Guy37 name: Guy37
school_id: 1 school_id: 1
weight_id: 5 weight_id: 5
@@ -432,43 +450,38 @@ fourtyeight:
season_win: 50 season_win: 50
criteria: criteria:
fourtynine: wrestler46:
name: Guy38 id: 46
name: Guy33
school_id: 1 school_id: 1
weight_id: 6 weight_id: 5
original_seed: 1 original_seed: 12
season_loss: 2 season_loss: 2
season_win: 50 season_win: 50
criteria: criteria:
fourtynine: wrestler47:
name: Guy39 id: 47
name: Guy24
school_id: 1 school_id: 1
weight_id: 6 weight_id: 5
original_seed: 2 original_seed: 3
season_loss: 2 season_loss: 2
season_win: 50 season_win: 50
criteria: criteria:
fifty: wrestler48:
name: Guy40 id: 48
name: Guy25
school_id: 1 school_id: 1
weight_id: 6 weight_id: 5
original_seed: original_seed: 4
season_loss: 2 season_loss: 2
season_win: 50 season_win: 50
criteria: criteria:
fiftyone: wrestler49:
name: Guy41 id: 49
school_id: 1
weight_id: 6
original_seed:
season_loss: 2
season_win: 50
criteria:
fiftytwo:
name: Guy42 name: Guy42
school_id: 1 school_id: 1
weight_id: 6 weight_id: 6
@@ -477,7 +490,28 @@ fiftytwo:
season_win: 50 season_win: 50
criteria: criteria:
fiftythree: wrestler50:
id: 50
name: Guy39
school_id: 1
weight_id: 6
original_seed: 2
season_loss: 2
season_win: 50
criteria:
wrestler51:
id: 51
name: Guy41
school_id: 1
weight_id: 6
original_seed:
season_loss: 2
season_win: 50
criteria:
wrestler52:
id: 52
name: Guy43 name: Guy43
school_id: 1 school_id: 1
weight_id: 6 weight_id: 6
@@ -485,3 +519,13 @@ fiftythree:
season_loss: 2 season_loss: 2
season_win: 50 season_win: 50
criteria: criteria:
wrestler53:
id: 53
name: Guy40
school_id: 1
weight_id: 6
original_seed:
season_loss: 2
season_win: 50
criteria:

View File

@@ -3,129 +3,127 @@ require 'test_helper'
class PoolAdvancementTest < ActionDispatch::IntegrationTest class PoolAdvancementTest < ActionDispatch::IntegrationTest
def setup def setup
@tournament = Tournament.find(1) tournament = Tournament.find(1)
@tournament.generateMatchups tournament.generateMatchups
@matches = @tournament.matches
end end
def showMatches # def showMatches
matches = Weight.where("id = ?", 4).first.matches # matches = Weight.where("id = ?", 4).first.matches
# matches = @matches.select{|m| m.weight_id == 4} # matches.each do |m|
matches.each do |m| # puts "Bout: #{m.bout_number} #{m.w1_name} vs #{m.w2_name} #{m.bracket_position} #{m.poolNumber}"
puts "Bout: #{m.bout_number} #{m.w1_name} vs #{m.w2_name} #{m.bracket_position} #{m.poolNumber}" # end
end # end
end
def singlePoolNotFinished def singlePoolNotFinished
matches = @matches
endMatch(1000,"Jackson Lakso",matches) endMatch(1000,"Jackson Lakso")
endMatch(1001,"Jaden Mattox",matches) endMatch(1001,"Jaden Mattox")
endMatch(2000,"James Wimer",matches) endMatch(2000,"James Wimer")
endMatch(2001,"Jaden Mattox",matches) endMatch(2001,"Jaden Mattox")
endMatch(3000,"Jaden Mattox",matches) endMatch(3000,"Jaden Mattox")
endMatch(3001,"James Wimer",matches) endMatch(3001,"James Wimer")
endMatch(4000,"JD Woods",matches) endMatch(4000,"JD Woods")
endMatch(4001,"James Wimer",matches) endMatch(4001,"James Wimer")
endMatch(5000,"James Wimer",matches) endMatch(5000,"James Wimer")
end end
def singlePoolFinished def singlePoolFinished
singlePoolNotFinished singlePoolNotFinished
matches = @matches
endMatch(5001,"Jackson Lakso",matches) endMatch(5001,"Jackson Lakso")
end end
def sixteenManToSemi def sixteenManToSemi
matches = @matches
endMatch(1013,"Guy22",matches) endMatch(1013,"Guy22")
endMatch(1014,"Guy29",matches) endMatch(1014,"Guy29")
endMatch(2012,"Guy29",matches) endMatch(2012,"Guy29")
endMatch(2013,"Guy22",matches) endMatch(2013,"Guy22")
endMatch(3012,"Guy37",matches) endMatch(3012,"Guy37")
endMatch(3013,"Guy22",matches) endMatch(3013,"Guy22")
endMatch(1015,"Guy36",matches) endMatch(1015,"Guy36")
endMatch(1016,"Guy32",matches) endMatch(1016,"Guy32")
endMatch(2014,"Guy36",matches) endMatch(2014,"Guy36")
endMatch(2015,"Guy32",matches) endMatch(2015,"Guy32")
endMatch(3014,"Guy36",matches) endMatch(3014,"Guy36")
endMatch(3015,"Guy23",matches) endMatch(3015,"Guy23")
endMatch(1017,"Guy31",matches) endMatch(1017,"Guy31")
endMatch(1018,"Guy35",matches) endMatch(1018,"Guy35")
endMatch(2016,"Guy35",matches) endMatch(2016,"Guy35")
endMatch(2017,"Guy31",matches) endMatch(2017,"Guy31")
endMatch(3016,"Guy27",matches) endMatch(3016,"Guy27")
endMatch(3017,"Guy31",matches) endMatch(3017,"Guy31")
endMatch(1019,"Guy34",matches) endMatch(1019,"Guy34")
endMatch(1020,"Guy26",matches) endMatch(1020,"Guy26")
endMatch(2018,"Guy30",matches) endMatch(2018,"Guy30")
endMatch(2019,"Guy34",matches) endMatch(2019,"Guy34")
endMatch(3018,"Guy26",matches) endMatch(3018,"Guy26")
endMatch(3019,"Guy34",matches) endMatch(3019,"Guy34")
end end
def sevenManTwoPoolToSemi def sevenManTwoPoolToSemi
matches = @matches
endMatch(1006,"Casey Davis",matches) endMatch(1006,"Casey Davis")
endMatch(1007,"Ethan Leapley",matches) endMatch(1007,"Ethan Leapley")
endMatch(2006,"Clayton Ray",matches) endMatch(2006,"Clayton Ray")
endMatch(2007,"Ethan Leapley",matches) endMatch(2007,"Ethan Leapley")
endMatch(3006,"Ethan Leapley",matches) endMatch(3006,"Ethan Leapley")
endMatch(3007,"Casey Davis",matches) endMatch(3007,"Casey Davis")
endMatch(1008,"Kameron Teacher",matches) endMatch(1008,"Kameron Teacher")
endMatch(2008,"Kameron Teacher",matches) endMatch(2008,"Kameron Teacher")
endMatch(3008,"Robbie Fusner",matches) endMatch(3008,"Robbie Fusner")
end end
def sevenManTwoPoolSemiToFinals def sevenManTwoPoolSemiToFinals
sevenManTwoPoolToSemi sevenManTwoPoolToSemi
matches = @matches
endMatch(4005,"Casey Davis",matches) endMatch(4005,"Casey Davis")
endMatch(4004,"Ethan Leapley",matches) endMatch(4004,"Ethan Leapley")
end end
def nineManBracketPoolOneOutrightWinnerGuyTwo def nineManBracketPoolOneOutrightWinnerGuyTwo
matches = @matches.select{|m| m.weight_id == 3 && m.bracket_position == "Pool"}
endMatch(1002,"Guy8",matches) endMatch(1002,"Guy8")
endMatch(1003,"Guy5",matches) endMatch(1003,"Guy5")
endMatch(2002,"Guy2",matches) endMatch(2002,"Guy2")
endMatch(2003,"Guy8",matches) endMatch(2003,"Guy8")
endMatch(3002,"Guy5",matches) endMatch(3002,"Guy5")
endMatch(3003,"Guy2",matches) endMatch(3003,"Guy2")
endMatch(4002,"Guy8",matches) endMatch(4002,"Guy8")
endMatch(4003,"Guy2",matches) endMatch(4003,"Guy2")
endMatch(5002,"Guy2",matches) endMatch(5002,"Guy2")
endMatch(5003,"Guy10",matches) endMatch(5003,"Guy10")
end end
def nineManBracketPoolTwoGuyNineHeadToHead def nineManBracketPoolTwoGuyNineHeadToHead
matches = @matches.select{|m| m.weight_id == 3 && m.bracket_position == "Pool"}
endMatch(1004,"Guy4",matches) endMatch(1004,"Guy4")
endMatch(1005,"Guy3",matches) endMatch(1005,"Guy3")
endMatch(2004,"Guy9",matches) endMatch(2004,"Guy9")
endMatch(2005,"Guy7",matches) endMatch(2005,"Guy7")
endMatch(3004,"Guy9",matches) endMatch(3004,"Guy9")
endMatch(3005,"Guy3",matches) endMatch(3005,"Guy3")
end end
def nineManBracketPoolTwoGuyThreeHeadToHead def nineManBracketPoolTwoGuyThreeHeadToHead
matches = @matches.select{|m| m.weight_id == 3 && m.bracket_position == "Pool"}
endMatch(1004,"Guy9",matches) endMatch(1004,"Guy9")
endMatch(1005,"Guy3",matches) endMatch(1005,"Guy3")
endMatch(2004,"Guy3",matches) endMatch(2004,"Guy3")
endMatch(2005,"Guy7",matches) endMatch(2005,"Guy7")
endMatch(3004,"Guy9",matches) endMatch(3004,"Guy9")
endMatch(3005,"Guy4",matches) endMatch(3005,"Guy4")
end end
def nineManBracketPoolTwoGuyThreeDeductedPoints def nineManBracketPoolTwoGuyThreeDeductedPoints
matches = @matches.select{|m| m.weight_id == 3 && m.bracket_position == "Pool"}
endMatch(1004,"Guy9",matches) endMatch(1004,"Guy9")
endMatch(1005,"Guy7",matches) endMatch(1005,"Guy7")
endMatch(2004,"Guy3",matches) endMatch(2004,"Guy3")
endMatch(2005,"Guy7",matches) endMatch(2005,"Guy7")
endMatch(3004,"Guy9",matches) endMatch(3004,"Guy9")
endMatch(3005,"Guy3",matches) endMatch(3005,"Guy3")
deduct = Teampointadjust.new deduct = Teampointadjust.new
deduct.wrestler_id = translateNameToId("Guy7") deduct.wrestler_id = translateNameToId("Guy7")
deduct.points = 1 deduct.points = 1
@@ -133,174 +131,161 @@ class PoolAdvancementTest < ActionDispatch::IntegrationTest
end end
def nineManBracketPoolTwoGuyThreeMostDecisionPoints def nineManBracketPoolTwoGuyThreeMostDecisionPoints
matches = @matches.select{|m| m.weight_id == 3 && m.bracket_position == "Pool"}
endMatchExtraPoints(1004,"Guy9",matches) endMatchExtraPoints(1004,"Guy9")
endMatch(1005,"Guy7",matches) endMatch(1005,"Guy7")
endMatchExtraPoints(2004,"Guy3",matches) endMatchExtraPoints(2004,"Guy3")
endMatch(2005,"Guy7",matches) endMatch(2005,"Guy7")
endMatch(3004,"Guy9",matches) endMatch(3004,"Guy9")
endMatchExtraPoints(3005,"Guy3",matches) endMatchExtraPoints(3005,"Guy3")
end end
def nineManBracketPoolTwoGuyThreeQuickestPin def nineManBracketPoolTwoGuyThreeQuickestPin
matches = @matches.select{|m| m.weight_id == 3 && m.bracket_position == "Pool"}
endMatchWithQuickPin(1004,"Guy9",matches) endMatchWithQuickPin(1004,"Guy9")
endMatchWithPin(1005,"Guy7",matches) endMatchWithPin(1005,"Guy7")
endMatchWithQuickPin(2004,"Guy3",matches) endMatchWithQuickPin(2004,"Guy3")
endMatchWithPin(2005,"Guy7",matches) endMatchWithPin(2005,"Guy7")
endMatchWithPin(3004,"Guy9",matches) endMatchWithPin(3004,"Guy9")
endMatchWithQuickestPin(3005,"Guy3",matches) endMatchWithQuickestPin(3005,"Guy3")
end end
def nineManBracketPoolTwoGuyThreeTeamPoints def nineManBracketPoolTwoGuyThreeTeamPoints
matches = @matches.select{|m| m.weight_id == 3 && m.bracket_position == "Pool"}
endMatch(1004,"Guy9",matches) endMatch(1004,"Guy9")
endMatch(1005,"Guy7",matches) endMatch(1005,"Guy7")
endMatchWithMajor(2004,"Guy3",matches) endMatchWithMajor(2004,"Guy3")
endMatch(2005,"Guy7",matches) endMatch(2005,"Guy7")
endMatch(3004,"Guy9",matches) endMatch(3004,"Guy9")
endMatch(3005,"Guy3",matches) endMatch(3005,"Guy3")
end end
def nineManBracketPoolTwoGuyThreeMostPins def nineManBracketPoolTwoGuyThreeMostPins
matches = @matches.select{|m| m.weight_id == 3 && m.bracket_position == "Pool"}
endMatchWithMajor(1004,"Guy9",matches) endMatchWithMajor(1004,"Guy9")
endMatch(1005,"Guy7",matches) endMatch(1005,"Guy7")
endMatchWithPin(2004,"Guy3",matches) endMatchWithPin(2004,"Guy3")
endMatchWithMajor(2005,"Guy7",matches) endMatchWithMajor(2005,"Guy7")
endMatch(3004,"Guy9",matches) endMatch(3004,"Guy9")
endMatch(3005,"Guy3",matches) endMatch(3005,"Guy3")
end end
def nineManBracketPoolOneGuyEightMostTechs def nineManBracketPoolOneGuyEightMostTechs
matches = @matches.select{|m| m.weight_id == 3 && m.bracket_position == "Pool"}
endMatchWithTech(1002,"Guy8",matches) endMatchWithTech(1002,"Guy8")
endMatch(1003,"Guy5",matches) endMatch(1003,"Guy5")
endMatchWithMajor(2002,"Guy2",matches) endMatchWithMajor(2002,"Guy2")
endMatchWithTech(2003,"Guy8",matches) endMatchWithTech(2003,"Guy8")
endMatchWithMajor(3002,"Guy10",matches) endMatchWithMajor(3002,"Guy10")
endMatchWithMajor(3003,"Guy2",matches) endMatchWithMajor(3003,"Guy2")
endMatch(4002,"Guy8",matches) endMatch(4002,"Guy8")
endMatchWithMajor(4003,"Guy10",matches) endMatchWithMajor(4003,"Guy10")
endMatchWithMajor(5002,"Guy2",matches) endMatchWithMajor(5002,"Guy2")
endMatchWithMajor(5003,"Guy10",matches) endMatchWithMajor(5003,"Guy10")
end end
def elevenManBracketToQuarter def elevenManBracketToQuarter
matches = @matches
endMatch(1009,"Guy11",matches) endMatch(1009,"Guy11")
endMatch(2009,"Guy11",matches) endMatch(2009,"Guy11")
endMatch(3009,"Guy18",matches) endMatch(3009,"Guy18")
endMatch(1010,"Guy12",matches) endMatch(1010,"Guy12")
endMatch(2010,"Guy12",matches) endMatch(2010,"Guy12")
endMatch(3010,"Guy17",matches) endMatch(3010,"Guy17")
endMatch(1011,"Guy13",matches) endMatch(1011,"Guy13")
endMatch(2011,"Guy13",matches) endMatch(2011,"Guy13")
endMatch(3011,"Guy19",matches) endMatch(3011,"Guy19")
endMatch(1012,"Guy14",matches) endMatch(1012,"Guy14")
end end
def elevenManBracketToSemis def elevenManBracketToSemis
elevenManBracketToQuarter elevenManBracketToQuarter
matches = @matches
endMatch(4006,"Guy11",matches) endMatch(4006,"Guy11")
endMatch(4007,"Guy14",matches) endMatch(4007,"Guy14")
endMatch(4008,"Guy12",matches) endMatch(4008,"Guy12")
endMatch(4009,"Guy13",matches) endMatch(4009,"Guy13")
end end
def elevenManBracketToFinals def elevenManBracketToFinals
elevenManBracketToSemis elevenManBracketToSemis
matches = @matches
endMatch(5004,"Guy11",matches) endMatch(5004,"Guy11")
endMatch(5005,"Guy12",matches) endMatch(5005,"Guy12")
endMatch(5006,"Guy17",matches) endMatch(5006,"Guy17")
endMatch(5007,"Guy18",matches) endMatch(5007,"Guy18")
end end
def elevenManBracketFinished def elevenManBracketFinished
elevenManBracketToFinals elevenManBracketToFinals
matches = @matches
endMatch(6004,"Guy11",matches) endMatch(6004,"Guy11")
endMatch(6005,"Guy14",matches) endMatch(6005,"Guy14")
endMatch(6006,"Guy17",matches) endMatch(6006,"Guy17")
endMatch(6007,"Guy19",matches) endMatch(6007,"Guy19")
end end
def extraDoesNotScoreTeamPoints def extraDoesNotScoreTeamPoints
matches = @matches
wrestlerName = "Guy22" wrestlerName = "Guy22"
wrestler = Wrestler.find(translateNameToId(wrestlerName)) wrestler = Wrestler.find(translateNameToId(wrestlerName))
wrestler.extra = true wrestler.extra = true
wrestler.save wrestler.save
endMatch(1013,"Guy22",matches) endMatch(1013,"Guy22")
end end
def endMatch(bout,winner,matches) def endMatch(bout,winner)
match = Match.where(bout_number: bout).first match = Match.where(bout_number: bout).first
match.finished = 1 # match = @matches.select{|m| m.bout_number == bout}.first
match.winner_id = translateNameToId(winner)
match.win_type = "Decision" match.win_type = "Decision"
match.score = 1-0 match.score = 1-0
saveMatch(match,winner)
match.save
end end
def endMatchExtraPoints(bout,winner,matches) def endMatchExtraPoints(bout,winner)
match = Match.where(bout_number: bout).first match = Match.where(bout_number: bout).first
match.finished = 1
match.winner_id = translateNameToId(winner)
match.win_type = "Decision" match.win_type = "Decision"
match.score = 0-2 match.score = 0-2
saveMatch(match,winner)
match.save
end end
def endMatchWithMajor(bout,winner,matches) def endMatchWithMajor(bout,winner)
match = Match.where(bout_number: bout).first match = Match.where(bout_number: bout).first
match.finished = 1
match.winner_id = translateNameToId(winner)
match.win_type = "Major" match.win_type = "Major"
match.score = 8-0 match.score = 8-0
saveMatch(match,winner)
match.save
end end
def endMatchWithTech(bout,winner,matches) def endMatchWithTech(bout,winner)
match = Match.where(bout_number: bout).first match = Match.where(bout_number: bout).first
match.finished = 1
match.winner_id = translateNameToId(winner)
match.win_type = "Tech Fall" match.win_type = "Tech Fall"
match.score = 15-0
match.save saveMatch(match,winner)
end end
def endMatchWithPin(bout,winner,matches) def endMatchWithPin(bout,winner)
match = Match.where(bout_number: bout).first match = Match.where(bout_number: bout).first
match.finished = 1
match.winner_id = translateNameToId(winner)
match.win_type = "Pin" match.win_type = "Pin"
match.score = "5:00" match.score = "5:00"
saveMatch(match,winner)
match.save
end end
def endMatchWithQuickestPin(bout,winner,matches) def endMatchWithQuickestPin(bout,winner)
match = Match.where(bout_number: bout).first match = Match.where(bout_number: bout).first
match.finished = 1
match.winner_id = translateNameToId(winner)
match.win_type = "Pin" match.win_type = "Pin"
match.score = "0:20" match.score = "0:20"
saveMatch(match,winner)
match.save
end end
def endMatchWithQuickPin(bout,winner,matches) def endMatchWithQuickPin(bout,winner)
match = Match.where(bout_number: bout).first match = Match.where(bout_number: bout).first
match.finished = 1
match.winner_id = translateNameToId(winner)
match.win_type = "Pin" match.win_type = "Pin"
match.score = "1:20" match.score = "1:20"
saveMatch(match,winner)
end
def saveMatch(match,winner)
match.finished = 1
match.winner_id = translateNameToId(winner)
match.save match.save
end end
@@ -458,7 +443,7 @@ class PoolAdvancementTest < ActionDispatch::IntegrationTest
test "advancement points winner 1/2" do test "advancement points winner 1/2" do
nineManBracketPoolOneOutrightWinnerGuyTwo nineManBracketPoolOneOutrightWinnerGuyTwo
nineManBracketPoolTwoGuyThreeHeadToHead nineManBracketPoolTwoGuyThreeHeadToHead
endMatch(6000,"Guy2",@matches) endMatch(6000,"Guy2")
wrestler1 = Wrestler.where("name = ?", "Guy2").first wrestler1 = Wrestler.where("name = ?", "Guy2").first
assert_equal 16, wrestler1.placementPoints assert_equal 16, wrestler1.placementPoints
end end
@@ -466,7 +451,7 @@ class PoolAdvancementTest < ActionDispatch::IntegrationTest
test "advancement points winner 3/4" do test "advancement points winner 3/4" do
nineManBracketPoolOneOutrightWinnerGuyTwo nineManBracketPoolOneOutrightWinnerGuyTwo
nineManBracketPoolTwoGuyThreeHeadToHead nineManBracketPoolTwoGuyThreeHeadToHead
endMatch(6001,"Guy8",@matches) endMatch(6001,"Guy8")
wrestler1 = Wrestler.where("name = ?", "Guy8").first wrestler1 = Wrestler.where("name = ?", "Guy8").first
assert_equal 10, wrestler1.placementPoints assert_equal 10, wrestler1.placementPoints
end end
@@ -486,25 +471,25 @@ class PoolAdvancementTest < ActionDispatch::IntegrationTest
end end
test "bonus points major" do test "bonus points major" do
endMatchWithMajor(2002,"Guy2",@matches) endMatchWithMajor(2002,"Guy2")
wrestler1 = Wrestler.where("name = ?", "Guy2").first wrestler1 = Wrestler.where("name = ?", "Guy2").first
assert_equal 3, wrestler1.teamPointsEarned assert_equal 3, wrestler1.teamPointsEarned
end end
test "bonus points pin" do test "bonus points pin" do
endMatchWithPin(2002,"Guy2",@matches) endMatchWithPin(2002,"Guy2")
wrestler1 = Wrestler.where("name = ?", "Guy2").first wrestler1 = Wrestler.where("name = ?", "Guy2").first
assert_equal 4, wrestler1.teamPointsEarned assert_equal 4, wrestler1.teamPointsEarned
end end
test "bonus points tech fall" do test "bonus points tech fall" do
endMatchWithTech(2002,"Guy2",@matches) endMatchWithTech(2002,"Guy2")
wrestler1 = Wrestler.where("name = ?", "Guy2").first wrestler1 = Wrestler.where("name = ?", "Guy2").first
assert_equal 3.5, wrestler1.teamPointsEarned assert_equal 3.5, wrestler1.teamPointsEarned
end end
test "pool team points win" do test "pool team points win" do
endMatch(2002,"Guy2",@matches) endMatch(2002,"Guy2")
wrestler1 = Wrestler.where("name = ?", "Guy2").first wrestler1 = Wrestler.where("name = ?", "Guy2").first
assert_equal 2, wrestler1.teamPointsEarned assert_equal 2, wrestler1.teamPointsEarned
end end
@@ -570,19 +555,19 @@ class PoolAdvancementTest < ActionDispatch::IntegrationTest
test "Championship bracket wins are 2pts" do test "Championship bracket wins are 2pts" do
elevenManBracketToQuarter elevenManBracketToQuarter
assert_equal 7, Wrestler.where("name = ?", "Guy11").first.teamPointsEarned assert_equal 7, Wrestler.where("name = ?", "Guy11").first.teamPointsEarned
matches = @matches
endMatch(4006,"Guy11",matches) endMatch(4006,"Guy11")
assert_equal 15, Wrestler.where("name = ?", "Guy11").first.teamPointsEarned assert_equal 15, Wrestler.where("name = ?", "Guy11").first.teamPointsEarned
endMatch(4007,"Guy14",matches) endMatch(4007,"Guy14")
endMatch(5004,"Guy11",matches) endMatch(5004,"Guy11")
assert_equal 20, Wrestler.where("name = ?", "Guy11").first.teamPointsEarned assert_equal 20, Wrestler.where("name = ?", "Guy11").first.teamPointsEarned
end end
test "Conso bracket wins are 1pt" do test "Conso bracket wins are 1pt" do
elevenManBracketToSemis elevenManBracketToSemis
assert_equal 5, Wrestler.where("name = ?", "Guy17").first.teamPointsEarned assert_equal 5, Wrestler.where("name = ?", "Guy17").first.teamPointsEarned
matches = @matches
endMatch(5006,"Guy17",matches) endMatch(5006,"Guy17")
assert_equal 9, Wrestler.where("name = ?", "Guy17").first.teamPointsEarned assert_equal 9, Wrestler.where("name = ?", "Guy17").first.teamPointsEarned
end end

View File

@@ -1,8 +1,60 @@
require 'test_helper' require 'test_helper'
class SingleTestTest < ActionDispatch::IntegrationTest class SingleTestTest < ActionDispatch::IntegrationTest
def setup
@tournament = Tournament.find(1)
# @tournament.generateMatchups
# @matches = @tournament.matches
end
#rake test test/integration/single_test_test.rb > matches.txt
# Loser names need to be in quotes in yml file
def showMatches
# matches = Weight.where("id = ?", 4).first.matches
count = 1
# Yml for matches
# Match.where(tournament_id: 1).each do |m|
# puts "tournament_1_bout_#{m.bout_number}:"
# puts " tournament_id: #{m.tournament_id}"
# puts " weight_id: #{m.weight_id}"
# puts " bout_number: #{m.bout_number}"
# puts " w1: #{m.w1}"
# puts " w2: #{m.w2}"
# puts " bracket_position: #{m.bracket_position}"
# puts " bracket_position_number: #{m.bracket_position_number}"
# puts " loser1_name: #{m.loser1_name}"
# puts " loser2_name: #{m.loser2_name}"
# puts " round: #{m.round}"
# puts " mat_id: #{m.mat_id}"
# puts " finished: #{m.finished}"
# puts " w1_stat: "
# puts " w2_stat: "
# puts " score: "
# puts " winner_id: "
# puts " win_type: "
# puts ""
# count += 1
# end
# Yml for wrestlers
# @tournament.wrestlers.each do |w|
# puts "tournament_1_#{w.name}:"
# puts " id: #{count}"
# puts " name: #{w.name}"
# puts " school_id: #{w.school_id}"
# puts " weight_id: #{w.weight_id}"
# puts " original_seed: #{w.original_seed}"
# puts " season_loss: #{w.season_loss}"
# puts " season_win: #{w.season_win}"
# puts " criteria: #{w.criteria}"
# puts ""
# count += 1
# end
end
test "the truth" do test "the truth" do
showMatches
assert true assert true
end end
end end

View File

@@ -1,6 +1,7 @@
require 'test_helper' require 'test_helper'
class TournamentTest < ActiveSupport::TestCase class TournamentTest < ActiveSupport::TestCase
test "the truth" do test "the truth" do
assert true assert true
end end