mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-04-16 21:11:38 +00:00
Merge pull request #3 from rjo1970/master
Pool and tournament generation work
This commit is contained in:
@@ -1,24 +1,34 @@
|
|||||||
class Pool
|
class Pool
|
||||||
def generatePools(weight, tournament, matches)
|
def initialize(weight)
|
||||||
@pools = weight.pools
|
@weight = weight
|
||||||
@pool = 1
|
@pool = 1
|
||||||
while @pool <= @pools
|
end
|
||||||
matches = roundRobin(weight.wrestlers, weight, tournament, matches)
|
|
||||||
|
def generatePools
|
||||||
|
matches = []
|
||||||
|
pools = @weight.pools
|
||||||
|
while @pool <= pools
|
||||||
|
matches += roundRobin()
|
||||||
@pool += 1
|
@pool += 1
|
||||||
end
|
end
|
||||||
return matches
|
return matches
|
||||||
end
|
end
|
||||||
|
|
||||||
def roundRobin(wrestlers,weight,tournament,matches)
|
def roundRobin
|
||||||
@wrestlers = wrestlers.select{|w| w.generatePoolNumber == @pool}.to_a
|
matches = []
|
||||||
@poolMatches = RoundRobinTournament.schedule(@wrestlers).reverse
|
wrestlers = @weight.wrestlers_for_pool(@pool)
|
||||||
@poolMatches.each_with_index do |b, index|
|
poolMatches = RoundRobinTournament.schedule(wrestlers).reverse
|
||||||
|
poolMatches.each_with_index do |b, index|
|
||||||
round = index + 1
|
round = index + 1
|
||||||
@bout = b.map
|
bouts = b.map
|
||||||
@bout.each do |bout|
|
bouts.each do |bout|
|
||||||
if bout[0] != nil and bout[1] != nil
|
if bout[0] != nil and bout[1] != nil
|
||||||
@match = Match.new(w1: bout[0].id, w2: bout[1].id, weight_id: weight.id, round: round)
|
match = Match.new(
|
||||||
matches << @match
|
w1: bout[0].id,
|
||||||
|
w2: bout[1].id,
|
||||||
|
weight_id: @weight.id,
|
||||||
|
round: round)
|
||||||
|
matches << match
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -28,15 +28,15 @@ class Tournament < ActiveRecord::Base
|
|||||||
|
|
||||||
def upcomingMatches
|
def upcomingMatches
|
||||||
if matches.nil?
|
if matches.nil?
|
||||||
return matches
|
return nil
|
||||||
else
|
else
|
||||||
generateMatchups
|
generateMatchups
|
||||||
return matches
|
matches
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def generateMatchups
|
def generateMatchups
|
||||||
@matches = Tournamentmatchgen.new.genMatches(self)
|
@matches = Tournamentmatchgen.new(self).genMatches()
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroyAllMatches
|
def destroyAllMatches
|
||||||
@@ -44,6 +44,3 @@ class Tournament < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,36 +1,51 @@
|
|||||||
class Tournamentmatchgen
|
class Tournamentmatchgen
|
||||||
def genMatches(tournament)
|
|
||||||
if tournament.tournament_type == "Pool to bracket"
|
def initialize(tournament)
|
||||||
@matches = poolToBracket(tournament)
|
@tournament = tournament
|
||||||
end
|
@matches = @tournament.matches
|
||||||
return @matches
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def poolToBracket(tournament)
|
def genMatches
|
||||||
tournament.destroyAllMatches
|
if @tournament.tournament_type == "Pool to bracket"
|
||||||
|
@matches = poolToBracket()
|
||||||
|
end
|
||||||
|
@matches
|
||||||
|
end
|
||||||
|
|
||||||
|
def poolToBracket
|
||||||
|
destroyMatches
|
||||||
|
buildTournamentWeights
|
||||||
|
generateMatches
|
||||||
|
saveMatches
|
||||||
|
@matches
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroyMatches
|
||||||
|
@tournament.destroyAllMatches
|
||||||
@matches = []
|
@matches = []
|
||||||
tournament.weights.sort_by{|x|[x.max]}.each do |w|
|
end
|
||||||
buildTournamentWeights(tournament.id, w)
|
|
||||||
|
def buildTournamentWeights
|
||||||
|
@tournament.weights.sort_by{|x|[x.max]}.each do |weight|
|
||||||
|
matches = Pool.new(weight).generatePools()
|
||||||
|
last_match = matches.sort_by{|m| m.round}.last
|
||||||
|
highest_round = last_match.round
|
||||||
|
@matches += Poolbracket.new.generateBracketMatches(matches, weight, highest_round)
|
||||||
end
|
end
|
||||||
@matches = Boutgen.new.assignBouts(@matches,tournament.weights)
|
|
||||||
@matches = Losernamegen.new.assignLoserNames(@matches,tournament.weights)
|
|
||||||
saveMatches(tournament,@matches)
|
|
||||||
return @matches
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def buildTournamentWeights(tournament_id, weight)
|
def generateMatches
|
||||||
@wrestlers = weight.wrestlers
|
@matches =
|
||||||
@matches = Pool.new.generatePools(weight, tournament_id, @matches)
|
Losernamegen.new.assignLoserNames(
|
||||||
@weight_matches = @matches.select{|m| m.weight_id == weight.id }
|
Boutgen.new.assignBouts(@matches, @tournament.weights),
|
||||||
@last_match = @weight_matches.sort_by{|m| m.round}.last
|
@tournament.weights)
|
||||||
@highest_round = @last_match.round
|
|
||||||
@matches = Poolbracket.new.generateBracketMatches(@matches, weight, @highest_round)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def saveMatches(tournament,matches)
|
def saveMatches
|
||||||
matches.each do |m|
|
@matches.each do |m|
|
||||||
m.tournament_id = tournament.id
|
m.tournament_id = @tournament.id
|
||||||
m.save
|
m.save
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -8,6 +8,10 @@ class Weight < ActiveRecord::Base
|
|||||||
self.tournament.destroyAllMatches
|
self.tournament.destroyAllMatches
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def wrestlers_for_pool(pool)
|
||||||
|
wrestlers.select{|w| w.generatePoolNumber == pool}.to_a
|
||||||
|
end
|
||||||
|
|
||||||
def pools
|
def pools
|
||||||
@wrestlers = self.wrestlers
|
@wrestlers = self.wrestlers
|
||||||
if @wrestlers.size <= 6
|
if @wrestlers.size <= 6
|
||||||
|
|||||||
10
db/migrate/20150523121319_introduce_indexes.rb
Normal file
10
db/migrate/20150523121319_introduce_indexes.rb
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
class IntroduceIndexes < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_index :weights, :tournament_id
|
||||||
|
add_index :schools, :tournament_id
|
||||||
|
add_index :mats, :tournament_id
|
||||||
|
add_index :matches, :tournament_id
|
||||||
|
add_index :matches, [:w1, :w2], :unique => true
|
||||||
|
add_index :wrestlers, :weight_id
|
||||||
|
end
|
||||||
|
end
|
||||||
13
db/schema.rb
13
db/schema.rb
@@ -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: 20150517075923) do
|
ActiveRecord::Schema.define(version: 20150523121319) do
|
||||||
|
|
||||||
create_table "matches", force: :cascade do |t|
|
create_table "matches", force: :cascade do |t|
|
||||||
t.integer "w1"
|
t.integer "w1"
|
||||||
@@ -34,6 +34,9 @@ ActiveRecord::Schema.define(version: 20150517075923) do
|
|||||||
t.string "loser2_name"
|
t.string "loser2_name"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
add_index "matches", ["tournament_id"], name: "index_matches_on_tournament_id"
|
||||||
|
add_index "matches", ["w1", "w2"], name: "index_matches_on_w1_and_w2", unique: true
|
||||||
|
|
||||||
create_table "mats", force: :cascade do |t|
|
create_table "mats", force: :cascade do |t|
|
||||||
t.string "name"
|
t.string "name"
|
||||||
t.integer "tournament_id"
|
t.integer "tournament_id"
|
||||||
@@ -41,6 +44,8 @@ ActiveRecord::Schema.define(version: 20150517075923) do
|
|||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
add_index "mats", ["tournament_id"], name: "index_mats_on_tournament_id"
|
||||||
|
|
||||||
create_table "schools", force: :cascade do |t|
|
create_table "schools", force: :cascade do |t|
|
||||||
t.string "name"
|
t.string "name"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
@@ -48,6 +53,8 @@ ActiveRecord::Schema.define(version: 20150517075923) do
|
|||||||
t.integer "tournament_id"
|
t.integer "tournament_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
add_index "schools", ["tournament_id"], name: "index_schools_on_tournament_id"
|
||||||
|
|
||||||
create_table "tournaments", force: :cascade do |t|
|
create_table "tournaments", force: :cascade do |t|
|
||||||
t.string "name"
|
t.string "name"
|
||||||
t.string "address"
|
t.string "address"
|
||||||
@@ -83,6 +90,8 @@ ActiveRecord::Schema.define(version: 20150517075923) do
|
|||||||
t.integer "tournament_id"
|
t.integer "tournament_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
add_index "weights", ["tournament_id"], name: "index_weights_on_tournament_id"
|
||||||
|
|
||||||
create_table "wrestlers", force: :cascade do |t|
|
create_table "wrestlers", force: :cascade do |t|
|
||||||
t.string "name"
|
t.string "name"
|
||||||
t.integer "school_id"
|
t.integer "school_id"
|
||||||
@@ -97,4 +106,6 @@ ActiveRecord::Schema.define(version: 20150517075923) do
|
|||||||
t.boolean "extra"
|
t.boolean "extra"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
add_index "wrestlers", ["weight_id"], name: "index_wrestlers_on_weight_id"
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user