1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-04-04 05:43:47 +00:00

Made onePool and twoPool views. Also implemented round robin gem.

This commit is contained in:
2015-02-05 09:53:08 -05:00
parent 7183935b60
commit e9cf73f9d5
6 changed files with 132 additions and 52 deletions

View File

@@ -45,27 +45,51 @@ class Pool
roundRobin(4,tournament,weight_id)
end
def roundRobin(pool,tournament,weight_id)
@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
other_guy = @wrestlers[next_guy_index]
createMatch(w.id,other_guy.id,tournament)
index += 1
next_guy_index += 1
def roundRobin(pool,tournament_id,weight_id)
@wrestlers = Wrestler.where(weight_id: weight_id, poolNumber: pool).to_a
@poolMatches = RoundRobinTournament.schedule(@wrestlers)
@poolMatches.each_with_index do |b,index|
@bout = b.map
@bout.each do |b|
if b[0] != nil and b[1] != nil
# puts "Start Map Here"
# puts b[0].name
# puts " vs "
# puts b[1].name
# puts "Round "
# puts index + 1
@match = Match.new
@match.r_id = b[0].id
@match.g_id = b[1].id
@match.tournament_id = tournament_id
@match.round = index + 1
@match.save
end
end
end
end
# def roundRobin(pool,tournament,weight_id)
# @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
# other_guy = @wrestlers[next_guy_index]
# createMatch(w.id,other_guy.id,tournament)
# index += 1
# next_guy_index += 1
# end
# end
# end
def createMatch(w1,w2,tournament)
@match = Match.new
@match.r_id = w1
@match.g_id = w2
@match.tournament_id = tournament
@match.save
end
# def createMatch(w1,w2,tournament)
# @match = Match.new
# @match.r_id = w1
# @match.g_id = w2
# @match.tournament_id = tournament
# @match.save
# end
end

View File

@@ -3,7 +3,11 @@ class Tournament < ActiveRecord::Base
has_many :weights, dependent: :destroy
has_many :matches, dependent: :destroy
has_many :mats, dependent: :destroy
attr_accessor :upcomingMatches
attr_accessor :upcomingMatches, :unfinishedMatches
def self.unfinishedMatches
end
def upcomingMatches
@matches = Match.where(tournament_id: self.id)
@@ -17,7 +21,7 @@ class Tournament < ActiveRecord::Base
self.weights.each do |weight|
weight.generatePool
end
assignRound
# assignRound
assignBouts
end
@@ -28,34 +32,13 @@ class Tournament < ActiveRecord::Base
end
end
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)
until wrestlingThisRound(@w1,@w2,@round) == false do
@round += 1
end
match.round = @round
match.save
end
end
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
return true
else
return false
end
end
end

View File

@@ -0,0 +1,25 @@
<h5>Pool 1</h5>
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Name</th>
<th>R1</th>
<th>R2</th>
<th>R3</th>
<th>R4</th>
<th>R5</th>
</tr>
</thead>
<tbody>
<% @poolOneWrestlers.each do |w| %>
<tr>
<td><%= w.name %> <%= w.season_win %>-<%= w.season_loss %> <%= w.school.name %></td>
<td><%= w.boutByRound(1) %><br>Result</td>
<td><%= w.boutByRound(2) %></td>
<td><%= w.boutByRound(3) %></td>
<td><%= w.boutByRound(4) %></td>
<td><%= w.boutByRound(5) %></td>
</tr>
<% end %>
</tbody>
</table>

View File

@@ -0,0 +1,43 @@
<h5>Pool 1</h5>
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Name</th>
<th>R1</th>
<th>R2</th>
<th>R3</th>
</tr>
</thead>
<tbody>
<% @poolOneWrestlers.each do |w| %>
<tr>
<td><%= w.name %> <%= w.season_win %>-<%= w.season_loss %> <%= w.school.name %></td>
<td><%= w.boutByRound(1) %><br>Result</td>
<td><%= w.boutByRound(2) %></td>
<td><%= w.boutByRound(3) %></td>
</tr>
<% end %>
</tbody>
</table>
<h5>Pool 2</h5>
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Name</th>
<th>R1</th>
<th>R2</th>
<th>R3</th>
</tr>
</thead>
<tbody>
<% @poolTwoWrestlers.each do |w| %>
<tr>
<td><%= w.name %> <%= w.season_win %>-<%= w.season_loss %> <%= w.school.name %></td>
<td><%= w.boutByRound(1) %><br>Result</td>
<td><%= w.boutByRound(2) %></td>
<td><%= w.boutByRound(3) %></td>
</tr>
<% end %>
</tbody>
</table>