From 8db5113a761d443374a64e5e9fe877fafa3f0a50 Mon Sep 17 00:00:00 2001 From: AndrewMurrell Date: Mon, 28 Apr 2014 21:21:47 -0400 Subject: Fixed status 2-3 transition and statistic sampling. --- lib/sampling/manual.html.erb | 2 +- lib/sampling/manual.rb | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'lib/sampling') diff --git a/lib/sampling/manual.html.erb b/lib/sampling/manual.html.erb index b783506..187f002 100644 --- a/lib/sampling/manual.html.erb +++ b/lib/sampling/manual.html.erb @@ -2,7 +2,7 @@ <% @match.teams.each do |team| %> <% end %> diff --git a/lib/sampling/manual.rb b/lib/sampling/manual.rb index 4e86925..01f6835 100644 --- a/lib/sampling/manual.rb +++ b/lib/sampling/manual.rb @@ -44,7 +44,10 @@ module Sampling end def handle_user_interaction(user, sampling_params) - # TODO + # => Save sampling_params as statistics + sampling_params.select {|name, value| @match.stats_from(self.class).include? name }.each do |name, value| + Statistic.create(name: value, user: user, match: @match) + end end end end -- cgit v1.2.3 From 819fd70c1285bf5670b68842adad8c77c36d1076 Mon Sep 17 00:00:00 2001 From: nfoy Date: Mon, 28 Apr 2014 21:32:04 -0400 Subject: All the changes. Luke should know what's up. --- lib/sampling/riot_api.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'lib/sampling') diff --git a/lib/sampling/riot_api.rb b/lib/sampling/riot_api.rb index 7d75475..18a5ee7 100644 --- a/lib/sampling/riot_api.rb +++ b/lib/sampling/riot_api.rb @@ -17,7 +17,7 @@ module Sampling protected def self.url(request, args={}) - "https://prod.api.pvp.net/api/lol/#{region}/#{request % args.merge(args){|k,v|url_escape(v)}}?#{api_key}" + "https://prod.api.pvp.net/api/lol/#{region}/#{request % args.merge(args){|k,v|url_escape(v)}}?api_key=#{api_key}" end protected @@ -43,7 +43,7 @@ module Sampling {:unit_time => 10.seconds, :requests_per => 10}, {:unit_time => 10.minutes, :requests_per => 500}, ] - super(api_name, limits) + super(RiotApi::api_name, limits) end def perform @@ -110,7 +110,7 @@ module Sampling # When given a summoner name for a user, figure out the summoner ID. public def self.set_remote_name(user, game, summoner_name) - Delayed::Job.enqueue(UsernameJob.new(user, game, summoner_name), :queue => api_name) + Delayed::Job.enqueue(UsernameJob.new(user, game, summoner_name), :queue => RiotApi::api_name) end protected class UsernameJob < Job @@ -158,7 +158,7 @@ module Sampling @match.teams.each do |team| team.users.each do |user| #For demo purposes, we are hard coding in a league of legends game id. - Delayed::Job.enqueue(MatchJob.new(user, @match, @match.stats_from(self.class), 1362730546), :queue => api_name) + Delayed::Job.enqueue(FetchStatisticsJob.new(user, @match, @match.stats_from(self.class), 10546), :queue => RiotApi::api_name) end end end @@ -176,20 +176,22 @@ module Sampling super("v1.3/game/by-summoner/%{summonerId}/recent", { :summonerId => summoner["id"] }) end def handle(data) + puts("handling...") user = User.find(@user_id) match = Match.find(@match_id) if @last_game_id.nil? - Delayed::Job.enqueue(MatchJob.new(user, match, data["games"][0]["gameId"]), :queue => api_name) + Delayed::Job.enqueue(FetchStatisticsJob.new(user, match, data["games"][0]["gameId"]), :queue => RiotApi::api_name) else if @last_game_id == data["games"][0]["gameId"] sleep(4.minutes) - Delayed::Job.enqueue(MatchJob.new(user, match, @last_game_id), :queue => api_name) + Delayed::Job.enqueue(FetchStatisticsJob.new(user, match, @last_game_id), :queue => RiotApi::api_name) else @stats.each do |stat| Statistic.create(user: user, match: match, name: stat, value: data["games"][0]["stats"][stat]) end end end + puts("done handling") end end -- cgit v1.2.3