From cd19b2591a52ac604632a70929448ee5e78c2568 Mon Sep 17 00:00:00 2001 From: AndrewMurrell Date: Mon, 28 Apr 2014 18:29:01 -0400 Subject: Misc fixes. (This commit is from Luke on Andrew's box) --- app/controllers/matches_controller.rb | 16 ++++------------ app/models/match.rb | 7 ++----- lib/sampling/manual.rb | 4 ++-- lib/sampling/peer_review.rb | 8 ++++---- lib/scoring/winner_takes_all.rb | 4 ++-- 5 files changed, 14 insertions(+), 25 deletions(-) diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb index bed06ba..5745ac9 100644 --- a/app/controllers/matches_controller.rb +++ b/app/controllers/matches_controller.rb @@ -45,18 +45,10 @@ class MatchesController < ApplicationController when 2 # Started, waiting to finish @match.handle_sampling(params) - if @match.finished? - @match.status = 3 - respond_to do |format| - if @match.save - format.html { redirect_to tournament_match_path(@tournament, @match), notice: 'Match has finished.' } - format.json { head :no_content } - else - format.html { render action: 'show' } - format.json { render json: @match.errors, status: :unprocessable_entity } - end - end - return + # The @match.status will be updated by Statistic's after_save hook + respond_to do |format| + format.html { redirect_to tournament_match_path(@tournament, @match), notice: 'Match has finished.' } + format.json { head :no_content } end when 3 if (@tournament.hosts.include? current_user) and (params[:update_action] == "start") diff --git a/app/models/match.rb b/app/models/match.rb index 4c7acbf..219e662 100644 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -5,9 +5,6 @@ class Match < ActiveRecord::Base belongs_to :winner, class_name: "Team" - def setup() - end - def finished? ok = true tournament_stage.scoring_method.stats_needed.each do |stat| @@ -59,7 +56,7 @@ class Match < ActiveRecord::Base method_class = "Sampling::#{method_name.camelcase}".constantize needed.each do |stat| data[stat] ||= {} - data[stat][method] = method_class.can_get?(user, stat) + data[stat][method_class] = method_class.can_get?(stat) end end @@ -83,7 +80,7 @@ class Match < ActiveRecord::Base if @method_classes.nil? data = Set.new figure_sampling_methods.each do |stat,method| - data.push(method) + data.add(method) end @method_classes = data end diff --git a/lib/sampling/manual.rb b/lib/sampling/manual.rb index a190bd2..cfecd8f 100644 --- a/lib/sampling/manual.rb +++ b/lib/sampling/manual.rb @@ -4,7 +4,7 @@ module Sampling return true end - def can_get?(setting_name) + def self.can_get?(setting_name) return 1 end @@ -36,7 +36,7 @@ module Sampling @stats = @match.stats_from(self.class) require 'erb' - erb_filename = File.join(__FILE__.sub(/\.rb$/, '.svg.erb')) + erb_filename = File.join(__FILE__.sub(/\.rb$/, '.html.erb')) erb = ERB.new(File.read(erb_filename)) erb.filename = erb_filename return erb.result.html_safe diff --git a/lib/sampling/peer_review.rb b/lib/sampling/peer_review.rb index 4577542..e86595f 100644 --- a/lib/sampling/peer_review.rb +++ b/lib/sampling/peer_review.rb @@ -5,7 +5,7 @@ module Sampling end def self.can_get?(setting_name) - return setting_name.start_with?("feedback_from_") + return setting_name.start_with?("feedback_from_") ? 2 : 0 end def self.uses_remote? @@ -36,7 +36,7 @@ module Sampling @feedbacks_missing = get_feedbacks_missing(match) require 'erb' - erb_filename = File.join(__FILE__.sub(/\.rb$/, '.svg.erb')) + erb_filename = File.join(__FILE__.sub(/\.rb$/, '.html.erb')) erb = ERB.new(File.read(erb_filename)) erb.filename = erb_filename return erb.result.html_safe @@ -74,14 +74,14 @@ module Sampling def self.get_feedbacks_missing(match) require 'set' - ret = Set.new() + ret = Set.new feedback = get_feedbacks(match) users = get_users(match) feedback.each do |feedback| (users - feedback.keys).each do |user| - ret.push(user) + ret.add(user) end end diff --git a/lib/scoring/winner_takes_all.rb b/lib/scoring/winner_takes_all.rb index bf95781..57ddae6 100644 --- a/lib/scoring/winner_takes_all.rb +++ b/lib/scoring/winner_takes_all.rb @@ -1,13 +1,13 @@ module Scoring module WinnerTakesAll def self.stats_needed - return [] + return ["win"] end def self.score(match, interface) scores = {} match.players.each do |player| - scores[player.user_name] = score_user(match.win?(player)) + scores[player.user_name] = score_user(player.statistics.where(:match => match, :name => "win").value) end scores end -- cgit v1.2.3