From 105612b151eced803238a24180c29f92e9685dc8 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 27 Apr 2014 22:11:45 -0400 Subject: riot_api: add detecting when a match is done --- lib/sampling/riot_api.rb | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/sampling/riot_api.rb b/lib/sampling/riot_api.rb index d5e9c72..677749b 100644 --- a/lib/sampling/riot_api.rb +++ b/lib/sampling/riot_api.rb @@ -129,27 +129,37 @@ module Sampling def self.sampling_start(match) @match.teams.each do |team| team.users.each do |user| - Delayed::Job.enqueue(MatchJob.new(user, match), :queue => api_name) + Delayed::Job.enqueue(MatchJob.new(user, match, nil), :queue => api_name) end end end protected class FetchStatisticsJob < Job - def initialize(user, match) + def initialize(user, match, last_game_id) @user_id = user.id @match_id = match.id + @last_game_id = last_game_id + # Get the summoner id summoner = user.get_remote_username(match.tournament_stage.tournament.game) - if summoner.nil? - raise "Someone didn't enter their summoner name" - end # Generate the request super("v1.3/game/by-summoner/%{summonerId}/recent", { :summonerId => summoner["id"] }) end def handle(data) user = User.find(@user_id) match = Match.find(@match_id) - Statistic.create(user: user, match: match, value: TODO) + if @last_game_id.nil? + Delayed::Job.enqueue(MatchJob.new(user, match, data["games"][0]["gameId"]), :queue => api_name) + else + if @last_game_id == data["games"][0]["gameId"] + # TODO: perhaps insert a delay here? + Delayed::Job.enqueue(MatchJob.new(user, match, @last_game_id), :queue => api_name) + else + for stat in ["win", "numDeaths", "turretsKilled", "championsKilled", "minionsKilled", "assists"] do + Statistic.create(user: user, match: match, name: stat, value: data["games"][0]["stats"][stat]) + end + end + end end end -- cgit v1.2.3 From 049637ce9ac37f807234e0f679e9da6dba48767a Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 27 Apr 2014 22:24:08 -0400 Subject: dissable sampling/double_blind --- lib/sampling/double_blind.rb | 35 ----------------------------------- lib/sampling/double_blind.rb.bak | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 35 deletions(-) delete mode 100644 lib/sampling/double_blind.rb create mode 100644 lib/sampling/double_blind.rb.bak (limited to 'lib') diff --git a/lib/sampling/double_blind.rb b/lib/sampling/double_blind.rb deleted file mode 100644 index 409da10..0000000 --- a/lib/sampling/double_blind.rb +++ /dev/null @@ -1,35 +0,0 @@ -module Sampling - module DoubleBlind - def self.works_with?(game) - return true - end - - def self.uses_remote? - return false - end - - def self.set_remote_name(user, game, value) - raise "This sampling method doesn't use remote usernames." - end - - def self.get_remote_name(value) - raise "This sampling method doesn't use remote usernames." - end - - def self.sampling_start(match) - # TODO - end - - def self.sampling_done?(match) - # TODO - end - - def self.render_user_interaction(match, user) - # TODO - end - - def self.handle_user_interaction(match, user, sampling_params) - # TODO - end - end -end diff --git a/lib/sampling/double_blind.rb.bak b/lib/sampling/double_blind.rb.bak new file mode 100644 index 0000000..6a30d57 --- /dev/null +++ b/lib/sampling/double_blind.rb.bak @@ -0,0 +1,35 @@ +module Sampling + module DoubleBlind + def self.works_with?(game) + return true + end + + def can_get?(setting_name) + return 1 + end + + def self.uses_remote? + return false + end + + def self.set_remote_name(user, game, value) + raise "This sampling method doesn't use remote usernames." + end + + def self.get_remote_name(value) + raise "This sampling method doesn't use remote usernames." + end + + def self.sampling_start(match, statistics) + # TODO + end + + def self.render_user_interaction(match, user) + # TODO + end + + def self.handle_user_interaction(match, user, sampling_params) + # TODO + end + end +end -- cgit v1.2.3 From 35674c86626981a990e9cbcc3e95a23c5cf61356 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 27 Apr 2014 22:25:05 -0400 Subject: (incomplete) re-jigger the sampling interface --- lib/sampling/README.md | 13 +++++++------ lib/sampling/manual.rb | 18 ++++++++++++------ lib/sampling/peer_review.rb | 4 ---- 3 files changed, 19 insertions(+), 16 deletions(-) (limited to 'lib') diff --git a/lib/sampling/README.md b/lib/sampling/README.md index 731f1d1..bde84cd 100644 --- a/lib/sampling/README.md +++ b/lib/sampling/README.md @@ -9,6 +9,12 @@ interface: Returns whether or not this sampling method works with the specified game. + - `can_get?(User, String setting_name) => Fixnum` + + Returns whether or nat this sampling method can get a specifed + statistic; 0 means 'false', positive integers mean 'true', where + higher numbers are higher priority. + - `uses_remote?() => Boolean` Return whether or not this sampling method requires remote IDs for @@ -22,15 +28,10 @@ interface: When given an object from `RemoteUsername#value`, give back a human-readable/editable name to display. - - `sampling_start(Match)` + - `sampling_start(Match, Array[]={:user=>User,:stat=>String})` Fetch the statistics for a match. - - `sampling_done?(Match) => Boolean` - - Returns whether or not statistics have been completely collected - yet. - - `render_user_interaction(Match, User) => String` Returns HTML to render on a page. diff --git a/lib/sampling/manual.rb b/lib/sampling/manual.rb index a1bf9a5..b5c97c4 100644 --- a/lib/sampling/manual.rb +++ b/lib/sampling/manual.rb @@ -4,6 +4,10 @@ module Sampling return true end + def can_get?(user, setting_name) + return 1 + end + def self.uses_remote? return false end @@ -16,16 +20,18 @@ module Sampling raise "This sampling method doesn't use remote usernames." end - def self.sampling_start(match) - # TODO - end - - def self.sampling_done?(match) - # TODO + def self.sampling_start(match, statistics) + # do nothing end def self.render_user_interaction(match, user) # TODO + + require 'erb' + erb_filename = File.join(__FILE__.sub(/\.rb$/, '.svg.erb')) + erb = ERB.new(File.read(erb_filename)) + erb.filename = erb_filename + return erb.result.html_safe end def self.handle_user_interaction(match, user, sampling_params) diff --git a/lib/sampling/peer_review.rb b/lib/sampling/peer_review.rb index 9f1833d..cbbd2f9 100644 --- a/lib/sampling/peer_review.rb +++ b/lib/sampling/peer_review.rb @@ -20,10 +20,6 @@ module Sampling # do nothing end - def self.sampling_done?(match) - return get_feedbacks_missing(match).empty? - end - def self.render_user_interaction(match, user) @user = user @team = get_team(match) -- cgit v1.2.3 From 7722baf950085f57bd037f918b81440219a56846 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 27 Apr 2014 22:25:26 -0400 Subject: riot_api: update interface, add matchId detection --- lib/sampling/riot_api.rb | 45 +++++++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 12 deletions(-) (limited to 'lib') diff --git a/lib/sampling/riot_api.rb b/lib/sampling/riot_api.rb index 677749b..333095c 100644 --- a/lib/sampling/riot_api.rb +++ b/lib/sampling/riot_api.rb @@ -30,6 +30,11 @@ module Sampling summoner_name.to_s.downcase.gsub(' ', '') end + protected + def self.stats_available + ["win", "numDeaths", "turretsKilled", "championsKilled", "minionsKilled", "assists"] + end + protected class Job < ThrottledApiRequest def initialize(request, args={}) @@ -78,6 +83,26 @@ module Sampling end end + ## + # TODO description + public + def self.can_get?(user, stat) + if user.nil? + return 0 + end + summoner = user.get_remote_username(match.tournament_stage.tournament.game) + if summoner.nil? + return 0 + end + if summoner["id"].nil? + return 0 + end + unless stats_available.include?(stat) + return 0 + end + return 2 + end + ## # This sampling method uses remote IDs public @@ -105,10 +130,10 @@ module Sampling user = User.find(@user_id) game = Game.find(@game_id) - normalized_summoner_name = data.keys.first + standardized_summoner_name = data.keys.first remote_data = { - :id => data[normalized_summoner_name]["id"], - :name => data[normalized_summoner_name]["name"], + :id => data[standardized_summoner_name]["id"], + :name => data[standardized_summoner_name]["name"], } user.set_remote_username(game, remote_data) @@ -126,18 +151,19 @@ module Sampling ## # Fetch all the statistics for a match. public - def self.sampling_start(match) + def self.sampling_start(match, stats) @match.teams.each do |team| team.users.each do |user| - Delayed::Job.enqueue(MatchJob.new(user, match, nil), :queue => api_name) + Delayed::Job.enqueue(MatchJob.new(user, match, stats.map{|stat|stat[:name]}, nil), :queue => api_name) end end end protected class FetchStatisticsJob < Job - def initialize(user, match, last_game_id) + def initialize(user, match, stats, last_game_id) @user_id = user.id @match_id = match.id + @stats = stats @last_game_id = last_game_id # Get the summoner id @@ -155,7 +181,7 @@ module Sampling # TODO: perhaps insert a delay here? Delayed::Job.enqueue(MatchJob.new(user, match, @last_game_id), :queue => api_name) else - for stat in ["win", "numDeaths", "turretsKilled", "championsKilled", "minionsKilled", "assists"] do + @stats.each do |stat| Statistic.create(user: user, match: match, name: stat, value: data["games"][0]["stats"][stat]) end end @@ -163,11 +189,6 @@ module Sampling end end - public - def self.sampling_done?(match) - # TODO - end - public def self.render_user_interaction(match, user) return "" -- cgit v1.2.3