mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-04-18 21:42:16 +00:00
Moved poolNumber generation to weight.
This commit is contained in:
@@ -39,10 +39,10 @@ class StaticPagesController < ApplicationController
|
|||||||
@tournament = Tournament.find(@weight.tournament_id)
|
@tournament = Tournament.find(@weight.tournament_id)
|
||||||
@matches = @tournament.upcomingMatches
|
@matches = @tournament.upcomingMatches
|
||||||
@wrestlers = Wrestler.where(weight_id: @weight.id)
|
@wrestlers = Wrestler.where(weight_id: @weight.id)
|
||||||
@poolOneWrestlers = @wrestlers.select{|w| w.poolNumber == 1}
|
@poolOneWrestlers = @wrestlers.select{|w| w.generatePoolNumber == 1}
|
||||||
@poolTwoWrestlers = @wrestlers.select{|w| w.poolNumber == 2}
|
@poolTwoWrestlers = @wrestlers.select{|w| w.generatePoolNumber == 2}
|
||||||
@poolThreeWrestlers = @wrestlers.select{|w| w.poolNumber == 3}
|
@poolThreeWrestlers = @wrestlers.select{|w| w.generatePoolNumber == 3}
|
||||||
@poolFourWrestlers = @wrestlers.select{|w| w.poolNumber == 4}
|
@poolFourWrestlers = @wrestlers.select{|w| w.generatePoolNumber == 4}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,69 +1,16 @@
|
|||||||
class Pool
|
class Pool
|
||||||
def onePool(wrestlers,weight,tournament,matches)
|
def generatePools(pools,wrestlers,weight,tournament,matches)
|
||||||
wrestlers.sort_by{|x|[x.original_seed]}.each do |w|
|
@pools = pools
|
||||||
w.poolNumber = 1
|
|
||||||
end
|
|
||||||
matches = roundRobin(1,tournament,weight,matches,wrestlers)
|
|
||||||
return matches
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
def twoPools(wrestlers,weight,tournament,matches)
|
|
||||||
pool = 1
|
|
||||||
wrestlers.sort_by{|x|[x.original_seed]}.reverse.each do |w|
|
|
||||||
if w.original_seed == 1
|
|
||||||
w.poolNumber = 1
|
|
||||||
elsif w.original_seed == 2
|
|
||||||
w.poolNumber = 2
|
|
||||||
elsif w.original_seed == 3
|
|
||||||
w.poolNumber = 2
|
|
||||||
elsif w.original_seed == 4
|
|
||||||
w.poolNumber = 1
|
|
||||||
else
|
|
||||||
w.poolNumber = pool
|
|
||||||
end
|
|
||||||
if pool < 2
|
|
||||||
pool = pool + 1
|
|
||||||
else
|
|
||||||
pool =1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
matches = roundRobin(1,tournament,weight,matches,wrestlers)
|
|
||||||
matches = roundRobin(2,tournament,weight,matches,wrestlers)
|
|
||||||
return matches
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
def fourPools(wrestlers,weight,tournament,matches)
|
|
||||||
@pool = 1
|
@pool = 1
|
||||||
wrestlers.sort_by{|x|[x.original_seed]}.reverse.each do |w|
|
while @pool <= @pools
|
||||||
if w.original_seed == 3
|
matches = roundRobin(@pool,wrestlers,weight,tournament,matches)
|
||||||
w.poolNumber = 3
|
@pool = @pool +1
|
||||||
elsif w.original_seed == 4
|
|
||||||
w.poolNumber = 4
|
|
||||||
elsif w.original_seed == 1
|
|
||||||
w.poolNumber = 1
|
|
||||||
elsif w.original_seed == 2
|
|
||||||
w.poolNumber = 2
|
|
||||||
else
|
|
||||||
w.poolNumber = @pool
|
|
||||||
end
|
|
||||||
if @pool < 4
|
|
||||||
@pool = @pool + 1
|
|
||||||
else
|
|
||||||
@pool =1
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
matches = roundRobin(1,tournament,weight,matches,wrestlers)
|
|
||||||
matches = roundRobin(2,tournament,weight,matches,wrestlers)
|
|
||||||
matches = roundRobin(3,tournament,weight,matches,wrestlers)
|
|
||||||
matches = roundRobin(4,tournament,weight,matches,wrestlers)
|
|
||||||
return matches
|
return matches
|
||||||
end
|
end
|
||||||
|
|
||||||
def roundRobin(pool,tournament_id,weight,matches,wrestlers)
|
def roundRobin(pool,wrestlers,weight,tournament,matches)
|
||||||
@wrestlers = wrestlers.select{|w| w.poolNumber == pool}.to_a
|
@wrestlers = wrestlers.select{|w| w.generatePoolNumber == pool}.to_a
|
||||||
@poolMatches = RoundRobinTournament.schedule(@wrestlers).reverse
|
@poolMatches = RoundRobinTournament.schedule(@wrestlers).reverse
|
||||||
@poolMatches.each_with_index do |b,index|
|
@poolMatches.each_with_index do |b,index|
|
||||||
@bout = b.map
|
@bout = b.map
|
||||||
|
|||||||
@@ -15,6 +15,73 @@ class Weight < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
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 fourPoolNumbers(wrestlers)
|
||||||
|
@pool = 1
|
||||||
|
wrestlers.sort_by{|x|[x.original_seed]}.reverse.each do |w|
|
||||||
|
if w.original_seed == 3
|
||||||
|
w.poolNumber = 3
|
||||||
|
elsif w.original_seed == 4
|
||||||
|
w.poolNumber = 4
|
||||||
|
elsif w.original_seed == 1
|
||||||
|
w.poolNumber = 1
|
||||||
|
elsif w.original_seed == 2
|
||||||
|
w.poolNumber = 2
|
||||||
|
else
|
||||||
|
w.poolNumber = @pool
|
||||||
|
end
|
||||||
|
if @pool < 4
|
||||||
|
@pool = @pool + 1
|
||||||
|
else
|
||||||
|
@pool =1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return wrestlers
|
||||||
|
end
|
||||||
|
|
||||||
|
def onePoolNumbers(wrestlers)
|
||||||
|
wrestlers.sort_by{|x|[x.original_seed]}.each do |w|
|
||||||
|
w.poolNumber = 1
|
||||||
|
end
|
||||||
|
return wrestlers
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def twoPoolNumbers(wrestlers)
|
||||||
|
pool = 1
|
||||||
|
wrestlers.sort_by{|x|[x.original_seed]}.reverse.each do |w|
|
||||||
|
if w.original_seed == 1
|
||||||
|
w.poolNumber = 1
|
||||||
|
elsif w.original_seed == 2
|
||||||
|
w.poolNumber = 2
|
||||||
|
elsif w.original_seed == 3
|
||||||
|
w.poolNumber = 2
|
||||||
|
elsif w.original_seed == 4
|
||||||
|
w.poolNumber = 1
|
||||||
|
else
|
||||||
|
w.poolNumber = pool
|
||||||
|
end
|
||||||
|
if pool < 2
|
||||||
|
pool = pool + 1
|
||||||
|
else
|
||||||
|
pool =1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return wrestlers
|
||||||
|
end
|
||||||
|
|
||||||
def bracket_size
|
def bracket_size
|
||||||
@wrestlers = Wrestler.where(weight_id: self.id)
|
@wrestlers = Wrestler.where(weight_id: self.id)
|
||||||
return @wrestlers.size
|
return @wrestlers.size
|
||||||
@@ -35,16 +102,15 @@ class Weight < ActiveRecord::Base
|
|||||||
|
|
||||||
def generateMatchups(matches)
|
def generateMatchups(matches)
|
||||||
@wrestlers = self.wrestlers
|
@wrestlers = self.wrestlers
|
||||||
#@wrestlers.sort_by{|w| [w.original_seed]}
|
|
||||||
if self.pools == 1
|
if self.pools == 1
|
||||||
@pool = Pool.new
|
@pool = Pool.new
|
||||||
@matches = @pool.onePool(@wrestlers,self,self.tournament_id,matches)
|
@matches = @pool.generatePools(1,@wrestlers,self,self.tournament_id,matches)
|
||||||
elsif self.pools == 2
|
elsif self.pools == 2
|
||||||
@pool = Pool.new
|
@pool = Pool.new
|
||||||
@matches = @pool.twoPools(@wrestlers,self,self.tournament_id,matches)
|
@matches = @pool.generatePools(2,@wrestlers,self,self.tournament_id,matches)
|
||||||
elsif self.pools == 4
|
elsif self.pools == 4
|
||||||
@pool = Pool.new
|
@pool = Pool.new
|
||||||
@matches = @pool.fourPools(@wrestlers,self,self.tournament_id,matches)
|
@matches = @pool.generatePools(4,@wrestlers,self,self.tournament_id,matches)
|
||||||
end
|
end
|
||||||
return @matches
|
return @matches
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
class Wrestler < ActiveRecord::Base
|
class Wrestler < ActiveRecord::Base
|
||||||
belongs_to :school
|
belongs_to :school
|
||||||
belongs_to :weight
|
belongs_to :weight
|
||||||
attr_accessor :matches_all, :isWrestlingThisRound, :boutByRound, :seasonWinPercentage
|
attr_accessor :matches_all, :isWrestlingThisRound, :boutByRound, :seasonWinPercentage, :poolNumber
|
||||||
|
|
||||||
def isWrestlingThisRound(matchRound)
|
def isWrestlingThisRound(matchRound)
|
||||||
@gMatches = Match.where(g_id: self.id, round: matchRound)
|
@gMatches = Match.where(g_id: self.id, round: matchRound)
|
||||||
@@ -14,6 +14,11 @@ class Wrestler < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def generatePoolNumber
|
||||||
|
@pool = self.weight.returnPoolNumber(self)
|
||||||
|
return @pool
|
||||||
|
end
|
||||||
|
|
||||||
def boutByRound(round,matches)
|
def boutByRound(round,matches)
|
||||||
@matches = matches.select{|m| m.w1 == self.id || m.w2 == self.id}
|
@matches = matches.select{|m| m.w1 == self.id || m.w2 == self.id}
|
||||||
@match = @matches.select{|m| m.round == round}.first
|
@match = @matches.select{|m| m.round == round}.first
|
||||||
|
|||||||
5
db/migrate/20150317122709_drop_pool_number.rb
Normal file
5
db/migrate/20150317122709_drop_pool_number.rb
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
class DropPoolNumber < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
remove_column :wrestlers, :poolNumber
|
||||||
|
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: 20150316131043) do
|
ActiveRecord::Schema.define(version: 20150317122709) do
|
||||||
|
|
||||||
create_table "matches", force: :cascade do |t|
|
create_table "matches", force: :cascade do |t|
|
||||||
t.integer "r_id"
|
t.integer "r_id"
|
||||||
@@ -89,7 +89,6 @@ ActiveRecord::Schema.define(version: 20150316131043) do
|
|||||||
t.integer "season_win"
|
t.integer "season_win"
|
||||||
t.integer "season_loss"
|
t.integer "season_loss"
|
||||||
t.string "criteria"
|
t.string "criteria"
|
||||||
t.integer "poolNumber"
|
|
||||||
t.boolean "extra"
|
t.boolean "extra"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -46,6 +46,11 @@ if Rails.env.development?
|
|||||||
Wrestler.create(name: 'Guy 27', school_id: 202, weight_id: 201, original_seed: 11, season_win: 0, season_loss: 0, criteria: 'N/A')
|
Wrestler.create(name: 'Guy 27', school_id: 202, weight_id: 201, original_seed: 11, season_win: 0, season_loss: 0, criteria: 'N/A')
|
||||||
Wrestler.create(name: 'Guy 28', school_id: 203, weight_id: 201, original_seed: 12, season_win: 0, season_loss: 0, criteria: 'N/A')
|
Wrestler.create(name: 'Guy 28', school_id: 203, weight_id: 201, original_seed: 12, season_win: 0, season_loss: 0, criteria: 'N/A')
|
||||||
Wrestler.create(name: 'Guy 29', school_id: 204, weight_id: 201, original_seed: 13, season_win: 0, season_loss: 0, criteria: 'N/A')
|
Wrestler.create(name: 'Guy 29', school_id: 204, weight_id: 201, original_seed: 13, season_win: 0, season_loss: 0, criteria: 'N/A')
|
||||||
|
Wrestler.create(name: 'Guy 30', school_id: 204, weight_id: 202, original_seed: 13, season_win: 0, season_loss: 0, criteria: 'N/A')
|
||||||
|
Wrestler.create(name: 'Guy 31', school_id: 204, weight_id: 202, original_seed: 13, season_win: 0, season_loss: 0, criteria: 'N/A')
|
||||||
|
Wrestler.create(name: 'Guy 32', school_id: 204, weight_id: 202, original_seed: 13, season_win: 0, season_loss: 0, criteria: 'N/A')
|
||||||
|
Wrestler.create(name: 'Guy 33', school_id: 204, weight_id: 202, original_seed: 13, season_win: 0, season_loss: 0, criteria: 'N/A')
|
||||||
|
Wrestler.create(name: 'Guy 34', school_id: 204, weight_id: 202, original_seed: 13, season_win: 0, season_loss: 0, criteria: 'N/A')
|
||||||
end
|
end
|
||||||
|
|
||||||
if Rails.env.production?
|
if Rails.env.production?
|
||||||
|
|||||||
Reference in New Issue
Block a user