diff options
author | nfoy <nfoy@purdue.edu> | 2014-04-26 20:57:26 -0400 |
---|---|---|
committer | nfoy <nfoy@purdue.edu> | 2014-04-26 20:57:26 -0400 |
commit | 31d458e59077340f28955033735f5c433197cb75 (patch) | |
tree | 8784a35b5d50f32ce693c0427b277f7238c6d691 /app | |
parent | 00f3d70445d7cae0976ec9794e555c52a1765b24 (diff) | |
parent | edcca83c6c251a79afcd83760cf20ebaf00b3b32 (diff) |
Merge branch 'master' of https://github.com/LukeShu/leaguer
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/alerts_controller.rb | 5 | ||||
-rw-r--r-- | app/controllers/brackets_controller.rb | 25 | ||||
-rw-r--r-- | app/controllers/games_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/matches_controller.rb | 48 | ||||
-rw-r--r-- | app/controllers/tournaments_controller.rb | 5 | ||||
-rw-r--r-- | app/models/bracket.rb | 7 | ||||
-rw-r--r-- | app/models/tournament.rb | 17 | ||||
-rw-r--r-- | app/models/tournament_stage.rb | 52 | ||||
-rw-r--r-- | app/models/user.rb | 4 | ||||
-rw-r--r-- | app/views/brackets/index.html.erb | 7 | ||||
-rw-r--r-- | app/views/brackets/new.html.erb | 4 | ||||
-rw-r--r-- | app/views/brackets/show.html.erb | 14 | ||||
-rw-r--r-- | app/views/common/_show_tournament.html.erb | 3 | ||||
-rw-r--r-- | app/views/games/_form.html.erb | 4 | ||||
-rw-r--r-- | app/views/games/index.html.erb | 2 | ||||
-rw-r--r-- | app/views/games/index.json.jbuilder | 2 | ||||
-rw-r--r-- | app/views/games/show.html.erb | 5 | ||||
-rw-r--r-- | app/views/games/show.json.jbuilder | 2 | ||||
-rw-r--r-- | app/views/matches/show.html.erb | 20 | ||||
-rw-r--r-- | app/views/tournaments/_form.html.erb | 4 | ||||
-rw-r--r-- | app/views/tournaments/index.json.jbuilder | 2 | ||||
-rw-r--r-- | app/views/tournaments/show.json.jbuilder | 2 |
22 files changed, 106 insertions, 130 deletions
diff --git a/app/controllers/alerts_controller.rb b/app/controllers/alerts_controller.rb index 6ab3663..1d09864 100644 --- a/app/controllers/alerts_controller.rb +++ b/app/controllers/alerts_controller.rb @@ -24,6 +24,11 @@ class AlertsController < ApplicationController def create @alert = Alert.new(alert_params) @alert.author = current_user + users = {} + users = Users.all + + #current_user.send_message(users, @alert.message, "Pay Attention!") + respond_to do |format| if @alert.save format.html { redirect_to @alert, notice: 'Alert was successfully created.' } diff --git a/app/controllers/brackets_controller.rb b/app/controllers/brackets_controller.rb index fe43ca9..ed335d6 100644 --- a/app/controllers/brackets_controller.rb +++ b/app/controllers/brackets_controller.rb @@ -1,10 +1,11 @@ class BracketsController < ApplicationController - before_action :set_bracket, only: [:show, :edit, :update, :destroy] + before_action :set_tournament, only: [:index, :create] # GET /brackets # GET /brackets.json def index - @brackets = Bracket.all + @tournament = Tournament.find(params[:tournament_id]) + @brackets = @tournament.brackets end # GET /brackets/1 @@ -12,11 +13,6 @@ class BracketsController < ApplicationController def show end - # GET /brackets/new - def new - @bracket = Bracket.new - end - # GET /brackets/1/edit def edit end @@ -24,12 +20,14 @@ class BracketsController < ApplicationController # POST /brackets # POST /brackets.json def create - @bracket = Bracket.new(bracket_params) + @bracket = @tournament.brackets.create(user: current_user) + @bracket.name = current_user.user_name + "'s Prediction for " + @tournament.name + @bracket.create_matches respond_to do |format| if @bracket.save format.html { redirect_to @bracket, notice: 'Bracket was successfully created.' } - format.json { render action: 'show', status: :created, location: @bracket } + format.json { render action: 'edit', status: :created, location: @bracket } else format.html { render action: 'new' } format.json { render json: @bracket.errors, status: :unprocessable_entity } @@ -64,11 +62,20 @@ class BracketsController < ApplicationController private # Use callbacks to share common setup or constraints between actions. def set_bracket + @tournament = Tournament.find(params[:tournament_id]) @bracket = Bracket.find(params[:id]) end + def set_tournament + @tournament = Tournament.find(params[:tournament_id]) + end + # Never trust parameters from the scary internet, only allow the white list through. def bracket_params params.require(:bracket).permit(:user_id, :tournament_id, :name) end + + def is_owner?(bracket) + bracket.user == current_user + end end diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index aec5294..09119c8 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -67,6 +67,6 @@ class GamesController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def game_params - params.require(:game).permit(:parent_id, :name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams, :sampling_method) + params.require(:game).permit(:parent_id, :name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams, :sampling_method, :scoring_method) end end diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb index 6709a53..a2a1269 100644 --- a/app/controllers/matches_controller.rb +++ b/app/controllers/matches_controller.rb @@ -183,54 +183,13 @@ class MatchesController < ApplicationController end end when "finish" - # # Get the winner and blowout status from the params given by the correct sampling view # - - #in general - #provide contribution - #if all contributions are in, update statistics - - - #make this use the statistics interface for scoring and ScoringAlgorithms - - @match.winner = @match.teams.find_by_id(params['winner']) - @match.statistics.create(name: "blowout", user: nil, value: 0) - - - #How to access the blowout statistic of a match: - @match.statistics.where(:name => "blowout").first.value - - - - #@match.statistics.create(name: 'score', value: @tournament.settings.where(:name => 'Scoring Method').value.constantize.score(@match, @match.statistics) - -=begin - # Individual scores - #scores = params["scores"] - #scores.each do |user_name, score| - # Statistic.create(user: User.find_by_user_name(user_name), match: @match, name: "score", value: score.to_i) - #end - - # Team scores (processing for manual) - team_scores = {} - @match.teams.each do |team| - team_scores[team] = 0 - team.users.each do |user| - team_scores[team] += scores[user.user_name].to_i - end + unless @match.tournament_stage.tournament.sampling.sampling_done? + @match.tournament_stage.tournament.sampling.handle_user_interaction(@match, current_user, params) end - teams = team_scores.invert - @match.winner = teams[teams.keys.sort.last] - - # Schedule next match - #cur_match_num = @tournament.matches_ordered.invert[@match] - #unless cur_match_num == 1 - # @match.winner.matches.push(@tournament.matches_ordered[cur_match_num/2]) - #end -=end # Skip peer evaluation if there aren't enough players per team peer = false @@ -241,7 +200,6 @@ class MatchesController < ApplicationController end @match.status = peer ? 2 : 3 - respond_to do |format| if @match.save format.html { redirect_to tournament_match_path(@tournament, @match), notice: 'Peer evaluation started.' } @@ -256,6 +214,8 @@ class MatchesController < ApplicationController # Update user scores via scoring method # + #update this to use scoring interface + order = params[:review_action] base_score = 2 next_score = 3 diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index 1354ad6..60f8789 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -116,7 +116,8 @@ class TournamentsController < ApplicationController success = true ActiveRecord::Base.transaction do success &= @tournament.save && - success &= @tournament.stages.create(scheduling: "elimination") + sched = tournament_attribute_params[:type_opt] + success &= @tournament.stages.create(scheduling: sched) success &= @tournament.stages.first.create_matches end if success @@ -162,7 +163,7 @@ class TournamentsController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def tournament_attribute_params if params[:tournament] - params.require(:tournament).permit(:game_id, :status, :name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams, :sampling_method) + params.require(:tournament).permit(:game_id, :status, :name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams, :sampling_method, :scoring_method) else return {} end diff --git a/app/models/bracket.rb b/app/models/bracket.rb index e8d9c5a..acd33ca 100644 --- a/app/models/bracket.rb +++ b/app/models/bracket.rb @@ -1,4 +1,11 @@ class Bracket < ActiveRecord::Base belongs_to :user belongs_to :tournament + has_many :bracket_matches + + def create_matches + tournament.stages.first.matches.each do |m| + bracket_matches.create(match: m) + end + end end diff --git a/app/models/tournament.rb b/app/models/tournament.rb index 861be6c..61b4700 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -1,10 +1,13 @@ class Tournament < ActiveRecord::Base belongs_to :game has_many :stages, class_name: "TournamentStage" + has_many :brackets 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" + # Settings ################################################################# + def settings @settings ||= Settings.new(self) end @@ -56,10 +59,14 @@ class Tournament < ActiveRecord::Base end end + # Misc. #################################################################### + def open? return true end + # Joining/Leaving ########################################################## + def joinable_by?(user) return (open? and user.can?(:join_tournament) and !players.include?(user)) end @@ -76,4 +83,14 @@ class Tournament < ActiveRecord::Base players.delete(user) end end + + # Configured methods ####################################################### + + def scoring + @scoring ||= "Scoring::#{self.scoring_method.camelcase}".constantize + end + + def sampling + @sampling ||= "Sampling::#{self.sampling_method.camelcase}".constantize + end end diff --git a/app/models/tournament_stage.rb b/app/models/tournament_stage.rb index 0775305..9352137 100644 --- a/app/models/tournament_stage.rb +++ b/app/models/tournament_stage.rb @@ -2,6 +2,7 @@ class TournamentStage < ActiveRecord::Base belongs_to :tournament has_many :matches + # A 1-indexed hash of matches def matches_ordered h = {} i = 1 @@ -13,57 +14,32 @@ class TournamentStage < ActiveRecord::Base end def create_matches - set_scheduling - @scheduling.create_matches + scheduling.create_matches end def to_svg(highlight_user) - set_scheduling - return @scheduling.graph(highlight_user) + return scheduling.graph(highlight_user) end - def pair - set_pairing - return @pairing.pair(matches, players) + def seed + return seeding.seed.pair(matches, players) end - def score - set_scoring - #populating the user scores in the database form what you get from @scoring.score(match, interface) - end + # Accessors to the configured methods - #populate the statistics interface (with populating method) - def populate - set_populating - #? + def scoring + @scoring ||= tournament.scoring end - private - def set_scheduling - if @scheduling.nil? - @scheduling = "Scheduling::#{self.scheduling.capitalize}".constantize.new(self) - end - return @scheduling - end - - private - def set_pairing - if @pairing.nil? - if(@tournament.randomized_teams) - @pairing = "Pairing::RandomPairing" - #elsif(setTeams) - #@pairing = Pre built - #return @pairing - end - end - return @pairing + def sampling + @sampling ||= tournament.sampling end - private - def set_scoring + def scheduling + @scheduling ||= "Scheduling::#{self.scheduling_method.camelcase}".constantize.new(self) end - private - def set_populating + def seeding + @seeding ||= "Seeding::#{self.seeding_method.camelcase}".constantize.new(self) end end diff --git a/app/models/user.rb b/app/models/user.rb index d87f988..b2c7862 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -74,6 +74,10 @@ class User < ActiveRecord::Base :edit_permissions => (2**19), :edit_server => (2**20), + + :create_bracket => (2**21), + :edit_bracket => (2**22), + :delete_bracket => (2**23) } end diff --git a/app/views/brackets/index.html.erb b/app/views/brackets/index.html.erb index 2195d69..9effe37 100644 --- a/app/views/brackets/index.html.erb +++ b/app/views/brackets/index.html.erb @@ -8,7 +8,6 @@ <th>Name</th> <th></th> <th></th> - <th></th> </tr> </thead> @@ -18,9 +17,8 @@ <td><%= bracket.user %></td> <td><%= bracket.tournament %></td> <td><%= bracket.name %></td> - <td><%= link_to 'Show', bracket %></td> - <td><%= link_to 'Edit', edit_bracket_path(bracket) %></td> - <td><%= link_to 'Destroy', bracket, method: :delete, data: { confirm: 'Are you sure?' } %></td> + <td><%= link_to 'Show', tournament_bracket_path(@tournament, bracket) %></td> + <td><%= link_to 'Edit', edit_tournament_bracket_path(@tournament, bracket) %></td> </tr> <% end %> </tbody> @@ -28,4 +26,3 @@ <br> -<%= link_to 'New Bracket', new_bracket_path %> diff --git a/app/views/brackets/new.html.erb b/app/views/brackets/new.html.erb index c379c15..91d0033 100644 --- a/app/views/brackets/new.html.erb +++ b/app/views/brackets/new.html.erb @@ -1,5 +1,3 @@ <h1>New bracket</h1> -<%= render 'form' %> - -<%= link_to 'Back', brackets_path %> +<%= link_to 'Back', tournament_brackets_path %> diff --git a/app/views/brackets/show.html.erb b/app/views/brackets/show.html.erb index 9c7c14b..2e92bfb 100644 --- a/app/views/brackets/show.html.erb +++ b/app/views/brackets/show.html.erb @@ -1,13 +1,11 @@ -<p id="notice"><%= notice %></p> - <p> <strong>User:</strong> - <%= @bracket.user %> + <%= @bracket.user.user_name %> </p> <p> <strong>Tournament:</strong> - <%= @bracket.tournament %> + <%= @bracket.tournament.name %> </p> <p> @@ -15,5 +13,9 @@ <%= @bracket.name %> </p> -<%= link_to 'Edit', edit_bracket_path(@bracket) %> | -<%= link_to 'Back', brackets_path %> +<% @bracket.bracket_matches.each do |m| %> + <p><b><%= m.match.id %></b></p> +<% end %> + + +<%= link_to 'Back', tournaments_path %> diff --git a/app/views/common/_show_tournament.html.erb b/app/views/common/_show_tournament.html.erb index 0f60fad..b16a37b 100644 --- a/app/views/common/_show_tournament.html.erb +++ b/app/views/common/_show_tournament.html.erb @@ -29,6 +29,9 @@ <% else %> <p style="margin-top:10px;"> You've signed up for this tournament! </p> <% end %> + <%= form_tag(tournament_brackets_path(target), method: "post") do %> + <%= submit_tag("Make Bracket") %> + <% end %> <% end %> </div> </div>
\ No newline at end of file diff --git a/app/views/games/_form.html.erb b/app/views/games/_form.html.erb index 20cb214..b1db0b3 100644 --- a/app/views/games/_form.html.erb +++ b/app/views/games/_form.html.erb @@ -47,6 +47,10 @@ <%= f.label :sampling_method %><br> <%= f.text_field :sampling_method %> </div> + <div class="field"> + <%= f.label :scoring_method %><br> + <%= f.text_field :scoring_method %> + </div> <div class="actions"> <%= f.submit %> </div> diff --git a/app/views/games/index.html.erb b/app/views/games/index.html.erb index bcd10dd..3045325 100644 --- a/app/views/games/index.html.erb +++ b/app/views/games/index.html.erb @@ -12,6 +12,7 @@ <th>Set rounds</th> <th>Randomized teams</th> <th>Sampling method</th> + <th>Scoring method</th> <th></th> <th></th> <th></th> @@ -30,6 +31,7 @@ <td><%= game.set_rounds %></td> <td><%= game.randomized_teams %></td> <td><%= game.sampling_method %></td> + <td><%= game.scoring_method %></td> <td><%= link_to 'Show', game %></td> <td><%= link_to 'Edit', edit_game_path(game) %></td> <td><%= link_to 'Destroy', game, method: :delete, data: { confirm: 'Are you sure?' } %></td> diff --git a/app/views/games/index.json.jbuilder b/app/views/games/index.json.jbuilder index 6b20f60..7964f2c 100644 --- a/app/views/games/index.json.jbuilder +++ b/app/views/games/index.json.jbuilder @@ -1,4 +1,4 @@ json.array!(@games) do |game| - json.extract! game, :id, :parent_id, :name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams, :sampling_method + json.extract! game, :id, :parent_id, :name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams, :sampling_method, :scoring_method json.url game_url(game, format: :json) end diff --git a/app/views/games/show.html.erb b/app/views/games/show.html.erb index 1250cbd..1a18356 100644 --- a/app/views/games/show.html.erb +++ b/app/views/games/show.html.erb @@ -43,5 +43,10 @@ <%= @game.sampling_method %> </p> +<p> + <strong>Scoring method:</strong> + <%= @game.scoring_method %> +</p> + <%= link_to 'Edit', edit_game_path(@game) %> | <%= link_to 'Back', games_path %> diff --git a/app/views/games/show.json.jbuilder b/app/views/games/show.json.jbuilder index 087a156..c5fb4ed 100644 --- a/app/views/games/show.json.jbuilder +++ b/app/views/games/show.json.jbuilder @@ -1 +1 @@ -json.extract! @game, :id, :parent_id, :name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams, :sampling_method, :created_at, :updated_at +json.extract! @game, :id, :parent_id, :name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams, :sampling_method, :scoring_method, :created_at, :updated_at diff --git a/app/views/matches/show.html.erb b/app/views/matches/show.html.erb index 7a82527..8344a7a 100644 --- a/app/views/matches/show.html.erb +++ b/app/views/matches/show.html.erb @@ -78,24 +78,8 @@ function score_peers() { <!-- Started, waiting to finish --> <!-- This will depend on the Sampling Method Eventually instead of always being Manual --> - <% case @tournament.sampling_method %> - <% when "Manual" %> - <% if @tournament.hosts.include? current_user %> - <input type="hidden" name="update_action" value="finish"> - <% @match.teams.each do |team| %> - <%= tag :input, {"type" => "radio", "name" => "winner", "value" => "#{team.id}" } %> - <%= "Team #{team.id} Won" %> - <% end %> - <%= submit_tag("Finish match") %> - <%= @tournament.settings['ScoringMethod'] %> - <% else %> - <p>The match is running; the host has yet to post the scores of the match.</p> - <% end %> - <% when "Double Blind" %> - <p>Double Blind isn't implemented yet.</p> - <% when "RiotAPI" %> - <p>Riot API is being called for Statistics. Results will appear shortly.</p> - <% end %> + <%= raw @match.tournament_stage.tournament.sampling_method.camelcase.constantize.render_user_interaction(@match, current_user) %> + <% when 2 %> <!-- Finished, waiting for peer reviews --> <input type="hidden" name="update_action" value="peer"> diff --git a/app/views/tournaments/_form.html.erb b/app/views/tournaments/_form.html.erb index 9b9681c..7127d38 100644 --- a/app/views/tournaments/_form.html.erb +++ b/app/views/tournaments/_form.html.erb @@ -51,6 +51,10 @@ <%= f.label :sampling_method %><br> <%= f.text_field :sampling_method %> </div> + <div class="field"> + <%= f.label :scoring_method %><br> + <%= f.text_field :scoring_method %> + </div> <div class="actions"> <%= f.submit %> </div> diff --git a/app/views/tournaments/index.json.jbuilder b/app/views/tournaments/index.json.jbuilder index 7118ecc..bd86e04 100644 --- a/app/views/tournaments/index.json.jbuilder +++ b/app/views/tournaments/index.json.jbuilder @@ -1,4 +1,4 @@ json.array!(@tournaments) do |tournament| - json.extract! tournament, :id, :game_id, :status, :name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams, :sampling_method + json.extract! tournament, :id, :game_id, :status, :name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams, :sampling_method, :scoring_method json.url tournament_url(tournament, format: :json) end diff --git a/app/views/tournaments/show.json.jbuilder b/app/views/tournaments/show.json.jbuilder index 4542e52..ff82412 100644 --- a/app/views/tournaments/show.json.jbuilder +++ b/app/views/tournaments/show.json.jbuilder @@ -1 +1 @@ -json.extract! @tournament, :id, :game_id, :status, :name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams, :sampling_method, :created_at, :updated_at +json.extract! @tournament, :id, :game_id, :status, :name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams, :sampling_method, :scoring_method, :created_at, :updated_at |