mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-04-07 06:54:16 +00:00
Making progress on generating matches.
This commit is contained in:
@@ -1,11 +0,0 @@
|
||||
class Bout
|
||||
attr_accessor :w1, :w2, :tournament_id
|
||||
def self.all
|
||||
ObjectSpace.each_object(self).to_a
|
||||
end
|
||||
|
||||
def self.count
|
||||
all.count
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,30 +0,0 @@
|
||||
class Pool
|
||||
def createPool(tournament)
|
||||
@weights = Weight.where(tournament_id: tournament)
|
||||
@weights.each do |weight|
|
||||
roundRobin(weight,tournament)
|
||||
end
|
||||
end
|
||||
|
||||
def createBout(wrestler,tournament)
|
||||
@bout = Bout.new
|
||||
@bout.w1 = wrestler.id
|
||||
@bout.tournament_id = tournament
|
||||
end
|
||||
|
||||
def roundRobin(weight,tournament)
|
||||
@wrestlers = Wrestler.where(weight_id: weight)
|
||||
@wrestlers.each do |wrestler|
|
||||
createBout(wrestler,tournament)
|
||||
end
|
||||
end
|
||||
|
||||
def self.all
|
||||
ObjectSpace.each_object(self).to_a
|
||||
end
|
||||
|
||||
def self.count
|
||||
all.count
|
||||
end
|
||||
|
||||
end
|
||||
@@ -4,10 +4,19 @@ class Tournament < ActiveRecord::Base
|
||||
has_many :matches, dependent: :destroy
|
||||
has_many :mats, dependent: :destroy
|
||||
|
||||
def bouts
|
||||
@pool = Pool.new
|
||||
@pool.createPool(self.id)
|
||||
@bouts = Bout.all
|
||||
return @bouts
|
||||
def generateMatches
|
||||
destroyAllMatches
|
||||
self.weights.each do |weight|
|
||||
puts weight.inspect
|
||||
weight.generatePool
|
||||
end
|
||||
end
|
||||
|
||||
def destroyAllMatches
|
||||
@matches_all = Match.where(tournament_id: self.id)
|
||||
@matches_all.each do |match|
|
||||
match.destroy
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -2,5 +2,32 @@ class Weight < ActiveRecord::Base
|
||||
belongs_to :tournament
|
||||
has_many :wrestlers, dependent: :destroy
|
||||
|
||||
|
||||
attr_accessor :pools
|
||||
|
||||
def generatePool
|
||||
@wrestlers = Wrestler.where(weight_id: self.id)
|
||||
poolNumber(@wrestlers)
|
||||
@wrestlers.each do |wrestler|
|
||||
puts wrestler.inspect
|
||||
|
||||
end
|
||||
puts 'Pool size:'
|
||||
puts self.pools
|
||||
end
|
||||
|
||||
def poolNumber(wrestlers)
|
||||
if wrestlers.size <= 5
|
||||
self.pools = 1
|
||||
elsif (wrestlers.size > 5) && (wrestlers.size <= 8)
|
||||
self.pools = 2
|
||||
elsif (wrestlers.size > 8) && (wrestlers.size <= 16)
|
||||
self.pools = 4
|
||||
end
|
||||
end
|
||||
|
||||
def fourPool
|
||||
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user