summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortkimia <tkimia@purdue.edu>2014-04-28 22:01:14 -0400
committertkimia <tkimia@purdue.edu>2014-04-28 22:01:14 -0400
commitdd4c9e16c529bdbf0d055b279ed2dadc0c2aae13 (patch)
treeb0c9377df1f11ae626e5bd7057de158301884e0d
parentbc8be5e217279012cd4dc62e3fc2fe2bd9308b1c (diff)
parentd52ceaf8d2b823b68edcf3614999b8639a0971f9 (diff)
Merge branch 'master' of https://github.com/LukeShu/leaguer
-rw-r--r--app/controllers/matches_controller.rb1
-rw-r--r--app/models/match.rb10
-rw-r--r--db/seeds.rb2
-rw-r--r--lib/sampling/manual.html.erb2
-rw-r--r--lib/sampling/manual.rb5
-rw-r--r--lib/sampling/riot_api.rb14
-rw-r--r--lib/throttled_api_request.rb5
7 files changed, 26 insertions, 13 deletions
diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb
index 81ffcd8..d2dc918 100644
--- a/app/controllers/matches_controller.rb
+++ b/app/controllers/matches_controller.rb
@@ -31,6 +31,7 @@ class MatchesController < ApplicationController
# Scheduled, waiting to start
if (@tournament.hosts.include? current_user) and (params[:update_action] == "start")
@match.status = 2
+ @match.start_sampling
respond_to do |format|
if @match.save
format.html { redirect_to tournament_match_path(@tournament, @match), notice: 'Match has started.' }
diff --git a/app/models/match.rb b/app/models/match.rb
index 219e662..85084f5 100644
--- a/app/models/match.rb
+++ b/app/models/match.rb
@@ -7,8 +7,8 @@ class Match < ActiveRecord::Base
def finished?
ok = true
- tournament_stage.scoring_method.stats_needed.each do |stat|
- ok &= statistics.where(match: self, name: stat).nil?
+ tournament_stage.scoring.stats_needed.each do |stat|
+ ok &= !statistics.where(match: self, name: stat).nil?
end
ok
end
@@ -46,6 +46,12 @@ class Match < ActiveRecord::Base
return html.html_safe
end
+ def start_sampling
+ method_classes.each do |klass|
+ klass.new(self).start
+ end
+ end
+
private
def figure_sampling_methods
if @sampling_methods.nil?
diff --git a/db/seeds.rb b/db/seeds.rb
index 7e13f1e..8327e30 100644
--- a/db/seeds.rb
+++ b/db/seeds.rb
@@ -177,7 +177,7 @@ if Rails.env.development?
custom.hosts.push(User.find(1))
- custom.stages.create(scheduling_method: "round_robin" , seeding_method: "early_bird")
+ custom.stages.create(scheduling_method: "round_robin" , seeding_method: "early_bird_seeding")
custom.hosts.push(User.find(1))
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 @@
<input type="hidden" name="update_action" value="finish" >
<% @match.teams.each do |team| %>
<label>
- <input type="radio", name="winner", value="<%= team.id %>" >
+ <input type="radio", name="win", value="<%= team.id %>" >
<%= "Team #{team.id} Won" %>
</label>
<% 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
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
diff --git a/lib/throttled_api_request.rb b/lib/throttled_api_request.rb
index 1020071..b632d1e 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)
@@ -23,6 +23,7 @@ class ThrottledApiRequest < Struct.new(:api_name, :limits)
end
end
if sleep_for != -1
+ puts "sleeping for #{sleeping_for}"
sleep(sleep_for)
else
break