mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-04-12 08:18:44 +00:00
Made onePool and twoPool views. Also implemented round robin gem.
This commit is contained in:
2
Gemfile
2
Gemfile
@@ -50,6 +50,8 @@ gem 'spring', group: :development
|
|||||||
gem 'bootstrap-sass', '2.3.2.0'
|
gem 'bootstrap-sass', '2.3.2.0'
|
||||||
gem 'devise'
|
gem 'devise'
|
||||||
gem 'cancan'
|
gem 'cancan'
|
||||||
|
gem 'round_robin_tournament'
|
||||||
|
gem 'rb-readline'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
25
Gemfile.lock
25
Gemfile.lock
@@ -28,7 +28,7 @@ GEM
|
|||||||
thread_safe (~> 0.1)
|
thread_safe (~> 0.1)
|
||||||
tzinfo (~> 1.1)
|
tzinfo (~> 1.1)
|
||||||
arel (5.0.1.20140414130214)
|
arel (5.0.1.20140414130214)
|
||||||
bcrypt (3.1.9)
|
bcrypt (3.1.10)
|
||||||
bootstrap-sass (2.3.2.0)
|
bootstrap-sass (2.3.2.0)
|
||||||
sass (~> 3.2)
|
sass (~> 3.2)
|
||||||
builder (3.2.2)
|
builder (3.2.2)
|
||||||
@@ -39,7 +39,7 @@ GEM
|
|||||||
coffee-script (2.3.0)
|
coffee-script (2.3.0)
|
||||||
coffee-script-source
|
coffee-script-source
|
||||||
execjs
|
execjs
|
||||||
coffee-script-source (1.8.0)
|
coffee-script-source (1.9.0)
|
||||||
devise (3.4.1)
|
devise (3.4.1)
|
||||||
bcrypt (~> 3.0)
|
bcrypt (~> 3.0)
|
||||||
orm_adapter (~> 0.1)
|
orm_adapter (~> 0.1)
|
||||||
@@ -48,7 +48,7 @@ GEM
|
|||||||
thread_safe (~> 0.1)
|
thread_safe (~> 0.1)
|
||||||
warden (~> 1.2.3)
|
warden (~> 1.2.3)
|
||||||
erubis (2.7.0)
|
erubis (2.7.0)
|
||||||
execjs (2.2.2)
|
execjs (2.3.0)
|
||||||
hike (1.2.3)
|
hike (1.2.3)
|
||||||
i18n (0.7.0)
|
i18n (0.7.0)
|
||||||
jbuilder (2.2.6)
|
jbuilder (2.2.6)
|
||||||
@@ -57,19 +57,19 @@ GEM
|
|||||||
jquery-rails (3.1.2)
|
jquery-rails (3.1.2)
|
||||||
railties (>= 3.0, < 5.0)
|
railties (>= 3.0, < 5.0)
|
||||||
thor (>= 0.14, < 2.0)
|
thor (>= 0.14, < 2.0)
|
||||||
json (1.8.1)
|
json (1.8.2)
|
||||||
mail (2.5.4)
|
mail (2.5.4)
|
||||||
mime-types (~> 1.16)
|
mime-types (~> 1.16)
|
||||||
treetop (~> 1.4.8)
|
treetop (~> 1.4.8)
|
||||||
mime-types (1.25.1)
|
mime-types (1.25.1)
|
||||||
minitest (5.5.0)
|
minitest (5.5.1)
|
||||||
multi_json (1.10.1)
|
multi_json (1.10.1)
|
||||||
mysql2 (0.3.17)
|
mysql2 (0.3.17)
|
||||||
orm_adapter (0.5.0)
|
orm_adapter (0.5.0)
|
||||||
pg (0.17.1)
|
pg (0.18.1)
|
||||||
polyglot (0.3.5)
|
polyglot (0.3.5)
|
||||||
rack (1.5.2)
|
rack (1.5.2)
|
||||||
rack-test (0.6.2)
|
rack-test (0.6.3)
|
||||||
rack (>= 1.0)
|
rack (>= 1.0)
|
||||||
rails (4.1.4)
|
rails (4.1.4)
|
||||||
actionmailer (= 4.1.4)
|
actionmailer (= 4.1.4)
|
||||||
@@ -84,7 +84,7 @@ GEM
|
|||||||
rails_12factor (0.0.3)
|
rails_12factor (0.0.3)
|
||||||
rails_serve_static_assets
|
rails_serve_static_assets
|
||||||
rails_stdout_logging
|
rails_stdout_logging
|
||||||
rails_serve_static_assets (0.0.2)
|
rails_serve_static_assets (0.0.4)
|
||||||
rails_stdout_logging (0.0.3)
|
rails_stdout_logging (0.0.3)
|
||||||
railties (4.1.4)
|
railties (4.1.4)
|
||||||
actionpack (= 4.1.4)
|
actionpack (= 4.1.4)
|
||||||
@@ -92,10 +92,11 @@ GEM
|
|||||||
rake (>= 0.8.7)
|
rake (>= 0.8.7)
|
||||||
thor (>= 0.18.1, < 2.0)
|
thor (>= 0.18.1, < 2.0)
|
||||||
rake (10.4.2)
|
rake (10.4.2)
|
||||||
|
rb-readline (0.5.2)
|
||||||
rdoc (4.2.0)
|
rdoc (4.2.0)
|
||||||
json (~> 1.4)
|
|
||||||
responders (1.1.2)
|
responders (1.1.2)
|
||||||
railties (>= 3.2, < 4.2)
|
railties (>= 3.2, < 4.2)
|
||||||
|
round_robin_tournament (0.0.1)
|
||||||
sass (3.2.19)
|
sass (3.2.19)
|
||||||
sass-rails (4.0.5)
|
sass-rails (4.0.5)
|
||||||
railties (>= 4.0.0, < 5.0)
|
railties (>= 4.0.0, < 5.0)
|
||||||
@@ -111,7 +112,7 @@ GEM
|
|||||||
multi_json (~> 1.0)
|
multi_json (~> 1.0)
|
||||||
rack (~> 1.0)
|
rack (~> 1.0)
|
||||||
tilt (~> 1.1, != 1.3.0)
|
tilt (~> 1.1, != 1.3.0)
|
||||||
sprockets-rails (2.2.2)
|
sprockets-rails (2.2.4)
|
||||||
actionpack (>= 3.0)
|
actionpack (>= 3.0)
|
||||||
activesupport (>= 3.0)
|
activesupport (>= 3.0)
|
||||||
sprockets (>= 2.8, < 4.0)
|
sprockets (>= 2.8, < 4.0)
|
||||||
@@ -126,7 +127,7 @@ GEM
|
|||||||
coffee-rails
|
coffee-rails
|
||||||
tzinfo (1.2.2)
|
tzinfo (1.2.2)
|
||||||
thread_safe (~> 0.1)
|
thread_safe (~> 0.1)
|
||||||
uglifier (2.6.0)
|
uglifier (2.7.0)
|
||||||
execjs (>= 0.3.0)
|
execjs (>= 0.3.0)
|
||||||
json (>= 1.8.0)
|
json (>= 1.8.0)
|
||||||
warden (1.2.3)
|
warden (1.2.3)
|
||||||
@@ -146,6 +147,8 @@ DEPENDENCIES
|
|||||||
pg
|
pg
|
||||||
rails (= 4.1.4)
|
rails (= 4.1.4)
|
||||||
rails_12factor
|
rails_12factor
|
||||||
|
rb-readline
|
||||||
|
round_robin_tournament
|
||||||
sass-rails (~> 4.0.3)
|
sass-rails (~> 4.0.3)
|
||||||
sdoc (~> 0.4.0)
|
sdoc (~> 0.4.0)
|
||||||
spring
|
spring
|
||||||
|
|||||||
@@ -45,27 +45,51 @@ class Pool
|
|||||||
roundRobin(4,tournament,weight_id)
|
roundRobin(4,tournament,weight_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def roundRobin(pool,tournament,weight_id)
|
def roundRobin(pool,tournament_id,weight_id)
|
||||||
@wrestlers = Wrestler.where(weight_id: weight_id, poolNumber: pool)
|
@wrestlers = Wrestler.where(weight_id: weight_id, poolNumber: pool).to_a
|
||||||
@wrestlers.sort_by{|x|[x.original_seed]}.to_a
|
@poolMatches = RoundRobinTournament.schedule(@wrestlers)
|
||||||
@wrestlers.each_with_index do |w,index|
|
@poolMatches.each_with_index do |b,index|
|
||||||
next_guy_index = index+1
|
@bout = b.map
|
||||||
while index < @wrestlers.length && next_guy_index < @wrestlers.length
|
@bout.each do |b|
|
||||||
other_guy = @wrestlers[next_guy_index]
|
if b[0] != nil and b[1] != nil
|
||||||
createMatch(w.id,other_guy.id,tournament)
|
# puts "Start Map Here"
|
||||||
index += 1
|
# puts b[0].name
|
||||||
next_guy_index += 1
|
# 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
|
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
|
# def createMatch(w1,w2,tournament)
|
||||||
@match.r_id = w1
|
# @match = Match.new
|
||||||
@match.g_id = w2
|
# @match.r_id = w1
|
||||||
@match.tournament_id = tournament
|
# @match.g_id = w2
|
||||||
@match.save
|
# @match.tournament_id = tournament
|
||||||
end
|
# @match.save
|
||||||
|
# end
|
||||||
|
|
||||||
end
|
end
|
||||||
@@ -3,7 +3,11 @@ 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
|
attr_accessor :upcomingMatches, :unfinishedMatches
|
||||||
|
|
||||||
|
def self.unfinishedMatches
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
def upcomingMatches
|
def upcomingMatches
|
||||||
@matches = Match.where(tournament_id: self.id)
|
@matches = Match.where(tournament_id: self.id)
|
||||||
@@ -17,7 +21,7 @@ class Tournament < ActiveRecord::Base
|
|||||||
self.weights.each do |weight|
|
self.weights.each do |weight|
|
||||||
weight.generatePool
|
weight.generatePool
|
||||||
end
|
end
|
||||||
assignRound
|
# assignRound
|
||||||
assignBouts
|
assignBouts
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -28,34 +32,13 @@ class Tournament < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
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
|
def assignBouts
|
||||||
@bouts = Bout.new
|
@bouts = Bout.new
|
||||||
@bouts.assignBouts(self.id)
|
@bouts.assignBouts(self.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def wrestlingThisRound(w1,w2,round)
|
|
||||||
if w1.isWrestlingThisRound(round) == true or
|
|
||||||
w2.isWrestlingThisRound(round) == true
|
|
||||||
return true
|
|
||||||
else
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
25
app/views/static_pages/_onePool.html.erb
Normal file
25
app/views/static_pages/_onePool.html.erb
Normal 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>
|
||||||
43
app/views/static_pages/_twoPool.html.erb
Normal file
43
app/views/static_pages/_twoPool.html.erb
Normal 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>
|
||||||
Reference in New Issue
Block a user