summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrewMurrell <amurrel@purdue.edu>2014-04-28 00:37:19 -0400
committerAndrewMurrell <amurrel@purdue.edu>2014-04-28 00:37:19 -0400
commit9a8d183f6896a92b84a15599323b32e73b5868b9 (patch)
tree9b9009dca4526b227448f940ff46c73a649d5849
parentaedb959b027e10290a344495b28047437c28e1aa (diff)
parentfa8ec3d1e21de1456af74d411117a1b9d5e0bbc0 (diff)
Merge branch 'master' of http://github.com/LukeShu/leaguer
-rw-r--r--app/assets/javascripts/pms/show.js.coffee25
-rw-r--r--app/models/match.rb63
2 files changed, 82 insertions, 6 deletions
diff --git a/app/assets/javascripts/pms/show.js.coffee b/app/assets/javascripts/pms/show.js.coffee
index e69de29..559513c 100644
--- a/app/assets/javascripts/pms/show.js.coffee
+++ b/app/assets/javascripts/pms/show.js.coffee
@@ -0,0 +1,25 @@
+json_url = window.location.href.replace(/\.[^/]*$/,'')+".json"
+
+page_visited_pms = false
+starting_size_pms = 0
+update = (pms) ->
+ if !page_visited_pms
+ starting_size_pms = pms.conversation.count_messages
+ page_visited_pms = true
+
+ if pms.convesation.count_messages > starting_size_pms
+ window.location.reload true
+ return
+
+ console.log("hey we got here!")
+ console.log(starting_size_pms)
+ console.log(pms.convesation.count_messages)
+
+ setTimeout (->
+ $.ajax(url: json_url).done update
+ return
+ ), 2000
+
+# Now kick off the whole process
+window.onload = ->
+ $.ajax(url: json_url).done update \ No newline at end of file
diff --git a/app/models/match.rb b/app/models/match.rb
index fa15980..3cbe0da 100644
--- a/app/models/match.rb
+++ b/app/models/match.rb
@@ -27,18 +27,69 @@ class Match < ActiveRecord::Base
end
def stats_from(sampling_class)
- # TODO
+ figure_sampling_methods.map{|stat,klass| (sampling_class==klass) ? stat : nil}.select{|s| not s.nil?}
end
- def handle_sampling(params)
- # TODO
+ 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