diff options
author | guntasgrewal <guntasgrewal@gmail.com> | 2014-04-28 00:35:54 -0400 |
---|---|---|
committer | guntasgrewal <guntasgrewal@gmail.com> | 2014-04-28 00:35:54 -0400 |
commit | fa8ec3d1e21de1456af74d411117a1b9d5e0bbc0 (patch) | |
tree | db39868fb318275947ea4e419295bdcf47978a8c /app/models/match.rb | |
parent | fbd258986b41b96a9f901d6be03bcfa9111fe13d (diff) | |
parent | 0a5242c3a460d0b99be0adc4593774a58b68154a (diff) |
Merge branch 'master' of https://github.com/LukeShu/leaguer
Diffstat (limited to 'app/models/match.rb')
-rw-r--r-- | app/models/match.rb | 72 |
1 files changed, 67 insertions, 5 deletions
diff --git a/app/models/match.rb b/app/models/match.rb index d4c0ce5..3cbe0da 100644 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -12,6 +12,7 @@ class Match < ActiveRecord::Base ok = true tournament_stage.scoring_method.stats_needed.each do |stat| ok &= statistics.where(match: self, name: stat).nil? + end ok end @@ -19,15 +20,76 @@ class Match < ActiveRecord::Base winner.players.include? player end - def handle_sampling(params) - # TODO + def users + ret = [] + self.teams.each{|t| ret.concat(t.users)} + return ret + end + + def stats_from(sampling_class) + figure_sampling_methods.map{|stat,klass| (sampling_class==klass) ? stat : nil}.select{|s| not s.nil?} + end + + def handle_sampling(user, params) + method_classes.each do |klass| + klass.new(self).handle_user_interaction(user, params) + end end def render_sampling(user) - # TODO + require 'set' + html = '' + + method_classes.each do |klass| + html += '<div>' + html += klass.new(self).render_user_interaction(user) + html += '</div>' + end + + return html.html_safe end - def finished? - # TODO + private + def figure_sampling_methods + if @sampling_methods.nil? + data = {} + needed = self.tournament_stage.scoring.stats_needed + methods_names = self.tournament_stage.tournament.sampling_methods + methods_names.each do |method_name| + method_class = "Sampling::#{sampling_name.camelcase}".constantize + if method_class.works_with(self.tournament_stage.tournament.game) + needed.each do |stat| + data[stat] ||= {} + data[stat][method] = method.can_get?(user, stat) + end + end + end + + needed.each do |stat| + max_val = nil + max_pri = 0 + data[stat].each do |method,priority| + if priority > max_pri + max_val = method + max_pri = priority + end + end + data[stat] = max_val + end + @sampling_methods = data + end + return @sampling_methods end + + def method_classes + if @method_classes.nil? + data = Set.new + figure_sampling_methods.each do |stat,method| + data.push(method) + end + @method_classes = data + end + return @method_classes + end + end |