summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/sampling/README.md30
-rw-r--r--lib/sampling/manual.html.erb1
-rw-r--r--lib/sampling/manual.rb21
-rw-r--r--lib/sampling/peer_review.rb20
-rw-r--r--lib/sampling/riot_api.rb35
-rw-r--r--lib/scheduling/README.md4
-rw-r--r--lib/scheduling/round_robin.rb6
-rw-r--r--lib/scoring/README.md4
8 files changed, 73 insertions, 48 deletions
diff --git a/lib/sampling/README.md b/lib/sampling/README.md
index 3d564da..e4b3fbf 100644
--- a/lib/sampling/README.md
+++ b/lib/sampling/README.md
@@ -1,42 +1,50 @@
Sampling interface
==================
-Files in this directory should be _modules_ implementing the following
+Files in this directory should be _classes_ implementing the following
interface:
- - `works_with?(Game) => Boolean`
+ - `self.works_with?(Game) => Boolean`
Returns whether or not this sampling method works with the
specified game.
- - `can_get?(User, String setting_name) => Fixnum`
+ - `self.can_get?(String setting_name) => Fixnum`
Returns whether or not this sampling method can get a specifed
statistic; 0 means 'false', positive integers mean 'true', where
higher numbers are higher priority.
- - `uses_remote?() => Boolean`
+ - `self.uses_remote?() => Boolean`
Return whether or not this sampling method requires remote IDs for
users.
- - `set_remote_name(User, Game, String)`
+
+ - `self.set_remote_name(User, Game, String)`
Set the remote ID for a user for the specified game. It is safe to
assume that this sampling method `works_with?` that game.
- - `get_remote_name(Object)`
+
+ - `self.get_remote_name(Object)`
When given an object from `RemoteUsername#value`, give back a
- human-readable/editable name to display.
+ human-readable/editable name to display
+
+----
+
+ - `initialize(Match)`
+
+ Construct new Sampling object for the specified match.
- - `sampling_start(Match, Array[]={:user=>User,:stat=>String})`
+ - `start()`
- Fetch the statistics for a match.
+ Begin fetching the statistics.
- - `render_user_interaction(Match, User) => String`
+ - `render_user_interaction(User) => String`
Returns HTML to render on a page.
- - `handle_user_interaction(Match, User, Hash params)`
+ - `handle_user_interaction(User, Hash params)`
Handles params from the form generated by
`#user_interaction_render`.
diff --git a/lib/sampling/manual.html.erb b/lib/sampling/manual.html.erb
new file mode 100644
index 0000000..cf873b4
--- /dev/null
+++ b/lib/sampling/manual.html.erb
@@ -0,0 +1 @@
+<!-- TODO -->
diff --git a/lib/sampling/manual.rb b/lib/sampling/manual.rb
index b5c97c4..a190bd2 100644
--- a/lib/sampling/manual.rb
+++ b/lib/sampling/manual.rb
@@ -1,10 +1,10 @@
module Sampling
- module Manual
+ class Manual
def self.works_with?(game)
return true
end
- def can_get?(user, setting_name)
+ def can_get?(setting_name)
return 1
end
@@ -20,12 +20,20 @@ module Sampling
raise "This sampling method doesn't use remote usernames."
end
- def self.sampling_start(match, statistics)
+ ####
+
+ def initialize(match)
+ @match = match
+ end
+
+ def start
# do nothing
end
- def self.render_user_interaction(match, user)
- # TODO
+ def render_user_interaction(user)
+ @current_user = user
+ @users = @match.users
+ @stats = @match.stats_from(self.class)
require 'erb'
erb_filename = File.join(__FILE__.sub(/\.rb$/, '.svg.erb'))
@@ -34,9 +42,8 @@ module Sampling
return erb.result.html_safe
end
- def self.handle_user_interaction(match, user, sampling_params)
+ def handle_user_interaction(user, sampling_params)
# TODO
- #match.statistics.create(user: nil, name: "blowout",
end
end
end
diff --git a/lib/sampling/peer_review.rb b/lib/sampling/peer_review.rb
index 5ae4e81..4577542 100644
--- a/lib/sampling/peer_review.rb
+++ b/lib/sampling/peer_review.rb
@@ -1,9 +1,13 @@
module Sampling
- module PeerReview
+ class PeerReview
def self.works_with?(game)
return true
end
+ def self.can_get?(setting_name)
+ return setting_name.start_with?("feedback_from_")
+ end
+
def self.uses_remote?
return false
end
@@ -16,11 +20,17 @@ module Sampling
raise "This sampling method doesn't use remote usernames."
end
- def self.sampling_start(match)
+ ####
+
+ def initialize(match)
+ @match = match
+ end
+
+ def start
# do nothing
end
- def self.render_user_interaction(match, user)
+ def render_user_interaction(user)
@user = user
@team = get_team(match)
@feedbacks_missing = get_feedbacks_missing(match)
@@ -32,11 +42,11 @@ module Sampling
return erb.result.html_safe
end
- def self.handle_user_interaction(match, reviewing_user, params)
+ def handle_user_interaction(reviewing_user, params)
i = 0
params[:peer_review].to_s.split(',').each do |user_name|
reviewed_user = User.find_by_user_name(user_name)
- user.statistics.create(match: match, value: i)
+ user.statistics.create(match: @match, value: i)
i += 1
end
end
diff --git a/lib/sampling/riot_api.rb b/lib/sampling/riot_api.rb
index 8c34fc4..7e14551 100644
--- a/lib/sampling/riot_api.rb
+++ b/lib/sampling/riot_api.rb
@@ -1,5 +1,5 @@
module Sampling
- module RiotApi
+ class RiotApi
protected
def self.api_name
"prod.api.pvp.net/api/lol"
@@ -87,21 +87,12 @@ module Sampling
# Return whether or not the API can get a given statistic for
# a given user.
public
- def self.can_get?(user, stat)
- if user.nil?
+ def self.can_get?(stat)
+ if stats_available.include?(stat)
+ return 2
+ else
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
##
@@ -149,13 +140,20 @@ module Sampling
data["name"]
end
+ ####
+
+ public
+ def initialize(match)
+ @match = match
+ end
+
##
# Fetch all the statistics for a match.
public
- def self.sampling_start(match, stats)
+ def start
@match.teams.each do |team|
team.users.each do |user|
- Delayed::Job.enqueue(MatchJob.new(user, match, stats.map{|stat|stat[:name]}, nil), :queue => api_name)
+ Delayed::Job.enqueue(MatchJob.new(user, @match, @match.stats_from(self.class), nil), :queue => api_name)
end
end
end
@@ -191,12 +189,13 @@ module Sampling
end
public
- def self.render_user_interaction(match, user)
+ def render_user_interaction(user)
return ""
end
public
- def self.handle_user_interaction(match, user)
+ def handle_user_interaction(user)
+ # do nothing
end
end
end
diff --git a/lib/scheduling/README.md b/lib/scheduling/README.md
index 8b21164..fe6aba1 100644
--- a/lib/scheduling/README.md
+++ b/lib/scheduling/README.md
@@ -4,7 +4,7 @@ Scheduling interface
Files in this directory should be _classes_ implementing the following
interface:
- - `initialize(tournament_stage)`
+ - `initialize(TournamentStage)`
Construct new Scheduling object from tournament_stage.
@@ -12,7 +12,7 @@ interface:
Creates all the matches of the current round.
- - `finish_match(match)`
+ - `finish_match(Match)`
Progresses the match through the schedule.
diff --git a/lib/scheduling/round_robin.rb b/lib/scheduling/round_robin.rb
index 0cbddc1..f2e4144 100644
--- a/lib/scheduling/round_robin.rb
+++ b/lib/scheduling/round_robin.rb
@@ -9,7 +9,7 @@ module Scheduling
def create_matches
# => find the number of matches and teams to create
@num_teams = (tournament.players.count/tournament.min_players_per_team).floor
- @matches_per_round = num_teams * tournament.min_teams_per_match
+ @matches_per_round = @num_teams * tournament.min_teams_per_match
# => initialize data and status members
@team_pairs ||= {}
@@ -18,13 +18,13 @@ module Scheduling
end
# => Create new matches
- @matches_per_round.each do |match|
+ @matches_per_round.times do
tournament_stage.matches.create(status: 0, submitted_peer_evaluations: 0)
end
# => seed the first time
if @team_pairs.empty?
- tournament_stage.seeding.seed_matches(tournament_stage)
+ tournament_stage.seeding.seed(tournament_stage)
tournament_stage.matches.each {|match| match.teams.each {|team| @team_pairs += team}}
else
# => Reorder the list of teams
diff --git a/lib/scoring/README.md b/lib/scoring/README.md
index 5beb0a2..dce71d0 100644
--- a/lib/scoring/README.md
+++ b/lib/scoring/README.md
@@ -4,12 +4,12 @@ Scoring interface
Files in this directory should be _modules_ implementing the following
interface:
- - `stats_needed() => Array[i]=Symbol`
+ - `stats_needed(Match) => Array[]=Symbol`
Returns which statistics need to be collected for this scoring
algorithm.
- - `score(match) => Hash[User]=Integer`
+ - `score(Match) => Hash[User]=Integer`
User scores for this match, assuming statistics have been
collected.