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

Wrestler pool number is now saved in db. Pool number generation moved to it's own class.

This commit is contained in:
2017-03-02 18:11:21 +00:00
parent 8fa529dc5f
commit 3f72a912b6
12 changed files with 177 additions and 106 deletions

View File

@@ -130,7 +130,7 @@ class Match < ActiveRecord::Base
end
def poolNumber
if self.w1?
wrestler1.generatePoolNumber
wrestler1.pool
end
end

View File

@@ -17,8 +17,13 @@ class Weight < ActiveRecord::Base
# self.tournament.destroyAllMatches
end
def wrestlersForPool(pool)
self.wrestlers.select{|w| w.generatePoolNumber == pool}
def wrestlersForPool(poolNumber)
#For some reason this does not work
# wrestlers.select{|w| w.pool == poolNumber}
#This does...
weightWrestlers = Wrestler.where(:weight_id => self.id)
weightWrestlers.select{|w| w.pool == poolNumber}
end
def allPoolMatchesFinished(pool)
@@ -43,7 +48,8 @@ class Weight < ActiveRecord::Base
end
def poolSeedOrder(pool)
wrestlersForPool(pool).sort_by{|w| [w.original_seed ? 0 : 1, w.original_seed || 0]}
# wrestlersForPool(pool).sort_by{|w| [w.original_seed ? 0 : 1, w.original_seed || 0]}
return wrestlersForPool(pool).sort_by{|w|w.seed}
end
@@ -51,79 +57,6 @@ class Weight < ActiveRecord::Base
SwapWrestlers.new.swapWrestlers(wrestler1_id,wrestler2_id)
end
def returnPoolNumber(wrestler)
if self.pools == 4
@wrestlers = fourPoolNumbers(self.wrestlers)
elsif self.pools == 2
@wrestlers = twoPoolNumbers(self.wrestlers)
elsif self.pools == 1
@wrestlers = onePoolNumbers(self.wrestlers)
end
@wrestler = @wrestlers.select{|w| w.id == wrestler.id}.first
return @wrestler.poolNumber
end
def onePoolNumbers(poolWrestlers)
poolWrestlers.sort_by{|x| x.seed }.each do |w|
w.poolNumber = 1
end
return poolWrestlers
end
def twoPoolNumbers(poolWrestlers)
pool = 1
poolWrestlers.sort_by{|x| x.seed }.reverse.each do |w|
if w.seed == 1
w.poolNumber = 1
elsif w.seed == 2
w.poolNumber = 2
elsif w.seed == 3
w.poolNumber = 2
elsif w.seed == 4
w.poolNumber = 1
else
w.poolNumber = pool
end
if pool < 2
pool = pool + 1
else
pool = 1
end
end
return poolWrestlers
end
def fourPoolNumbers(poolWrestlers)
pool = 1
poolWrestlers.sort_by{|x| x.seed }.reverse.each do |w|
if w.seed == 1
w.poolNumber = 1
elsif w.seed == 2
w.poolNumber = 2
elsif w.seed == 3
w.poolNumber = 3
elsif w.seed == 4
w.poolNumber = 4
elsif w.seed == 8
w.poolNumber = 1
elsif w.seed == 7
w.poolNumber = 2
elsif w.seed == 6
w.poolNumber = 3
elsif w.seed == 5
w.poolNumber = 4
else
w.poolNumber = pool
end
if pool < 4
pool = pool + 1
else
pool = 1
end
end
return poolWrestlers
end
def bracket_size
wrestlers.size

View File

@@ -4,7 +4,7 @@ class Wrestler < ActiveRecord::Base
has_one :tournament, through: :weight
has_many :matches, through: :weight
has_many :deductedPoints, class_name: "Teampointadjust"
attr_accessor :poolNumber, :poolAdvancePoints, :originalId, :swapId
attr_accessor :poolAdvancePoints, :originalId, :swapId
validates :name, :weight_id, :school_id, presence: true
@@ -103,10 +103,6 @@ class Wrestler < ActiveRecord::Base
end
end
def generatePoolNumber
self.weight.returnPoolNumber(self)
end
def boutByRound(round)
round_match = allMatches.select{|m| m.round == round}.first
if round_match.blank?
@@ -122,7 +118,7 @@ class Wrestler < ActiveRecord::Base
def poolMatches
pool_matches = allMatches.select{|m| m.bracket_position == "Pool"}
pool_matches.select{|m| m.poolNumber == self.generatePoolNumber}
pool_matches.select{|m| m.poolNumber == self.pool}
end
def hasAPoolBye

View File

@@ -6,7 +6,7 @@ class PoolAdvance
end
def advanceWrestler
if @wrestler.weight.allPoolMatchesFinished(@wrestler.generatePoolNumber) && @wrestler.finishedBracketMatches.size == 0
if @wrestler.weight.allPoolMatchesFinished(@wrestler.pool) && @wrestler.finishedBracketMatches.size == 0
poolToBracketAdvancment
end
if @wrestler.finishedBracketMatches.size > 0
@@ -15,7 +15,7 @@ class PoolAdvance
end
def poolToBracketAdvancment
pool = @wrestler.generatePoolNumber
pool = @wrestler.pool
if @wrestler.weight.wrestlers.size > 6
poolOrder = @wrestler.weight.poolOrder(pool)
#Take pool order and move winner and runner up to correct match based on w1_name and w2_name

View File

@@ -6,12 +6,13 @@ class PoolGeneration
end
def generatePools
GeneratePoolNumbers.new(@weight).savePoolNumbers
pools = @weight.pools
while @pool <= pools
roundRobin
@pool += 1
end
end
end
def roundRobin
wrestlers = @weight.wrestlersForPool(@pool)

View File

@@ -0,0 +1,77 @@
class GeneratePoolNumbers
def initialize( weight )
@weight = weight
end
def savePoolNumbers
if @weight.pools == 4
saveFourPoolNumbers(@weight.wrestlers)
elsif @weight.pools == 2
saveTwoPoolNumbers(@weight.wrestlers)
elsif @weight.pools == 1
saveOnePoolNumbers(@weight.wrestlers)
end
end
def saveOnePoolNumbers(poolWrestlers)
poolWrestlers.sort_by{|x| x.seed }.each do |w|
w.pool = 1
w.save
end
end
def saveTwoPoolNumbers(poolWrestlers)
pool = 1
poolWrestlers.sort_by{|x| x.seed }.reverse.each do |w|
if w.seed == 1
w.pool = 1
elsif w.seed == 2
w.pool = 2
elsif w.seed == 3
w.pool = 2
elsif w.seed == 4
w.pool = 1
else
w.pool = pool
end
if pool < 2
pool = pool + 1
else
pool = 1
end
w.save
end
end
def saveFourPoolNumbers(poolWrestlers)
pool = 1
poolWrestlers.sort_by{|x| x.seed }.reverse.each do |w|
if w.seed == 1
w.pool = 1
elsif w.seed == 2
w.pool = 2
elsif w.seed == 3
w.pool = 3
elsif w.seed == 4
w.pool = 4
elsif w.seed == 8
w.pool = 1
elsif w.seed == 7
w.pool = 2
elsif w.seed == 6
w.pool = 3
elsif w.seed == 5
w.pool = 4
else
w.pool = pool
end
if pool < 4
pool = pool + 1
else
pool = 1
end
w.save
end
end
end

View File

@@ -1,6 +1,6 @@
<% @round = 1 %>
<% @pool = 1 %>
<% until @wrestlers.select{|w| w.generatePoolNumber == @pool}.blank? %>
<% until @wrestlers.select{|w| w.pool == @pool}.blank? %>
<h5>Pool <%= @pool %></h5>
<table class="table table-striped table-bordered table-condensed">
<thead>
@@ -15,7 +15,7 @@
</tr>
</thead>
<tbody>
<% @wrestlers.select{|w| w.generatePoolNumber == @pool}.sort_by{|w| w.seed}.each do |w| %>
<% @wrestlers.select{|w| w.pool == @pool}.sort_by{|w| w.seed}.each do |w| %>
<tr>
<td><%= w.original_seed %> <%= w.name %> <%= w.season_win %>-<%= w.season_loss %> <%= w.school.name %></td>
<% @round = 1 %>

View File

@@ -37,6 +37,7 @@ module Wrestling
config.autoload_paths += %W(#{config.root}/app/services/tournament_services)
config.autoload_paths += %W(#{config.root}/app/services/wrestler_services)
config.autoload_paths += %W(#{config.root}/app/services/weight_services)
config.autoload_paths += %W(#{config.root}/app/services/bracket_advancement)
end

View File

@@ -0,0 +1,5 @@
class AddPoolColumn < ActiveRecord::Migration
def change
add_column :wrestlers, :pool, :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: 20160126173424) do
ActiveRecord::Schema.define(version: 20170301174920) do
create_table "delayed_jobs", force: :cascade do |t|
t.integer "priority", default: 0, null: false
@@ -154,6 +154,7 @@ ActiveRecord::Schema.define(version: 20160126173424) do
t.string "criteria"
t.boolean "extra"
t.decimal "offical_weight"
t.integer "pool"
end
add_index "wrestlers", ["weight_id"], name: "index_wrestlers_on_weight_id"

View File

@@ -1,4 +1,4 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
tournament_1_wrestler_1:
id: 1
@@ -11,6 +11,7 @@ tournament_1_wrestler_1:
season_win: 30
criteria: SQ
extra:
pool: 1
tournament_1_wrestler_2:
id: 2
@@ -23,6 +24,7 @@ tournament_1_wrestler_2:
season_win: 30
criteria: DP 6th
extra:
pool: 1
tournament_1_wrestler_3:
id: 3
@@ -35,6 +37,7 @@ tournament_1_wrestler_3:
season_win: 49
criteria: SP 2nd
extra:
pool: 1
tournament_1_wrestler_4:
id: 4
@@ -47,6 +50,7 @@ tournament_1_wrestler_4:
season_win: 30
criteria: DP 5th
extra:
pool: 1
tournament_1_wrestler_5:
id: 5
@@ -59,6 +63,7 @@ tournament_1_wrestler_5:
season_win: 49
criteria: SP 5th
extra:
pool: 1
tournament_1_wrestler_6:
id: 6
@@ -71,6 +76,7 @@ tournament_1_wrestler_6:
season_win: 16
criteria:
extra:
pool: 2
tournament_1_wrestler_7:
id: 7
@@ -83,6 +89,7 @@ tournament_1_wrestler_7:
season_win: 16
criteria: DQ
extra:
pool: 1
tournament_1_wrestler_8:
id: 8
@@ -95,6 +102,7 @@ tournament_1_wrestler_8:
season_win: 50
criteria: SQ
extra:
pool: 2
tournament_1_wrestler_9:
id: 9
@@ -107,6 +115,7 @@ tournament_1_wrestler_9:
season_win: 40
criteria: SQ
extra:
pool: 2
tournament_1_wrestler_10:
id: 10
@@ -119,6 +128,7 @@ tournament_1_wrestler_10:
season_win: 50
criteria:
extra:
pool: 1
tournament_1_wrestler_11:
id: 11
@@ -131,6 +141,7 @@ tournament_1_wrestler_11:
season_win: 20
criteria: DP 6th
extra:
pool: 1
tournament_1_wrestler_12:
id: 12
@@ -143,6 +154,7 @@ tournament_1_wrestler_12:
season_win: 30
criteria: SP 7th
extra:
pool: 1
tournament_1_wrestler_13:
id: 13
@@ -155,6 +167,7 @@ tournament_1_wrestler_13:
season_win: 50
criteria:
extra:
pool: 1
tournament_1_wrestler_14:
id: 14
@@ -167,6 +180,7 @@ tournament_1_wrestler_14:
season_win: 50
criteria:
extra:
pool: 2
tournament_1_wrestler_15:
id: 15
@@ -179,6 +193,7 @@ tournament_1_wrestler_15:
season_win: 50
criteria:
extra:
pool: 2
tournament_1_wrestler_16:
id: 16
@@ -191,6 +206,7 @@ tournament_1_wrestler_16:
season_win: 50
criteria:
extra:
pool: 2
tournament_1_wrestler_17:
id: 17
@@ -203,6 +219,7 @@ tournament_1_wrestler_17:
season_win: 50
criteria:
extra:
pool: 2
tournament_1_wrestler_18:
id: 18
@@ -215,6 +232,7 @@ tournament_1_wrestler_18:
season_win: 50
criteria:
extra:
pool: 1
tournament_1_wrestler_19:
id: 19
@@ -227,6 +245,7 @@ tournament_1_wrestler_19:
season_win: 50
criteria:
extra:
pool: 1
tournament_1_wrestler_20:
id: 20
@@ -239,6 +258,7 @@ tournament_1_wrestler_20:
season_win: 50
criteria:
extra:
pool: 1
tournament_1_wrestler_21:
id: 21
@@ -251,6 +271,7 @@ tournament_1_wrestler_21:
season_win: 50
criteria:
extra:
pool: 1
tournament_1_wrestler_22:
id: 22
@@ -263,6 +284,7 @@ tournament_1_wrestler_22:
season_win: 50
criteria:
extra:
pool: 2
tournament_1_wrestler_23:
id: 23
@@ -275,6 +297,7 @@ tournament_1_wrestler_23:
season_win: 50
criteria:
extra:
pool: 2
tournament_1_wrestler_24:
id: 24
@@ -287,6 +310,7 @@ tournament_1_wrestler_24:
season_win: 50
criteria:
extra:
pool: 3
tournament_1_wrestler_25:
id: 25
@@ -299,6 +323,7 @@ tournament_1_wrestler_25:
season_win: 50
criteria:
extra:
pool: 3
tournament_1_wrestler_26:
id: 26
@@ -311,6 +336,7 @@ tournament_1_wrestler_26:
season_win: 50
criteria:
extra:
pool: 4
tournament_1_wrestler_27:
id: 27
@@ -323,6 +349,7 @@ tournament_1_wrestler_27:
season_win: 50
criteria:
extra:
pool: 1
tournament_1_wrestler_28:
id: 28
@@ -335,6 +362,7 @@ tournament_1_wrestler_28:
season_win: 50
criteria:
extra:
pool: 1
tournament_1_wrestler_29:
id: 29
@@ -347,6 +375,7 @@ tournament_1_wrestler_29:
season_win: 50
criteria:
extra:
pool: 4
tournament_1_wrestler_30:
id: 30
@@ -359,6 +388,7 @@ tournament_1_wrestler_30:
season_win: 50
criteria:
extra:
pool: 1
tournament_1_wrestler_31:
id: 31
@@ -371,6 +401,7 @@ tournament_1_wrestler_31:
season_win: 50
criteria:
extra:
pool: 2
tournament_1_wrestler_32:
id: 32
@@ -383,6 +414,7 @@ tournament_1_wrestler_32:
season_win: 50
criteria:
extra:
pool: 3
tournament_1_wrestler_33:
id: 33
@@ -395,6 +427,7 @@ tournament_1_wrestler_33:
season_win: 50
criteria:
extra:
pool: 2
tournament_1_wrestler_34:
id: 34
@@ -407,6 +440,7 @@ tournament_1_wrestler_34:
season_win: 50
criteria:
extra:
pool: 3
tournament_1_wrestler_35:
id: 35
@@ -419,6 +453,7 @@ tournament_1_wrestler_35:
season_win: 50
criteria:
extra:
pool: 1
tournament_1_wrestler_36:
id: 36
@@ -431,6 +466,7 @@ tournament_1_wrestler_36:
season_win: 50
criteria:
extra:
pool: 2
tournament_1_wrestler_37:
id: 37
@@ -443,6 +479,7 @@ tournament_1_wrestler_37:
season_win: 50
criteria:
extra:
pool: 2
tournament_1_wrestler_38:
id: 38
@@ -455,6 +492,7 @@ tournament_1_wrestler_38:
season_win: 50
criteria:
extra:
pool: 4
tournament_1_wrestler_39:
id: 39
@@ -467,6 +505,7 @@ tournament_1_wrestler_39:
season_win: 50
criteria:
extra:
pool: 1
tournament_1_wrestler_40:
id: 40
@@ -479,6 +518,7 @@ tournament_1_wrestler_40:
season_win: 50
criteria:
extra:
pool: 4
tournament_1_wrestler_41:
id: 41
@@ -491,6 +531,7 @@ tournament_1_wrestler_41:
season_win: 50
criteria:
extra:
pool: 3
tournament_1_wrestler_42:
id: 42
@@ -503,6 +544,7 @@ tournament_1_wrestler_42:
season_win: 50
criteria:
extra:
pool: 4
tournament_1_wrestler_43:
id: 43
@@ -515,6 +557,7 @@ tournament_1_wrestler_43:
season_win: 50
criteria:
extra:
pool: 3
tournament_1_wrestler_44:
id: 44
@@ -527,6 +570,7 @@ tournament_1_wrestler_44:
season_win: 50
criteria:
extra:
pool: 2
tournament_1_wrestler_45:
id: 45
@@ -539,6 +583,7 @@ tournament_1_wrestler_45:
season_win: 50
criteria:
extra:
pool: 1
tournament_1_wrestler_46:
id: 46
@@ -551,6 +596,7 @@ tournament_1_wrestler_46:
season_win: 50
criteria:
extra:
pool: 1
tournament_1_wrestler_47:
id: 47
@@ -563,6 +609,7 @@ tournament_1_wrestler_47:
season_win: 50
criteria:
extra:
pool: 3
tournament_1_wrestler_48:
id: 48
@@ -575,6 +622,7 @@ tournament_1_wrestler_48:
season_win: 50
criteria:
extra:
pool: 4
tournament_1_wrestler_49:
id: 49
@@ -582,11 +630,12 @@ tournament_1_wrestler_49:
school_id: 1
weight_id: 6
original_seed:
seed: 4
seed: 6
season_loss: 2
season_win: 50
criteria:
extra:
pool: 1
tournament_1_wrestler_50:
id: 50
@@ -599,6 +648,7 @@ tournament_1_wrestler_50:
season_win: 50
criteria:
extra:
pool: 1
tournament_1_wrestler_51:
id: 51
@@ -606,23 +656,25 @@ tournament_1_wrestler_51:
school_id: 1
weight_id: 6
original_seed:
seed: 3
season_loss: 2
season_win: 50
criteria:
extra:
tournament_1_wrestler_52:
id: 52
name: Guy43
school_id: 1
weight_id: 6
original_seed:
seed: 5
season_loss: 2
season_win: 50
criteria:
extra:
pool: 1
tournament_1_wrestler_52:
id: 52
name: Guy43
school_id: 1
weight_id: 6
original_seed:
seed: 3
season_loss: 2
season_win: 50
criteria:
extra:
pool: 1
tournament_1_wrestler_53:
id: 53
@@ -630,8 +682,12 @@ tournament_1_wrestler_53:
school_id: 1
weight_id: 6
original_seed:
seed: 6
seed: 4
season_loss: 2
season_win: 50
criteria:
extra:
extra:
pool: 1

View File

@@ -3,7 +3,7 @@ require 'test_helper'
class SingleTestTest < ActionDispatch::IntegrationTest
def setup
@tournament = Tournament.find(1)
# @tournament.generateMatchups
# GenerateTournamentMatches.new(@tournament).generate
end
#rake test test/integration/single_test_test.rb > matches.txt
@@ -47,6 +47,7 @@ class SingleTestTest < ActionDispatch::IntegrationTest
# puts " season_win: #{w.season_win}"
# puts " criteria: #{w.criteria}"
# puts " extra: #{w.extra}"
# puts " pool: #{w.pool}"
# puts ""
# count += 1
# end