From 42d6e3b1cc05ef5172081682b53675e4827254d3 Mon Sep 17 00:00:00 2001 From: tkimia Date: Tue, 29 Apr 2014 16:41:35 -0400 Subject: elimination works SOMETIMES... other times it just can't put down a damned winner --- lib/sampling/manual.rb | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'lib/sampling/manual.rb') diff --git a/lib/sampling/manual.rb b/lib/sampling/manual.rb index 01f6835..a9f9de4 100644 --- a/lib/sampling/manual.rb +++ b/lib/sampling/manual.rb @@ -33,7 +33,6 @@ module Sampling def render_user_interaction(user) @tournament = @match.tournament_stage.tournament @current_user = user - @users = @match.users @stats = @match.stats_from(self.class) require 'erb' @@ -43,11 +42,28 @@ module Sampling return erb.result(binding).html_safe end - def handle_user_interaction(user, sampling_params) + def handle_user_interaction(user, params) # => Save sampling_params as statistics - sampling_params.select {|name, value| @match.stats_from(self.class).include? name }.each do |name, value| - Statistic.create(name: value, user: user, match: @match) - end - end + require 'pp' + puts('>'*80) + pp @match + puts('>'*80) + if (@match.tournament_stage.tournament.hosts.include? user) + manual_params = params.require(:manual) + winner = Team.find(manual_params[:winner]) + @match.users.each do |user| + puts('>'*80) + pp "MAKING statistics BIIIIIIIITCH" + puts('>'*80) + Statistic.create(match: @match, user: user, + name: "win", value: winner.users.include?(user)) + @match.stats_from(self.class).reject{|s|s=="win"}.each do |stat| + Statistic.create(match: @match, user: user, + name: stat, value: manual_params[:statistics][user.id][stat].to_i) + end # stats + end # users + end # permission + end # def + end end -- cgit v1.2.3