summaryrefslogtreecommitdiff
path: root/app/controllers/matches_controller.rb
diff options
context:
space:
mode:
authorguntasgrewal <guntasgrewal@gmail.com>2014-04-07 01:45:15 -0400
committerguntasgrewal <guntasgrewal@gmail.com>2014-04-07 01:45:15 -0400
commit13fe3bab84f236b46b3dbda080a22051553346c2 (patch)
tree6c9964c885e8f8b5828f2ab3bf3ad1edc53466cc /app/controllers/matches_controller.rb
parent366244bec2d0aa0c395949efadc0a6f714547aa1 (diff)
foo
Diffstat (limited to 'app/controllers/matches_controller.rb')
-rw-r--r--app/controllers/matches_controller.rb12
1 files changed, 12 insertions, 0 deletions
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.' }