1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-03-25 01:14:43 +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])
end
if @tournament
@matches = Match.where(tournament_id: @tournament.id)
@matches = @tournament.upcomingMatches
end
end
def results

View File

@@ -1,3 +1,24 @@
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

View File

@@ -1,6 +1,11 @@
class Match < ActiveRecord::Base
belongs_to :tournament
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

View File

@@ -46,7 +46,8 @@ class Pool
end
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|
next_guy_index = index+1
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 :matches, 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
destroyAllMatches
self.weights.each do |weight|
puts weight.inspect
weight.generatePool
end
assignRound
assignBouts
end
def destroyAllMatches
@@ -22,31 +30,33 @@ class Tournament < ActiveRecord::Base
def assignRound
@matches = Match.where(tournament_id: self.id)
@matches.sort_by{|x|[x.id]}
@matches.each do |match|
@round = 1
@w1 = Wrestler.find(match.r_id)
@w2 = Wrestler.find(match.g_id)
checkRound(@w1,@w2,@round)
while checkRound(@w1,@w2,@round) == false
@round = @round + 1
until wrestlingThisRound(@w1,@w2,@round) == false do
@round += 1
end
match.round = @round
match.save
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
w2.isWrestlingThisRound(round) == true
puts "They wrestle this round"
return false
else
puts "They do not wrestle this round"
return true
else
return false
end
end
end
#@weights.sort_by{|x|[x.max]}

View File

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

View File

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

View File

@@ -3,6 +3,6 @@
<br>
<h3>Upcoming Matches</h3>
<% @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>
<% end %>