summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authortkimia <tkimia@purdue.edu>2014-04-28 20:03:34 -0400
committertkimia <tkimia@purdue.edu>2014-04-28 20:03:34 -0400
commit1a6450ec1f5c538eff6dbf6f91582c47fb16e3cc (patch)
treedc1a9455fedb082a3be0bb36ac19aae5cbbe39fd /app/models
parent3992a2e52a950c644cfe56bc23991e3a03166568 (diff)
parent3ab30900798a838b399d06f28251b6cdd82a94de (diff)
Merge branch 'master' of https://github.com/LukeShu/leaguer
Diffstat (limited to 'app/models')
-rw-r--r--app/models/match.rb7
-rw-r--r--app/models/statistic.rb23
2 files changed, 25 insertions, 5 deletions
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/app/models/statistic.rb b/app/models/statistic.rb
index 341fd9d..b4608b8 100644
--- a/app/models/statistic.rb
+++ b/app/models/statistic.rb
@@ -1,4 +1,27 @@
class Statistic < ActiveRecord::Base
belongs_to :user
belongs_to :match
+
+ def value
+ begin
+ return JSON.parse(self.json_value)
+ rescue
+ return {}
+ end
+ end
+
+ def value=(v)
+ self.json_value = v.to_json
+ end
+
+ after_save :update_match
+ def update_match
+ if (self.name == "win") and (self.value > 0)
+ self.match.winner = self.match.teams.find{|t| t.users.include? self.user}
+ end
+ if (self.match.status == 2) and (self.match.finished?)
+ self.match.status = 3
+ end
+ self.match.save
+ end
end