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

Moved poolNumber generation to weight.

This commit is contained in:
2015-03-17 09:06:21 -04:00
parent d6a9abffac
commit c86f678fd1
7 changed files with 98 additions and 71 deletions

View File

@@ -39,10 +39,10 @@ class StaticPagesController < ApplicationController
@tournament = Tournament.find(@weight.tournament_id)
@matches = @tournament.upcomingMatches
@wrestlers = Wrestler.where(weight_id: @weight.id)
@poolOneWrestlers = @wrestlers.select{|w| w.poolNumber == 1}
@poolTwoWrestlers = @wrestlers.select{|w| w.poolNumber == 2}
@poolThreeWrestlers = @wrestlers.select{|w| w.poolNumber == 3}
@poolFourWrestlers = @wrestlers.select{|w| w.poolNumber == 4}
@poolOneWrestlers = @wrestlers.select{|w| w.generatePoolNumber == 1}
@poolTwoWrestlers = @wrestlers.select{|w| w.generatePoolNumber == 2}
@poolThreeWrestlers = @wrestlers.select{|w| w.generatePoolNumber == 3}
@poolFourWrestlers = @wrestlers.select{|w| w.generatePoolNumber == 4}
end

View File

@@ -1,69 +1,16 @@
class Pool
def onePool(wrestlers,weight,tournament,matches)
wrestlers.sort_by{|x|[x.original_seed]}.each do |w|
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)
def generatePools(pools,wrestlers,weight,tournament,matches)
@pools = pools
@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
while @pool <= @pools
matches = roundRobin(@pool,wrestlers,weight,tournament,matches)
@pool = @pool +1
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
end
def roundRobin(pool,tournament_id,weight,matches,wrestlers)
@wrestlers = wrestlers.select{|w| w.poolNumber == pool}.to_a
def roundRobin(pool,wrestlers,weight,tournament,matches)
@wrestlers = wrestlers.select{|w| w.generatePoolNumber == pool}.to_a
@poolMatches = RoundRobinTournament.schedule(@wrestlers).reverse
@poolMatches.each_with_index do |b,index|
@bout = b.map

View File

@@ -15,6 +15,73 @@ class Weight < ActiveRecord::Base
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
@wrestlers = Wrestler.where(weight_id: self.id)
return @wrestlers.size
@@ -35,16 +102,15 @@ class Weight < ActiveRecord::Base
def generateMatchups(matches)
@wrestlers = self.wrestlers
#@wrestlers.sort_by{|w| [w.original_seed]}
if self.pools == 1
@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
@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
@pool = Pool.new
@matches = @pool.fourPools(@wrestlers,self,self.tournament_id,matches)
@matches = @pool.generatePools(4,@wrestlers,self,self.tournament_id,matches)
end
return @matches
end

View File

@@ -1,7 +1,7 @@
class Wrestler < ActiveRecord::Base
belongs_to :school
belongs_to :weight
attr_accessor :matches_all, :isWrestlingThisRound, :boutByRound, :seasonWinPercentage
attr_accessor :matches_all, :isWrestlingThisRound, :boutByRound, :seasonWinPercentage, :poolNumber
def isWrestlingThisRound(matchRound)
@gMatches = Match.where(g_id: self.id, round: matchRound)
@@ -14,6 +14,11 @@ class Wrestler < ActiveRecord::Base
end
end
def generatePoolNumber
@pool = self.weight.returnPoolNumber(self)
return @pool
end
def boutByRound(round,matches)
@matches = matches.select{|m| m.w1 == self.id || m.w2 == self.id}
@match = @matches.select{|m| m.round == round}.first

View File

@@ -0,0 +1,5 @@
class DropPoolNumber < ActiveRecord::Migration
def change
remove_column :wrestlers, :poolNumber
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: 20150316131043) do
ActiveRecord::Schema.define(version: 20150317122709) do
create_table "matches", force: :cascade do |t|
t.integer "r_id"
@@ -89,7 +89,6 @@ ActiveRecord::Schema.define(version: 20150316131043) do
t.integer "season_win"
t.integer "season_loss"
t.string "criteria"
t.integer "poolNumber"
t.boolean "extra"
end

View File

@@ -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 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 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
if Rails.env.production?