1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-04-21 06:22:00 +00:00

Generated bouts and rounds. Need to fix rounds for odd numbered pools.

This commit is contained in:
2015-02-03 10:41:49 -05:00
parent 7ea80b2997
commit 0244d15a8b
8 changed files with 62 additions and 24 deletions

View File

@@ -8,7 +8,7 @@ class StaticPagesController < ApplicationController
@tournament = Tournament.find(params[:tournament]) @tournament = Tournament.find(params[:tournament])
end end
if @tournament if @tournament
@matches = Match.where(tournament_id: @tournament.id) @matches = @tournament.upcomingMatches
end end
end end
def results def results

View File

@@ -1,3 +1,24 @@
class Bout class Bout
def assignBouts(tournament_id)
@round = 1
until matchesByRound(@round, tournament_id).blank? do
@matches = matchesByRound(@round, tournament_id)
giveBout(@matches)
@round += 1
end
end
def matchesByRound(round, tournament_id)
@matches = Match.where(tournament_id: tournament_id, round: round)
return @matches
end
def giveBout(matches)
@matches = matches.sort_by{|x|[x.weight_max]}
@matches.each_with_index do |m, i|
bout = m.round * 100 + i
m.boutNumber = bout
m.save
end
end
end end

View File

@@ -1,6 +1,11 @@
class Match < ActiveRecord::Base class Match < ActiveRecord::Base
belongs_to :tournament belongs_to :tournament
WIN_TYPES = ["Decision", "Major", "Tech Fall", "Pin", "Forfeit", "Injury Default", "Default"] WIN_TYPES = ["Decision", "Major", "Tech Fall", "Pin", "Forfeit", "Injury Default", "Default"]
attr_accessor :weight_max
def weight_max
@guy = Wrestler.find(self.r_id)
@weight = Weight.find(@guy.weight_id)
return @weight.max
end
end end

View File

@@ -46,7 +46,8 @@ class Pool
end end
def roundRobin(pool,tournament,weight_id) def roundRobin(pool,tournament,weight_id)
@wrestlers = Wrestler.where(weight_id: weight_id, poolNumber: pool).to_a @wrestlers = Wrestler.where(weight_id: weight_id, poolNumber: pool)
@wrestlers.sort_by{|x|[x.original_seed]}.to_a
@wrestlers.each_with_index do |w,index| @wrestlers.each_with_index do |w,index|
next_guy_index = index+1 next_guy_index = index+1
while index < @wrestlers.length && next_guy_index < @wrestlers.length while index < @wrestlers.length && next_guy_index < @wrestlers.length

View File

@@ -3,14 +3,22 @@ class Tournament < ActiveRecord::Base
has_many :weights, dependent: :destroy has_many :weights, dependent: :destroy
has_many :matches, dependent: :destroy has_many :matches, dependent: :destroy
has_many :mats, dependent: :destroy has_many :mats, dependent: :destroy
attr_accessor :upcomingMatches
def upcomingMatches
@matches = Match.where(tournament_id: self.id)
@matches.sort_by{|x|[x.boutNumber]}
# @matches.sort_by{|x|[x.round,x.weight.max]}
end
def generateMatches def generateMatches
destroyAllMatches destroyAllMatches
self.weights.each do |weight| self.weights.each do |weight|
puts weight.inspect
weight.generatePool weight.generatePool
end end
assignRound assignRound
assignBouts
end end
def destroyAllMatches def destroyAllMatches
@@ -22,31 +30,33 @@ class Tournament < ActiveRecord::Base
def assignRound def assignRound
@matches = Match.where(tournament_id: self.id) @matches = Match.where(tournament_id: self.id)
@matches.sort_by{|x|[x.id]}
@matches.each do |match| @matches.each do |match|
@round = 1 @round = 1
@w1 = Wrestler.find(match.r_id) @w1 = Wrestler.find(match.r_id)
@w2 = Wrestler.find(match.g_id) @w2 = Wrestler.find(match.g_id)
checkRound(@w1,@w2,@round) until wrestlingThisRound(@w1,@w2,@round) == false do
while checkRound(@w1,@w2,@round) == false @round += 1
@round = @round + 1
end end
match.round = @round match.round = @round
match.save match.save
end end
end end
def checkRound(w1,w2,round) def assignBouts
@bouts = Bout.new
@bouts.assignBouts(self.id)
end
def wrestlingThisRound(w1,w2,round)
if w1.isWrestlingThisRound(round) == true or if w1.isWrestlingThisRound(round) == true or
w2.isWrestlingThisRound(round) == true w2.isWrestlingThisRound(round) == true
puts "They wrestle this round"
return false
else
puts "They do not wrestle this round"
return true return true
else
return false
end end
end end
end end
#@weights.sort_by{|x|[x.max]}

View File

@@ -20,9 +20,9 @@ class Weight < ActiveRecord::Base
def pools def pools
@wrestlers = Wrestler.where(weight_id: self.id) @wrestlers = Wrestler.where(weight_id: self.id)
if @wrestlers.size <= 5 if @wrestlers.size <= 6
self.pools = 1 self.pools = 1
elsif (@wrestlers.size > 5) && (@wrestlers.size <= 8) elsif (@wrestlers.size > 6) && (@wrestlers.size <= 8)
self.pools = 2 self.pools = 2
elsif (@wrestlers.size > 8) && (@wrestlers.size <= 16) elsif (@wrestlers.size > 8) && (@wrestlers.size <= 16)
self.pools = 4 self.pools = 4

View File

@@ -3,14 +3,15 @@ class Wrestler < ActiveRecord::Base
belongs_to :weight belongs_to :weight
attr_accessor :matches_all, :isWrestlingThisRound attr_accessor :matches_all, :isWrestlingThisRound
def isWrestlingThisRound(round) def isWrestlingThisRound(matchRound)
@gMatches = Match.where(g_id: self.id, round: round) @gMatches = Match.where(g_id: self.id, round: matchRound)
@rMatches = Match.where(r_id: self.id, round: round) @rMatches = Match.where(r_id: self.id, round: matchRound)
@allMatches = @gMatches + @rMatches @allMatches = @gMatches + @rMatches
if @allMatches == nil if @gMatches.blank? and @rMatches.blank?
return true
else
return false return false
else
puts "He does wrestle this round"
return true
end end
end end

View File

@@ -3,6 +3,6 @@
<br> <br>
<h3>Upcoming Matches</h3> <h3>Upcoming Matches</h3>
<% @matches.each do |m| %> <% @matches.each do |m| %>
<%= Wrestler.find(m.r_id).weight.max %> Lbs <%= Wrestler.find(m.r_id).name %> vs. <%= Wrestler.find(m.g_id).weight.max %> Lbs <%= Wrestler.find(m.g_id).name %> Round <%= m.round %> Bout <%= m.boutNumber %> <%= Wrestler.find(m.r_id).weight.max %> Lbs <%= Wrestler.find(m.r_id).name %> vs. <%= Wrestler.find(m.g_id).weight.max %> Lbs <%= Wrestler.find(m.g_id).name %>
<br> <br>
<% end %> <% end %>