From f461002bef30b7bc1751917ab388be8d4eab37d8 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 29 Apr 2014 08:30:55 -0400 Subject: fix scoring (mostly... I managed to get a 500 while refreshing) --- app/models/remote_username.rb | 2 +- app/models/statistic.rb | 19 ++++++++++++------- app/views/matches/show.html.erb | 14 +++++++++++--- lib/sampling/riot_api.rb | 2 +- lib/scoring/fibonacci_peer_with_blowout.rb | 15 +++++++-------- lib/scoring/marginal_peer.rb | 9 +++++---- lib/scoring/winner_takes_all.rb | 10 ++++++---- 7 files changed, 43 insertions(+), 28 deletions(-) diff --git a/app/models/remote_username.rb b/app/models/remote_username.rb index 8c1ce26..c863ede 100644 --- a/app/models/remote_username.rb +++ b/app/models/remote_username.rb @@ -4,7 +4,7 @@ class RemoteUsername < ActiveRecord::Base def value begin - return JSON.parse(self.json_value) + return JSON::restore(self.json_value) rescue return {} end 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 diff --git a/app/views/matches/show.html.erb b/app/views/matches/show.html.erb index bf5518f..8f6f09c 100644 --- a/app/views/matches/show.html.erb +++ b/app/views/matches/show.html.erb @@ -26,14 +26,22 @@

Teams/users