blob: 853516c030852c68c23624dcc8cf9689eba3309f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
module Sampling
class Manual
def self.works_with?(game)
return true
end
def self.can_get?(setting_name)
return 1
end
def self.uses_remote?
return false
end
def self.set_remote_name(user, game, value)
raise "This sampling method doesn't use remote usernames."
end
def self.get_remote_name(value)
raise "This sampling method doesn't use remote usernames."
end
####
def initialize(match)
@match = match
end
def start
# do nothing
end
def render_user_interaction(user)
@tournament = @match.tournament_stage.tournament
@current_user = user
@stats = @match.stats_from(self.class)
require 'erb'
erb_filename = File.join(__FILE__.sub(/\.rb$/, '.html.erb'))
erb = ERB.new(File.read(erb_filename))
erb.filename = erb_filename
return erb.result(binding).html_safe
end
def handle_user_interaction(user, params)
# => Save sampling_params as statistics
if (@match.tournament_stage.tournament.hosts.include? user)
manual_params = params.require(:manual)
winner = Team.find(manual_params[:winner])
@match.users.each do |user|
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
|