summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/matches_controller.rb8
-rw-r--r--app/controllers/teams_controller.rb2
-rw-r--r--app/controllers/tournaments_controller.rb9
-rw-r--r--app/models/team.rb1
-rw-r--r--app/models/tournament.rb39
-rw-r--r--app/models/tournament_stage.rb26
-rw-r--r--app/views/matches/_form.html.erb6
-rw-r--r--app/views/matches/index.html.erb82
-rw-r--r--app/views/matches/index.json.jbuilder2
-rw-r--r--app/views/matches/show.json.jbuilder2
-rw-r--r--app/views/teams/_form.html.erb4
-rw-r--r--app/views/teams/index.html.erb2
-rw-r--r--app/views/teams/index.json.jbuilder2
-rw-r--r--app/views/teams/show.html.erb5
-rw-r--r--app/views/teams/show.json.jbuilder2
-rw-r--r--config/routes.rb12
-rw-r--r--db/migrate/20140422155038_create_simple_captcha_data.rb (renamed from db/migrate/20140422021622_create_simple_captcha_data.rb)0
-rw-r--r--db/migrate/20140422195042_create_delayed_jobs.rb (renamed from db/migrate/20140422061625_create_delayed_jobs.rb)0
-rw-r--r--db/migrate/20140422195045_create_servers.rb (renamed from db/migrate/20140422061628_create_servers.rb)0
-rw-r--r--db/migrate/20140422195049_create_matches.rb (renamed from db/migrate/20140422061631_create_matches.rb)3
-rw-r--r--db/migrate/20140422195052_create_teams.rb (renamed from db/migrate/20140422061633_create_teams.rb)1
-rw-r--r--db/migrate/20140422195056_create_alerts.rb (renamed from db/migrate/20140422061636_create_alerts.rb)0
-rw-r--r--db/migrate/20140422195059_create_pms.rb (renamed from db/migrate/20140422061639_create_pms.rb)0
-rw-r--r--db/migrate/20140422195103_create_tournaments.rb (renamed from db/migrate/20140422061642_create_tournaments.rb)0
-rw-r--r--db/migrate/20140422195107_create_games.rb (renamed from db/migrate/20140422061645_create_games.rb)0
-rw-r--r--db/migrate/20140422195110_create_users.rb (renamed from db/migrate/20140422061648_create_users.rb)0
-rw-r--r--db/migrate/20140422195114_create_sessions.rb (renamed from db/migrate/20140422061651_create_sessions.rb)0
-rw-r--r--db/migrate/20140422195118_create_brackets.rb (renamed from db/migrate/20140422061654_create_brackets.rb)0
-rw-r--r--db/migrate/20140422195121_create_game_settings.rb (renamed from db/migrate/20140422061657_create_game_settings.rb)0
-rw-r--r--db/migrate/20140422195125_create_tournament_settings.rb (renamed from db/migrate/20140422061700_create_tournament_settings.rb)0
-rw-r--r--db/migrate/20140422195128_create_tournament_stages.rb (renamed from db/migrate/20140422061703_create_tournament_stages.rb)0
-rw-r--r--db/migrate/20140422195132_create_statistics.rb (renamed from db/migrate/20140422061706_create_statistics.rb)0
-rw-r--r--db/migrate/20140422195135_create_remote_usernames.rb (renamed from db/migrate/20140422061709_create_remote_usernames.rb)0
-rw-r--r--db/migrate/20140422195139_create_bracket_matches.rb (renamed from db/migrate/20140422061712_create_bracket_matches.rb)0
-rw-r--r--db/migrate/20140422195143_create_api_requests.rb (renamed from db/migrate/20140422061715_create_api_requests.rb)0
-rw-r--r--db/migrate/20140422195146_create_tournament_players_join_table.rb (renamed from db/migrate/20140422061718_create_tournament_players_join_table.rb)0
-rw-r--r--db/migrate/20140422195150_create_tournament_hosts_join_table.rb (renamed from db/migrate/20140422061721_create_tournament_hosts_join_table.rb)0
-rw-r--r--db/migrate/20140422195153_create_team_user_join_table.rb (renamed from db/migrate/20140422061724_create_team_user_join_table.rb)0
-rw-r--r--db/migrate/20140422195157_create_match_team_join_table.rb (renamed from db/migrate/20140422061727_create_match_team_join_table.rb)0
-rw-r--r--db/migrate/20140422195211_add_hidden_attrs_to_user.rb (renamed from db/migrate/20140422061739_add_hidden_attrs_to_user.rb)0
-rw-r--r--db/schema.rb8
-rwxr-xr-xgenerate.sh7
-rw-r--r--lib/scheduling/elimination.rb55
-rw-r--r--lib/scheduling/elimination.svg.erb72
-rw-r--r--test/controllers/matches_controller_test.rb4
-rw-r--r--test/controllers/teams_controller_test.rb4
-rw-r--r--test/fixtures/matches.yml6
-rw-r--r--test/fixtures/teams.yml14
48 files changed, 206 insertions, 172 deletions
diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb
index d7a8b99..59f376a 100644
--- a/app/controllers/matches_controller.rb
+++ b/app/controllers/matches_controller.rb
@@ -8,12 +8,6 @@ class MatchesController < ApplicationController
# GET /tournaments/1/matches
# GET /tournaments/1/matches.json
def index
- @matches = @tournament.matches
- # depth of SVG tree
- @depth = Math.log2(@matches.count).floor+1;
- # height of SVG
- @height = 200 * 2**Math.log2(@matches.count).floor + 100;
- @h_sector = 2**(@depth-1)+1
end
# For compatability with the router assumptions made by ApplicationController#check_permission
@@ -250,7 +244,7 @@ class MatchesController < ApplicationController
# Never trust parameters from the scary internet, only allow the white list through.
def match_params
- params.require(:match).permit(:status, :tournament_stage_id, :name, :winner_id, :remote_id, :submitted_peer_evaluations)
+ params.require(:match).permit(:status, :tournament_stage_id, :winner_id, :remote_id, :submitted_peer_evaluations)
end
# Turn of check_edit, since our #update is flexible
diff --git a/app/controllers/teams_controller.rb b/app/controllers/teams_controller.rb
index 57ae256..6abc74c 100644
--- a/app/controllers/teams_controller.rb
+++ b/app/controllers/teams_controller.rb
@@ -68,7 +68,7 @@ class TeamsController < ApplicationController
# Never trust parameters from the scary internet, only allow the white list through.
def team_params
- params.require(:team).permit(:match_id)
+ params[:team]
end
def is_owner?(object)
diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb
index b6f911f..4b0e1af 100644
--- a/app/controllers/tournaments_controller.rb
+++ b/app/controllers/tournaments_controller.rb
@@ -96,10 +96,13 @@ class TournamentsController < ApplicationController
when "start"
check_permission(:edit, @tournament)
@tournament.status = 1
- @tournament.save
+ ok =
+ @tournament.save &&
+ @tournament.tournament_stages.create(scheduling: "elimination") &&
+ @tournament.tournament_stages.first.create_matches
respond_to do |format|
- if @tournament.setup
- format.html { redirect_to @tournament, notice: 'You have joined this tournament.' }
+ if ok
+ format.html { redirect_to @tournament, notice: 'You have started this tournament.' }
format.json { head :no_content }
else
format.html { redirect_to @tournament, notice: "You don't have permission to start this tournament." }
diff --git a/app/models/team.rb b/app/models/team.rb
index 7aae7c2..77136e7 100644
--- a/app/models/team.rb
+++ b/app/models/team.rb
@@ -1,5 +1,4 @@
class Team < ActiveRecord::Base
- belongs_to :match
has_and_belongs_to_many :matches
has_and_belongs_to_many :users
end
diff --git a/app/models/tournament.rb b/app/models/tournament.rb
index 73c8d93..e21ccb1 100644
--- a/app/models/tournament.rb
+++ b/app/models/tournament.rb
@@ -1,15 +1,15 @@
class Tournament < ActiveRecord::Base
belongs_to :game
- has_many :matches
+ has_many :tournament_stages
has_many :settings_raw, class_name: "TournamentSetting"
has_and_belongs_to_many :players, class_name: "User", association_foreign_key: "player_id", join_table: "players_tournaments"
has_and_belongs_to_many :hosts, class_name: "User", association_foreign_key: "host_id", join_table: "hosts_tournaments"
- def matches_ordered
+ def stages_ordered
h = {}
i = 1
- matches.order(:id).each do |m|
- h[i] = m
+ self.tournament_stages.order(:id).each do |s|
+ h[i] = s
i += 1
end
return h
@@ -26,14 +26,6 @@ class Tournament < ActiveRecord::Base
end
class Settings
- @vartypes = {
- :true_false => 0,
- :integer => 1,
- :string => 2,
- :select => 3,
- :range => 4
- }
-
def initialize(tournament)
@tournament = tournament
end
@@ -94,27 +86,4 @@ class Tournament < ActiveRecord::Base
players.delete(user)
end
end
-
- def setup
- num_teams = (self.players.count/self.min_players_per_team).floor
- num_matches = num_teams - 1
- for i in 1..num_matches
- self.matches.create(name: "Match #{i}", status: 0, submitted_peer_evaluations: 0)
- end
- match_num = num_matches-1
- team_num = 0
- #for each grouping of min_players_per_team
- players.each_slice(min_players_per_team) do |players|
-
- #if the match is full, move to the next match, otherwise move to the next team
- if (team_num == min_teams_per_match)
- match_num -= 1
- team_num = 0
- else
- team_num += 1
- end
- #create a new team in the current match
- self.matches[match_num].teams.push(Team.create(users: players))
- end
- end
end
diff --git a/app/models/tournament_stage.rb b/app/models/tournament_stage.rb
index 205c8cc..a24d7b9 100644
--- a/app/models/tournament_stage.rb
+++ b/app/models/tournament_stage.rb
@@ -1,3 +1,29 @@
class TournamentStage < ActiveRecord::Base
belongs_to :tournament
+ has_many :matches
+
+ def matches_ordered
+ h = {}
+ i = 1
+ self.matches.order(:id).each do |m|
+ h[i] = m
+ i += 1
+ end
+ return h
+ end
+
+ def create_matches
+ set_scheduling
+ @scheduling.create_matches
+ end
+
+ def to_svg
+ set_scheduling
+ return @scheduling.graph(self)
+ end
+
+ private
+ def set_scheduling
+ @scheduling ||= "Scheduling::#{self.scheduling}".constantize.new(self)
+ end
end
diff --git a/app/views/matches/_form.html.erb b/app/views/matches/_form.html.erb
index 88fe733..9d402b3 100644
--- a/app/views/matches/_form.html.erb
+++ b/app/views/matches/_form.html.erb
@@ -9,16 +9,12 @@
<%= f.text_field :tournament_stage_id %>
</div>
<div class="field">
- <%= f.label :name %><br>
- <%= f.text_field :name %>
- </div>
- <div class="field">
<%= f.label :winner_id %><br>
<%= f.text_field :winner_id %>
</div>
<div class="field">
<%= f.label :remote_id %><br>
- <%= f.text_field :remote_id %>
+ <%= f.text_area :remote_id %>
</div>
<div class="field">
<%= f.label :submitted_peer_evaluations %><br>
diff --git a/app/views/matches/index.html.erb b/app/views/matches/index.html.erb
index 03427d8..abca42b 100644
--- a/app/views/matches/index.html.erb
+++ b/app/views/matches/index.html.erb
@@ -13,7 +13,7 @@
<tbody class="table-hover">
<% @tournament.matches.order(:id).reverse.each do |match| %><tr>
- <td><%= match.name %></td>
+ <td><%= "Match #{match.id}" %></td>
<td><%= match.status %></td>
<td><%= (match.winner.nil? ? "-" : "Team #{match.winner.id}") %></td>
<td><%= link_to "Show", tournament_match_path(@tournament, match) %>
@@ -32,80 +32,6 @@
<br>
-<div id="match-tree">
- <SVG version="1.1"
- baseProfile="full"
- width="100%" height="<%= @height = [@height, 500].max %>"
- xmlns="http://www.w3.org/2000/svg"
- xmlns:xlink="http://www.w3.org/1999/xlink">
- <% lastrx = 0
- lastry = 0
- lastrh = 0
- lastrw = 0 %>
- <defs>
- <radialGradient id="gradMatch" cx="50%" cy="50%" r="80%" fx="80%" fy="80%">
- <stop offset="0%" style="stop-color:#ffd281;
- stop-opacity:0" />
- <stop offset="100%" style="stop-color:#ccc;stop-opacity:1" />
- </radialGradient>
- </defs>
- <script type="text/ecmascript"><![CDATA[
- function redirect(i){
- window.location.replace("<%= request.original_url %>"+"/"+i);
- }
- ]]>
- </script>
-
- <% (1..@matches.count).each do |i| %>
- <g id="svg-match-<%= i %>" onclick="redirect(<%= @matches[i-1].id %>)" cursor="pointer">
- <rect height="<%= rh = 100/(2**(@depth-1)+1) - 5 %>%"
- width="<%= rw = 100/(@depth+1) - 5 %>%"
- x="<%= rx = 50/(@depth+1) + 100/(@depth+1)*(@depth-(Math.log2(i).floor+1)) %>%"
- y="<%= ry = ( 100/(2**(Math.log2(i).floor)+1) + rh * 1.1 * (2**Math.log2(i).ceil-i)) %>%"
- fill="url(#gradMatch)"
- rx="5px"
- stroke-width="2"
- <% case @matches[i-1].status %>
- <% when 0 %>
- <% if @matches[i-1].teams.count < @tournament.min_teams_per_match %>
- stroke="red"
- fill-opacity="0.6"
- <% else %>
- stroke="green"
- <% end %>
- <% when 1 %>
- stroke="orange"
- <% when 2 %>
- stroke="yellow"
- <% when 3 %>
- stroke="grey"
- <% end %>
- />
- <rect width="<%= rw-5 %>%" height="<%= rh/4 %>%" x="<%= rx + 2.5 %>%" y="<%= ry + rh/6 %>%" fill="<%= @matches[i-1].teams.first and @matches[i-1].teams.first.users.include?(current_user) ? "#BCED91" : "white" %>" />
- <text x="<%= rx + rw/4 %>%" y="<%= ry + rh/3 %>%" font-size="<%= rh %>">
- <% if @matches[i-1].teams.first %>
- Team <%= @matches[i-1].teams.first.id %>
- <% end %>
- </text>
- <text x="<%= rx + 1.3*rw/3 %>%" y="<%= ry + 5.2*rh/9 %>%" font-size="<%= rh %>"> VS </text>
-
- <rect width="<%= rw-5 %>%" height="<%= rh/4 %>%" x="<%= rx + 2.5 %>%" y="<%= ry + 3*rh/5 %>%" fill="<%= @matches[i-1].teams[1] and @matches[i-1].teams[1].users.include?(current_user) ? "#BCED91" : "white" %>" />
- <text x="<%= rx + rw/4 %>%" y="<%= ry + 4*rh/5 %>%" font-size="<%= rh %>">
- <% if @matches[i-1].teams[1] %>
- Team <%= @matches[i-1].teams[1].id %>
- <% end %>
- </text>
- <% if i > 1 %>
- <line x1="<%= rx+rw %>%" y1="<%= ry+rh/2 %>%" x2="<%= lastrx %>%" y2="<%= lastry+lastrh/2 %>%" stroke="black" stroke-width="2" >
- <% end %>
- <% if Math.log2(i+1) == Math.log2(i+1).ceil %>
- <% lastrx = rx
- lastry = ry
- lastrh = rh
- lastrw = rw %>
- <% end %>
- </g>
-
- <% end %>
-</SVG>
-</div>
+<% @tournament.stages_ordered.each do |stage| %>
+ <div class="graph"><%= stage.to_svg %></div>
+<% end %>
diff --git a/app/views/matches/index.json.jbuilder b/app/views/matches/index.json.jbuilder
index f2499ac..bef149d 100644
--- a/app/views/matches/index.json.jbuilder
+++ b/app/views/matches/index.json.jbuilder
@@ -1,4 +1,4 @@
json.array!(@matches) do |match|
- json.extract! match, :id, :status, :tournament_stage_id, :name, :winner_id, :remote_id, :submitted_peer_evaluations
+ json.extract! match, :id, :status, :tournament_stage_id, :winner_id, :remote_id, :submitted_peer_evaluations
json.url match_url(match, format: :json)
end
diff --git a/app/views/matches/show.json.jbuilder b/app/views/matches/show.json.jbuilder
index 5b543ea..145f069 100644
--- a/app/views/matches/show.json.jbuilder
+++ b/app/views/matches/show.json.jbuilder
@@ -1 +1 @@
-json.extract! @match, :id, :status, :tournament_stage_id, :name, :winner_id, :remote_id, :submitted_peer_evaluations, :created_at, :updated_at
+json.extract! @match, :id, :status, :tournament_stage_id, :winner_id, :remote_id, :submitted_peer_evaluations, :created_at, :updated_at
diff --git a/app/views/teams/_form.html.erb b/app/views/teams/_form.html.erb
index cdd4299..fd10129 100644
--- a/app/views/teams/_form.html.erb
+++ b/app/views/teams/_form.html.erb
@@ -11,10 +11,6 @@
</div>
<% end %>
- <div class="field">
- <%= f.label :match_id %><br>
- <%= f.text_field :match_id %>
- </div>
<div class="actions">
<%= f.submit %>
</div>
diff --git a/app/views/teams/index.html.erb b/app/views/teams/index.html.erb
index 6a3188d..b077e10 100644
--- a/app/views/teams/index.html.erb
+++ b/app/views/teams/index.html.erb
@@ -3,7 +3,6 @@
<table>
<thead>
<tr>
- <th>Match</th>
<th></th>
<th></th>
<th></th>
@@ -13,7 +12,6 @@
<tbody>
<% @teams.each do |team| %>
<tr>
- <td><%= team.match %></td>
<td><%= link_to 'Show', team %></td>
<td><%= link_to 'Edit', edit_team_path(team) %></td>
<td><%= link_to 'Destroy', team, method: :delete, data: { confirm: 'Are you sure?' } %></td>
diff --git a/app/views/teams/index.json.jbuilder b/app/views/teams/index.json.jbuilder
index ca0ec8b..b29428b 100644
--- a/app/views/teams/index.json.jbuilder
+++ b/app/views/teams/index.json.jbuilder
@@ -1,4 +1,4 @@
json.array!(@teams) do |team|
- json.extract! team, :id, :match_id
+ json.extract! team, :id
json.url team_url(team, format: :json)
end
diff --git a/app/views/teams/show.html.erb b/app/views/teams/show.html.erb
index e41692a..5b18d33 100644
--- a/app/views/teams/show.html.erb
+++ b/app/views/teams/show.html.erb
@@ -1,9 +1,4 @@
<p id="notice"><%= notice %></p>
-<p>
- <strong>Match:</strong>
- <%= @team.match %>
-</p>
-
<%= link_to 'Edit', edit_team_path(@team) %> |
<%= link_to 'Back', teams_path %>
diff --git a/app/views/teams/show.json.jbuilder b/app/views/teams/show.json.jbuilder
index 8a85dcc..1538019 100644
--- a/app/views/teams/show.json.jbuilder
+++ b/app/views/teams/show.json.jbuilder
@@ -1 +1 @@
-json.extract! @team, :id, :match_id, :created_at, :updated_at
+json.extract! @team, :id, :created_at, :updated_at
diff --git a/config/routes.rb b/config/routes.rb
index 8c91ee1..f94bd2f 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,3 +1,4 @@
+# -*- Mode: Ruby; Ruby-indent-level: 2; Indent-tabs-mode: nil -*-
Leaguer::Application.routes.draw do
resources :brackets
@@ -17,13 +18,24 @@ Leaguer::Application.routes.draw do
#match 'simple_captcha/:id', :to => 'simple_captcha#show', :as => :simple_captcha
resources :teams
+
resources :tournaments do
resources :matches, only: [:index, :show, :update]
end
root to: 'static#homepage'
get '/testsvg', to: 'static#test'
+end
+Leaguer::Application.routes.named_routes.module.module_eval do
+ def match_path(match, options={})
+ tournament_match_path(match.tournament_stage.tournament, match, options)
+ end
+ def match_url(match, options={})
+ tournament_match_url(match.tournament_stage.tournament, match, options)
+ end
+end
+if false
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
diff --git a/db/migrate/20140422021622_create_simple_captcha_data.rb b/db/migrate/20140422155038_create_simple_captcha_data.rb
index 4573b20..4573b20 100644
--- a/db/migrate/20140422021622_create_simple_captcha_data.rb
+++ b/db/migrate/20140422155038_create_simple_captcha_data.rb
diff --git a/db/migrate/20140422061625_create_delayed_jobs.rb b/db/migrate/20140422195042_create_delayed_jobs.rb
index ec0dd93..ec0dd93 100644
--- a/db/migrate/20140422061625_create_delayed_jobs.rb
+++ b/db/migrate/20140422195042_create_delayed_jobs.rb
diff --git a/db/migrate/20140422061628_create_servers.rb b/db/migrate/20140422195045_create_servers.rb
index fbe1b02..fbe1b02 100644
--- a/db/migrate/20140422061628_create_servers.rb
+++ b/db/migrate/20140422195045_create_servers.rb
diff --git a/db/migrate/20140422061631_create_matches.rb b/db/migrate/20140422195049_create_matches.rb
index 3786d52..bac92d1 100644
--- a/db/migrate/20140422061631_create_matches.rb
+++ b/db/migrate/20140422195049_create_matches.rb
@@ -3,9 +3,8 @@ class CreateMatches < ActiveRecord::Migration
create_table :matches do |t|
t.integer :status
t.references :tournament_stage, index: true
- t.string :name
t.references :winner, index: true
- t.string :remote_id
+ t.text :remote_id
t.integer :submitted_peer_evaluations
t.timestamps
diff --git a/db/migrate/20140422061633_create_teams.rb b/db/migrate/20140422195052_create_teams.rb
index fdf9a68..dd8397d 100644
--- a/db/migrate/20140422061633_create_teams.rb
+++ b/db/migrate/20140422195052_create_teams.rb
@@ -1,7 +1,6 @@
class CreateTeams < ActiveRecord::Migration
def change
create_table :teams do |t|
- t.references :match, index: true
t.timestamps
end
diff --git a/db/migrate/20140422061636_create_alerts.rb b/db/migrate/20140422195056_create_alerts.rb
index 68a8e10..68a8e10 100644
--- a/db/migrate/20140422061636_create_alerts.rb
+++ b/db/migrate/20140422195056_create_alerts.rb
diff --git a/db/migrate/20140422061639_create_pms.rb b/db/migrate/20140422195059_create_pms.rb
index 93bb5c6..93bb5c6 100644
--- a/db/migrate/20140422061639_create_pms.rb
+++ b/db/migrate/20140422195059_create_pms.rb
diff --git a/db/migrate/20140422061642_create_tournaments.rb b/db/migrate/20140422195103_create_tournaments.rb
index 716871f..716871f 100644
--- a/db/migrate/20140422061642_create_tournaments.rb
+++ b/db/migrate/20140422195103_create_tournaments.rb
diff --git a/db/migrate/20140422061645_create_games.rb b/db/migrate/20140422195107_create_games.rb
index 46ed30d..46ed30d 100644
--- a/db/migrate/20140422061645_create_games.rb
+++ b/db/migrate/20140422195107_create_games.rb
diff --git a/db/migrate/20140422061648_create_users.rb b/db/migrate/20140422195110_create_users.rb
index 8032870..8032870 100644
--- a/db/migrate/20140422061648_create_users.rb
+++ b/db/migrate/20140422195110_create_users.rb
diff --git a/db/migrate/20140422061651_create_sessions.rb b/db/migrate/20140422195114_create_sessions.rb
index f667f1e..f667f1e 100644
--- a/db/migrate/20140422061651_create_sessions.rb
+++ b/db/migrate/20140422195114_create_sessions.rb
diff --git a/db/migrate/20140422061654_create_brackets.rb b/db/migrate/20140422195118_create_brackets.rb
index 8813bf2..8813bf2 100644
--- a/db/migrate/20140422061654_create_brackets.rb
+++ b/db/migrate/20140422195118_create_brackets.rb
diff --git a/db/migrate/20140422061657_create_game_settings.rb b/db/migrate/20140422195121_create_game_settings.rb
index 06fb72e..06fb72e 100644
--- a/db/migrate/20140422061657_create_game_settings.rb
+++ b/db/migrate/20140422195121_create_game_settings.rb
diff --git a/db/migrate/20140422061700_create_tournament_settings.rb b/db/migrate/20140422195125_create_tournament_settings.rb
index e56697f..e56697f 100644
--- a/db/migrate/20140422061700_create_tournament_settings.rb
+++ b/db/migrate/20140422195125_create_tournament_settings.rb
diff --git a/db/migrate/20140422061703_create_tournament_stages.rb b/db/migrate/20140422195128_create_tournament_stages.rb
index e3668cb..e3668cb 100644
--- a/db/migrate/20140422061703_create_tournament_stages.rb
+++ b/db/migrate/20140422195128_create_tournament_stages.rb
diff --git a/db/migrate/20140422061706_create_statistics.rb b/db/migrate/20140422195132_create_statistics.rb
index cc2e97d..cc2e97d 100644
--- a/db/migrate/20140422061706_create_statistics.rb
+++ b/db/migrate/20140422195132_create_statistics.rb
diff --git a/db/migrate/20140422061709_create_remote_usernames.rb b/db/migrate/20140422195135_create_remote_usernames.rb
index e265985..e265985 100644
--- a/db/migrate/20140422061709_create_remote_usernames.rb
+++ b/db/migrate/20140422195135_create_remote_usernames.rb
diff --git a/db/migrate/20140422061712_create_bracket_matches.rb b/db/migrate/20140422195139_create_bracket_matches.rb
index 3323e31..3323e31 100644
--- a/db/migrate/20140422061712_create_bracket_matches.rb
+++ b/db/migrate/20140422195139_create_bracket_matches.rb
diff --git a/db/migrate/20140422061715_create_api_requests.rb b/db/migrate/20140422195143_create_api_requests.rb
index 544c330..544c330 100644
--- a/db/migrate/20140422061715_create_api_requests.rb
+++ b/db/migrate/20140422195143_create_api_requests.rb
diff --git a/db/migrate/20140422061718_create_tournament_players_join_table.rb b/db/migrate/20140422195146_create_tournament_players_join_table.rb
index be240e8..be240e8 100644
--- a/db/migrate/20140422061718_create_tournament_players_join_table.rb
+++ b/db/migrate/20140422195146_create_tournament_players_join_table.rb
diff --git a/db/migrate/20140422061721_create_tournament_hosts_join_table.rb b/db/migrate/20140422195150_create_tournament_hosts_join_table.rb
index 7521d89..7521d89 100644
--- a/db/migrate/20140422061721_create_tournament_hosts_join_table.rb
+++ b/db/migrate/20140422195150_create_tournament_hosts_join_table.rb
diff --git a/db/migrate/20140422061724_create_team_user_join_table.rb b/db/migrate/20140422195153_create_team_user_join_table.rb
index f3b57fc..f3b57fc 100644
--- a/db/migrate/20140422061724_create_team_user_join_table.rb
+++ b/db/migrate/20140422195153_create_team_user_join_table.rb
diff --git a/db/migrate/20140422061727_create_match_team_join_table.rb b/db/migrate/20140422195157_create_match_team_join_table.rb
index c2ed1b7..c2ed1b7 100644
--- a/db/migrate/20140422061727_create_match_team_join_table.rb
+++ b/db/migrate/20140422195157_create_match_team_join_table.rb
diff --git a/db/migrate/20140422061739_add_hidden_attrs_to_user.rb b/db/migrate/20140422195211_add_hidden_attrs_to_user.rb
index 9b5c505..9b5c505 100644
--- a/db/migrate/20140422061739_add_hidden_attrs_to_user.rb
+++ b/db/migrate/20140422195211_add_hidden_attrs_to_user.rb
diff --git a/db/schema.rb b/db/schema.rb
index e8764b6..3f39538 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20140422061739) do
+ActiveRecord::Schema.define(version: 20140422195211) do
create_table "alerts", force: true do |t|
t.integer "author_id"
@@ -104,9 +104,8 @@ ActiveRecord::Schema.define(version: 20140422061739) do
create_table "matches", force: true do |t|
t.integer "status"
t.integer "tournament_stage_id"
- t.string "name"
t.integer "winner_id"
- t.string "remote_id"
+ t.text "remote_id"
t.integer "submitted_peer_evaluations"
t.datetime "created_at"
t.datetime "updated_at"
@@ -185,13 +184,10 @@ ActiveRecord::Schema.define(version: 20140422061739) do
add_index "statistics", ["user_id"], name: "index_statistics_on_user_id"
create_table "teams", force: true do |t|
- t.integer "match_id"
t.datetime "created_at"
t.datetime "updated_at"
end
- add_index "teams", ["match_id"], name: "index_teams_on_match_id"
-
create_table "teams_users", id: false, force: true do |t|
t.integer "team_id", null: false
t.integer "user_id", null: false
diff --git a/generate.sh b/generate.sh
index b8651c2..e965fde 100755
--- a/generate.sh
+++ b/generate.sh
@@ -21,8 +21,8 @@ bundle exec rails generate delayed_job:active_record
# The whole shebang, models, views, and controllers
bundle exec rails generate scaffold server default_user_permissions:integer
-bundle exec rails generate scaffold match status:integer tournament_stage:references name:string winner:references remote_id:string submitted_peer_evaluations:integer
-bundle exec rails generate scaffold team match:references
+bundle exec rails generate scaffold match status:integer tournament_stage:references winner:references remote_id:text submitted_peer_evaluations:integer
+bundle exec rails generate scaffold team
bundle exec rails generate scaffold alert author:references message:text
bundle exec rails generate scaffold pm author:references recipient:references message:text
bundle exec rails generate scaffold tournament game:references status:integer name:string:uniq min_players_per_team:integer max_players_per_team:integer min_teams_per_match:integer max_teams_per_match:integer set_rounds:integer randomized_teams:boolean sampling_method:string
@@ -60,9 +60,6 @@ bundle exec rails generate controller static
# not stick these in the views or anything.
bundle exec rails generate migration AddHiddenAttrsToUser password_digest:string permissions:integer
-#for the tournament controller to generate options
-#bundle exec rails generate scaffold
-
bundle exec rake db:drop
bundle exec rake db:migrate
bundle exec rake db:seed
diff --git a/lib/scheduling/elimination.rb b/lib/scheduling/elimination.rb
new file mode 100644
index 0000000..519d08a
--- /dev/null
+++ b/lib/scheduling/elimination.rb
@@ -0,0 +1,55 @@
+module Scheduling
+ class Elimination
+
+ def initialize(tournament_stage)
+ @tournament_stage = tournament_stage
+ end
+
+ def tournament_stage
+ @tournament_stage
+ end
+ def tournament
+ self.tournament_stage.tournament
+ end
+
+ def create_matches
+ num_teams = (self.tournament.players.count/self.tournament.min_players_per_team).floor
+ num_matches = num_teams - 1
+ for i in 1..num_matches
+ self.tournament_stage.matches.create(status: 0, submitted_peer_evaluations: 0)
+ end
+ match_num = num_matches-1
+ team_num = 0
+ # for each grouping of min_players_per_team
+ self.tournament.players.each_slice(min_players_per_team) do |team_members|
+ # if the match is full, move to the next match, otherwise move to the next team
+ if (team_num == min_teams_per_match)
+ match_num -= 1
+ team_num = 0
+ else
+ team_num += 1
+ end
+ # create a new team in the current match
+ self.tournament_stage.matches[match_num].teams.push(Team.create(users: team_members))
+ end
+ end
+
+ def match_finished(match)
+ matches = match.tournament_stage.matches_ordered
+ cur_match_num = matches.invert[match]
+ unless cur_match_num == 1
+ match.winner.matches.push(matches[cur_match_num/2])
+ end
+ end
+
+ def graph
+ require 'erb'
+ erb_filename = File.join(File.dirname(__FILE__), 'elimination.svg.erb')
+
+ erb = ERB.new(File.read(erb_filename))
+ erb.filename = erb_filename
+ return erb.result
+ end
+
+ end
+end
diff --git a/lib/scheduling/elimination.svg.erb b/lib/scheduling/elimination.svg.erb
new file mode 100644
index 0000000..91b8f6a
--- /dev/null
+++ b/lib/scheduling/elimination.svg.erb
@@ -0,0 +1,72 @@
+<%
+
+matches = @tournament_stage.matches_ordered
+# depth of SVG tree
+depth = Math.log2(matches.count).floor+1;
+# height of SVG
+height = 200 * 2**Math.log2(matches.count).floor + 100;
+lastrx = 0
+lastry = 0
+lastrh = 0
+lastrw = 0
+
+%><svg version="1.1" baseProfile="full"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ width="100%" height="<%= height = [height, 500].max %>">
+ <% %>
+ <defs>
+ <radialGradient id="gradMatch" cx="50%" cy="50%" r="80%" fx="80%" fy="80%">
+ <stop offset="0%" style="stop-color:#ffd281; stop-opacity:0" />
+ <stop offset="100%" style="stop-color:#ccc;stop-opacity:1" />
+ </radialGradient>
+ </defs>
+ <% (1..matches.count).each do |i| %>
+ <a id="svg-match-<%= i %>" xlink:href="<%= match_path(matches[i-1]) %>">
+ <rect height="<%= rh = 100/(2**(depth-1)+1) - 5 %>%"
+ width="<%= rw = 100/(depth+1) - 5 %>%"
+ x="<%= rx = 50/(depth+1) + 100/(depth+1)*(depth-(Math.log2(i).floor+1)) %>%"
+ y="<%= ry = ( 100/(2**(Math.log2(i).floor)+1) + rh * 1.1 * (2**Math.log2(i).ceil-i)) %>%"
+ fill="url(#gradMatch)"
+ rx="5px"
+ stroke-width="2"
+ <% case matches[i-1].status %>
+ <% when 0 %>
+ <% if matches[i-1].teams.count < @tournament_stage.tournament.min_teams_per_match %>
+ stroke="red"
+ fill-opacity="0.6"
+ <% else %>
+ stroke="green"
+ <% end %>
+ <% when 1 %>
+ stroke="orange"
+ <% when 2 %>
+ stroke="yellow"
+ <% when 3 %>
+ stroke="grey"
+ <% end %> />
+ <rect width="<%= rw-5 %>%" height="<%= rh/4 %>%" x="<%= rx + 2.5 %>%" y="<%= ry + rh/6 %>%" fill="<%= matches[i-1].teams.first and matches[i-1].teams.first.users.include?(current_user) ? "#BCED91" : "white" %>" />
+ <text x="<%= rx + rw/4 %>%" y="<%= ry + rh/3 %>%" font-size="<%= rh %>">
+ <% if matches[i-1].teams.first %>
+ Team <%= matches[i-1].teams.first.id %>
+ <% end %>
+ </text>
+ <text x="<%= rx + 1.3*rw/3 %>%" y="<%= ry + 5.2*rh/9 %>%" font-size="<%= rh %>"> VS </text>
+ <rect width="<%= rw-5 %>%" height="<%= rh/4 %>%" x="<%= rx + 2.5 %>%" y="<%= ry + 3*rh/5 %>%" fill="<%= matches[i-1].teams[1] and matches[i-1].teams[1].users.include?(current_user) ? "#BCED91" : "white" %>" />
+ <text x="<%= rx + rw/4 %>%" y="<%= ry + 4*rh/5 %>%" font-size="<%= rh %>">
+ <% if matches[i-1].teams[1] %>
+ Team <%= matches[i-1].teams[1].id %>
+ <% end %>
+ </text>
+ <% if i > 1 %>
+ <line x1="<%= rx+rw %>%" y1="<%= ry+rh/2 %>%" x2="<%= lastrx %>%" y2="<%= lastry+lastrh/2 %>%" stroke="black" stroke-width="2" >
+ <% end %>
+ <% if Math.log2(i+1) == Math.log2(i+1).ceil %>
+ <% lastrx = rx
+ lastry = ry
+ lastrh = rh
+ lastrw = rw %>
+ <% end %>
+ </a>
+ <% end %>
+</svg>
diff --git a/test/controllers/matches_controller_test.rb b/test/controllers/matches_controller_test.rb
index 033704e..d4ac1ed 100644
--- a/test/controllers/matches_controller_test.rb
+++ b/test/controllers/matches_controller_test.rb
@@ -18,7 +18,7 @@ class MatchesControllerTest < ActionController::TestCase
test "should create match" do
assert_difference('Match.count') do
- post :create, match: { name: @match.name, remote_id: @match.remote_id, status: @match.status, submitted_peer_evaluations: @match.submitted_peer_evaluations, tournament_stage_id: @match.tournament_stage_id, winner_id: @match.winner_id }
+ post :create, match: { remote_id: @match.remote_id, status: @match.status, submitted_peer_evaluations: @match.submitted_peer_evaluations, tournament_stage_id: @match.tournament_stage_id, winner_id: @match.winner_id }
end
assert_redirected_to match_path(assigns(:match))
@@ -35,7 +35,7 @@ class MatchesControllerTest < ActionController::TestCase
end
test "should update match" do
- patch :update, id: @match, match: { name: @match.name, remote_id: @match.remote_id, status: @match.status, submitted_peer_evaluations: @match.submitted_peer_evaluations, tournament_stage_id: @match.tournament_stage_id, winner_id: @match.winner_id }
+ patch :update, id: @match, match: { remote_id: @match.remote_id, status: @match.status, submitted_peer_evaluations: @match.submitted_peer_evaluations, tournament_stage_id: @match.tournament_stage_id, winner_id: @match.winner_id }
assert_redirected_to match_path(assigns(:match))
end
diff --git a/test/controllers/teams_controller_test.rb b/test/controllers/teams_controller_test.rb
index 52f7c17..8bf60be 100644
--- a/test/controllers/teams_controller_test.rb
+++ b/test/controllers/teams_controller_test.rb
@@ -18,7 +18,7 @@ class TeamsControllerTest < ActionController::TestCase
test "should create team" do
assert_difference('Team.count') do
- post :create, team: { match_id: @team.match_id }
+ post :create, team: { }
end
assert_redirected_to team_path(assigns(:team))
@@ -35,7 +35,7 @@ class TeamsControllerTest < ActionController::TestCase
end
test "should update team" do
- patch :update, id: @team, team: { match_id: @team.match_id }
+ patch :update, id: @team, team: { }
assert_redirected_to team_path(assigns(:team))
end
diff --git a/test/fixtures/matches.yml b/test/fixtures/matches.yml
index ff81182..4213238 100644
--- a/test/fixtures/matches.yml
+++ b/test/fixtures/matches.yml
@@ -3,15 +3,13 @@
one:
status: 1
tournament_stage_id:
- name: MyString
winner_id:
- remote_id: MyString
+ remote_id: MyText
submitted_peer_evaluations: 1
two:
status: 1
tournament_stage_id:
- name: MyString
winner_id:
- remote_id: MyString
+ remote_id: MyText
submitted_peer_evaluations: 1
diff --git a/test/fixtures/teams.yml b/test/fixtures/teams.yml
index 4efc76e..937a0c0 100644
--- a/test/fixtures/teams.yml
+++ b/test/fixtures/teams.yml
@@ -1,7 +1,11 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
-one:
- match_id:
-
-two:
- match_id:
+# This model initially had no columns defined. If you add columns to the
+# model remove the '{}' from the fixture names and add the columns immediately
+# below each fixture, per the syntax in the comments below
+#
+one: {}
+# column: value
+#
+two: {}
+# column: value