diff options
author | Luke Shumaker <shumakl@purdue.edu> | 2014-04-29 08:30:55 -0400 |
---|---|---|
committer | Luke Shumaker <shumakl@purdue.edu> | 2014-04-29 08:30:55 -0400 |
commit | f461002bef30b7bc1751917ab388be8d4eab37d8 (patch) | |
tree | 740fc3d0cdaa11102be221f4fca9bd32f3ab9484 | |
parent | 284da4d7e5badc0a1ad9dafc52672ab14168c91b (diff) |
fix scoring (mostly... I managed to get a 500 while refreshing)
-rw-r--r-- | app/models/remote_username.rb | 2 | ||||
-rw-r--r-- | app/models/statistic.rb | 19 | ||||
-rw-r--r-- | app/views/matches/show.html.erb | 14 | ||||
-rw-r--r-- | lib/sampling/riot_api.rb | 2 | ||||
-rw-r--r-- | lib/scoring/fibonacci_peer_with_blowout.rb | 15 | ||||
-rw-r--r-- | lib/scoring/marginal_peer.rb | 9 | ||||
-rw-r--r-- | 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 @@ <div> <h2>Teams/users</h2> <ul> + <% if @match.status == 3 + scores = @match.tournament_stage.scoring.score(@match) + end + %> <% @match.teams.each do |team| %> <li>Team <%= team.id %><ul> <% team.users.each do |user| %> - <% if @match.status <= 1 %> + <% if @match.status < 3 %> <li><%= user.user_name %></li> <% else %> - <% score = user.statistics.where(:name => "score", :match => @match).first %> - <li><%= user.user_name %> - SCORE: <%= score ? score.value : 0 %></li> + <% stats = Statistic.where(user: user, match: @match) %> + <li><%= user.user_name %> - Score: <%= scores[user] %><ul> + <% stats.all.reject{|s|s.name=="score"}.each do |stat| %> + <li><%= stat.name %>: <%= stat.value %></li> + <% end %> + </ul></li> <% end %> <% end %> </ul></li> diff --git a/lib/sampling/riot_api.rb b/lib/sampling/riot_api.rb index bbe9cea..4e72f91 100644 --- a/lib/sampling/riot_api.rb +++ b/lib/sampling/riot_api.rb @@ -49,7 +49,7 @@ module Sampling def perform response = open(@url) status = response.status - data = JSON::parse(response.read) + data = JSON::restore(response.read) # Error codes that RIOT uses: # "400"=>"Bad request" diff --git a/lib/scoring/fibonacci_peer_with_blowout.rb b/lib/scoring/fibonacci_peer_with_blowout.rb index f592540..9d72643 100644 --- a/lib/scoring/fibonacci_peer_with_blowout.rb +++ b/lib/scoring/fibonacci_peer_with_blowout.rb @@ -1,19 +1,18 @@ module Scoring module FibonacciPeerWithBlowout def self.stats_needed - return [:votes, :win, :blowout] + return ["votes", "win", "blowout"] end def self.score(match) scores = {} - match.players.each do |player| - stats = Statistics.where(user: player, match: match) + match.users.each do |user| + stats = Statistic.where(user: user, match: match) - votes = stats.where(name: :votes ).first - win = stats.where(name: :win ).first - blowout = stats.where(name: :blowout).first - - scores[player] = self.score_user(votes, win, blowout) + votes = stats.where(name: "votes" ).first.value + win = stats.where(name: "win" ).first.value + blowout = stats.where(name: "blowout").first.value + scores[user] = self.score_user(votes, win, blowout) end scores end diff --git a/lib/scoring/marginal_peer.rb b/lib/scoring/marginal_peer.rb index aa05f5e..8559b3d 100644 --- a/lib/scoring/marginal_peer.rb +++ b/lib/scoring/marginal_peer.rb @@ -1,13 +1,14 @@ module Scoring module MarginalPeer def self.stats_needed - return [:rating] + return ["rating", "win"] end - def self.score(match, interface) + def self.score(match) scores = {} - match.players.each do |player| - scores[player.user_name] = interface.get_statistic(match, player, :rating) + match.users.each do |user| + stats = Statistic.where(user: user, match: match) + scores[user] = stats.where(name: "rating").first.value end scores end diff --git a/lib/scoring/winner_takes_all.rb b/lib/scoring/winner_takes_all.rb index 57ddae6..9c83fb9 100644 --- a/lib/scoring/winner_takes_all.rb +++ b/lib/scoring/winner_takes_all.rb @@ -1,13 +1,15 @@ module Scoring module WinnerTakesAll def self.stats_needed - return ["win"] + #return ["win"] + ["win", "numDeaths", "turretsKilled", "championsKilled", "minionsKilled", "assists"] end - def self.score(match, interface) + def self.score(match) scores = {} - match.players.each do |player| - scores[player.user_name] = score_user(player.statistics.where(:match => match, :name => "win").value) + match.users.each do |user| + stats = Statistic.where(user: user, match: match) + scores[user] = score_user(stats.where(name: "win").first.value) end scores end |