diff options
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/matches_controller.rb | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb index 9c0a740..9e376f7 100644 --- a/app/controllers/matches_controller.rb +++ b/app/controllers/matches_controller.rb @@ -144,9 +144,6 @@ class MatchesController < ApplicationController handle_asynchronously :is_match_over def show - if (@match.status == 1) - @scores = @match.scores - end if Tournament.find_by_id(@match.tournament_id).game_id == 1 file_blue = "blue.yaml" file_purple = "purple.yaml" @@ -168,11 +165,32 @@ class MatchesController < ApplicationController format.json { render json: "Permission denied", status: :forbidden } end end - when "score" + when "finish" + @match.status = 2 + + # Individual scores scores = params["scores"] scores.each do |user_name, score| Score.create(user: User.find_by_user_name(user_name), match: @match, value: score.to_i) end + + # Team scores + 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 + 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 + respond_to do |format| if @match.save format.html { redirect_to tournament_match_path(@tournament, @match), notice: 'Peer evaluation started.' } @@ -183,17 +201,6 @@ class MatchesController < ApplicationController end end when "peer" - @match.status = 2; - respond_to do |format| - if @match.save - format.html { redirect_to tournament_match_path(@tournament, @match), notice: 'Scores Submitted' } - format.json { head :no_content } - else - format.html { redirect_to @tournament, notice: "You don't have permission to start this match." } - format.json { render json: "Permission denied", status: :forbidden } - end - end - when "finish" order = params[:review_action] base_score = 2 next_score = 3 @@ -214,7 +221,7 @@ class MatchesController < ApplicationController end respond_to do |format| if @match.save - format.html { redirect_to tournament_match_path(@tournament, @match), notice: 'Peer Review Submitted' } + format.html { redirect_to tournament_match_path(@tournament, @match), notice: 'Scores Submitted' } format.json { head :no_content } else format.html { redirect_to @tournament, notice: "You don't have permission to start this match." } @@ -232,7 +239,6 @@ class MatchesController < ApplicationController format.json { render json: "Permission denied", status: :forbidden } end end - else respond_to do |format| format.html { redirect_to @tournament, notice: "Invalid action", status: :unprocessable_entity } @@ -247,7 +253,6 @@ class MatchesController < ApplicationController def set_match set_tournament @match = @tournament.matches.find(params[:id]) - @first = @match.teams.first.users.first.user_name.downcase end def set_tournament @tournament = Tournament.find(params[:tournament_id]) |