summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/sampling/riot_api.rb15
-rw-r--r--lib/scheduling/elimination.rb5
-rw-r--r--lib/throttled_api_request.rb4
3 files changed, 13 insertions, 11 deletions
diff --git a/lib/sampling/riot_api.rb b/lib/sampling/riot_api.rb
index 7d75475..bbe9cea 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
@@ -62,10 +62,11 @@ module Sampling
if status[0] != "200"
raise "GET #{@url} => #{status.join(" ")}"
end
- self.handle(data)
+ return self.handle(data)
end
def handle(data)
+ return true
end
end
@@ -110,7 +111,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 +159,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
@@ -179,11 +180,11 @@ module Sampling
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])
diff --git a/lib/scheduling/elimination.rb b/lib/scheduling/elimination.rb
index 4518cff..73aefb4 100644
--- a/lib/scheduling/elimination.rb
+++ b/lib/scheduling/elimination.rb
@@ -52,6 +52,7 @@ module Scheduling
# height of SVG
matchHeight = 50*logBase;
height = [(matchHeight+50) * logBase**(depth-1) + 100, 500].max;
+ height = height/2;
str = <<-STRING
<svg version="1.1" baseProfile="full"
@@ -109,10 +110,10 @@ module Scheduling
color = (matches[i].teams[t-1] and matches[i].teams[t-1].users.include?(current_user)) ? "#5BC0DE" : "white"
str += "\t\t<rect width=\"#{rw-5}%\" height=\"#{rh*Float(30)/(matchHeight)}%\" x=\"#{rx + 2.5}%\" y=\"#{ry + (Float(t-1)/numTeams)*rh + 1 }%\" fill=\"#{color}\" />\n"
if matches[i].teams[t-1]
- str += "\t\t<text x=\"#{rx + rw/4}%\" y=\"#{ry + (Float(t-1)/numTeams + Float(33)/(matchHeight))*rh}%\" font-size=\"200%\">Team #{matches[i].teams[t-1].id}</text>\n"
+ str += "\t\t<text x=\"#{rx + rw/4}%\" y=\"#{ry + (Float(t-1)/numTeams + Float(33)/(matchHeight))*rh}%\" font-size=\"120%\">Team #{matches[i].teams[t-1].id}</text>\n"
end
if (t < numTeams)
- str += "\t\t<text x=\"#{rx + 1.3*rw/3}%\" y=\"#{ry + (Float(t)/numTeams)*rh + 1}%\" font-size=\"200%\"> VS </text>\n"
+ str += "\t\t<text x=\"#{rx + 1.3*rw/3}%\" y=\"#{ry + (Float(t)/numTeams)*rh + 1}%\" font-size=\"120%\"> VS </text>\n"
end
t = t + 1
end
diff --git a/lib/throttled_api_request.rb b/lib/throttled_api_request.rb
index 1020071..c48a66d 100644
--- a/lib/throttled_api_request.rb
+++ b/lib/throttled_api_request.rb
@@ -8,9 +8,9 @@ class ThrottledApiRequest < Struct.new(:api_name, :limits)
loop do
sleep_for = -1
ActiveRecord::Base.transaction do
- ApiRequests.create(:api_name => self.api_name)
+ ApiRequest.create(:api_name => self.api_name)
self.limits.each do |limit|
- recent_requests = ApiRequets.
+ recent_requests = ApiRequest.
where(:api_name => self.api_name).
where("updated_at > ?", Time.now.utc - limit[:unit_time]).
order(:updated_at)