From 36cdca9bc95599e67f73889c3ebf7d52f55f06eb Mon Sep 17 00:00:00 2001 From: AndrewMurrell Date: Sat, 26 Apr 2014 18:45:54 -0400 Subject: Added updated Skeleton for match controller. --- app/controllers/matches_controller.rb | 37 ++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb index b1b283b..6709a53 100644 --- a/app/controllers/matches_controller.rb +++ b/app/controllers/matches_controller.rb @@ -168,6 +168,10 @@ class MatchesController < ApplicationController def update case params[:update_action] when "start" + # + # Redirect to the current match page for this tournament with the correct sampling view rendered + # + @match.status = 1 respond_to do |format| if @match.save @@ -180,15 +184,30 @@ class MatchesController < ApplicationController 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.blowout = false + @match.statistics.create(name: "blowout", user: nil, value: 0) - @match.statistics['Score'] = @tournament.settings['ScoringMethod'].constantize.score(@match, @match.statistics) -=begin + #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| @@ -233,6 +252,10 @@ class MatchesController < ApplicationController end end when "peer" + # + # Update user scores via scoring method + # + order = params[:review_action] base_score = 2 next_score = 3 @@ -262,10 +285,14 @@ class MatchesController < ApplicationController end end when "reset" - @match.status = 0 + # + # Reset Match Status to 1 in case something needs to be replayed. + # + + @match.status = 1 respond_to do |format| if @match.save - format.html { redirect_to tournament_match_path(@tournament, @match), notice: 'Match Status Reset to 0' } + format.html { redirect_to tournament_match_path(@tournament, @match), notice: 'Match Status Reset to 1' } format.json { head :no_content } else format.html { redirect_to @tournament, notice: "You don't have permission to start this match." } -- cgit v1.2.3-2-g168b From 96dd3fbe302eec54b34678e098d3b59710b09b5f Mon Sep 17 00:00:00 2001 From: tkimia Date: Sat, 26 Apr 2014 19:16:19 -0400 Subject: prelim bracket control --- app/controllers/brackets_controller.rb | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/brackets_controller.rb b/app/controllers/brackets_controller.rb index fe43ca9..ebd0c6b 100644 --- a/app/controllers/brackets_controller.rb +++ b/app/controllers/brackets_controller.rb @@ -12,11 +12,6 @@ class BracketsController < ApplicationController def show end - # GET /brackets/new - def new - @bracket = Bracket.new - end - # GET /brackets/1/edit def edit end @@ -29,7 +24,7 @@ class BracketsController < ApplicationController 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 +59,12 @@ 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 # 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) + params.fetch(:bracket, {}).permit(:user_id, :tournament_id, :name) end end -- cgit v1.2.3-2-g168b From 93e291c8e5002fdea906bb8c96cd528fa8b75935 Mon Sep 17 00:00:00 2001 From: tkimia Date: Sat, 26 Apr 2014 19:39:57 -0400 Subject: brackets just get created --- app/controllers/brackets_controller.rb | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/brackets_controller.rb b/app/controllers/brackets_controller.rb index ebd0c6b..37f1803 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 @@ -19,7 +20,7 @@ class BracketsController < ApplicationController # POST /brackets # POST /brackets.json def create - @bracket = Bracket.new(bracket_params) + @bracket = @tournament.brackets.create(user: current_user) respond_to do |format| if @bracket.save @@ -63,8 +64,16 @@ class BracketsController < ApplicationController @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.fetch(:bracket, {}).permit(:user_id, :tournament_id, :name) + params.require(:bracket).permit(:user_id, :tournament_id, :name) + end + + def is_owner?(bracket) + bracket.user == current_user end end -- cgit v1.2.3-2-g168b From e60adb874faffd9bac678a19043532ff33dc6b07 Mon Sep 17 00:00:00 2001 From: tkimia Date: Sat, 26 Apr 2014 20:14:00 -0400 Subject: bracket creation is good --- app/controllers/brackets_controller.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'app/controllers') diff --git a/app/controllers/brackets_controller.rb b/app/controllers/brackets_controller.rb index 37f1803..ed335d6 100644 --- a/app/controllers/brackets_controller.rb +++ b/app/controllers/brackets_controller.rb @@ -21,6 +21,8 @@ class BracketsController < ApplicationController # POST /brackets.json def create @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 -- cgit v1.2.3-2-g168b From 62219ac4e3af36cc15c9ad61701550bee9a8424c Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sat, 26 Apr 2014 20:16:33 -0400 Subject: run ./generate.sh --- app/controllers/games_controller.rb | 2 +- app/controllers/tournaments_controller.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 8546efb..76a6296 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -69,6 +69,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/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index 6bf79fd..64ab155 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -69,6 +69,6 @@ class TournamentsController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def tournament_params - 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) end end -- cgit v1.2.3-2-g168b From 7d97ad8ff641c1f5d67706bec053c77ece70b18a Mon Sep 17 00:00:00 2001 From: AndrewMurrell Date: Sat, 26 Apr 2014 20:24:56 -0400 Subject: Made tons of red. Scheduling works from lib. --- app/controllers/matches_controller.rb | 48 +++-------------------------------- 1 file changed, 4 insertions(+), 44 deletions(-) (limited to 'app/controllers') 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 -- cgit v1.2.3-2-g168b