From 13fe3bab84f236b46b3dbda080a22051553346c2 Mon Sep 17 00:00:00 2001 From: guntasgrewal Date: Mon, 7 Apr 2014 01:45:15 -0400 Subject: foo --- app/controllers/matches_controller.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'app/controllers/matches_controller.rb') diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb index 93b5514..e88b6ef 100644 --- a/app/controllers/matches_controller.rb +++ b/app/controllers/matches_controller.rb @@ -172,6 +172,18 @@ class MatchesController < ApplicationController 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 = {} + @match.teams.each do |team| + team_scores[team] = 0 + team.users.each do |user| + team_scores[team] += scores[user.user_name] + end + end + + teams = team_scores.invert + @match.winner = teams[teams.keys.sort.last] + respond_to do |format| if @match.save format.html { redirect_to tournament_match_path(@tournament, @match), notice: 'Peer evaluation started.' } -- cgit v1.2.3