summaryrefslogtreecommitdiff
path: root/app/models/statistic.rb
diff options
context:
space:
mode:
authorLuke Shumaker <shumakl@purdue.edu>2014-04-29 08:30:55 -0400
committerLuke Shumaker <shumakl@purdue.edu>2014-04-29 08:30:55 -0400
commitf461002bef30b7bc1751917ab388be8d4eab37d8 (patch)
tree740fc3d0cdaa11102be221f4fca9bd32f3ab9484 /app/models/statistic.rb
parent284da4d7e5badc0a1ad9dafc52672ab14168c91b (diff)
fix scoring (mostly... I managed to get a 500 while refreshing)
Diffstat (limited to 'app/models/statistic.rb')
-rw-r--r--app/models/statistic.rb19
1 files changed, 12 insertions, 7 deletions
diff --git a/app/models/statistic.rb b/app/models/statistic.rb
index fefa3a8..d62d413 100644
--- a/app/models/statistic.rb
+++ b/app/models/statistic.rb
@@ -2,9 +2,11 @@ class Statistic < ActiveRecord::Base
belongs_to :user
belongs_to :match
+ validates(:name, presence: true, length: { minimum: 1 })
+
def value
begin
- return JSON.parse(self.json_value)
+ return JSON::restore(self.json_value)
rescue
return {}
end
@@ -16,12 +18,15 @@ class Statistic < ActiveRecord::Base
after_save :update_match
def update_match
- if (self.name == "win") and (self.value)
- 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
+ ActiveRecord::Base.transaction do
+ if (self.name == "win") and (self.value)
+ 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.tournament_stage.scoring.score(self.match)
+ self.match.status = 3
+ end
+ self.match.save!
end
- self.match.save
end
end