summaryrefslogtreecommitdiff
path: root/lib/scoring
diff options
context:
space:
mode:
Diffstat (limited to 'lib/scoring')
-rw-r--r--lib/scoring/README.md15
-rw-r--r--lib/scoring/fibonacci_peer_with_blowout.rb33
-rw-r--r--lib/scoring/marginal_peer.rb16
-rw-r--r--lib/scoring/winner_takes_all.rb16
4 files changed, 80 insertions, 0 deletions
diff --git a/lib/scoring/README.md b/lib/scoring/README.md
new file mode 100644
index 0000000..efdc3cc
--- /dev/null
+++ b/lib/scoring/README.md
@@ -0,0 +1,15 @@
+Scoring interface
+=================
+
+Files in this directory should be _modules_ implementing the following
+interface:
+
+ - `stats_needed(Match) => Array[]=String`
+
+ Returns which statistics need to be collected for this scoring
+ algorithm.
+
+ - `score(Match) => Hash[User]=Integer`
+
+ User scores for this match, assuming statistics have been
+ collected.
diff --git a/lib/scoring/fibonacci_peer_with_blowout.rb b/lib/scoring/fibonacci_peer_with_blowout.rb
new file mode 100644
index 0000000..a13d76c
--- /dev/null
+++ b/lib/scoring/fibonacci_peer_with_blowout.rb
@@ -0,0 +1,33 @@
+module Scoring
+ module FibonacciPeerWithBlowout
+ def self.stats_needed(match)
+ return ["votes", "win", "blowout"] + match.users.map{|u|"review_from_#{u.user_name}"}
+ end
+
+ def self.score(match)
+ scores = {}
+ match.users.each do |user|
+ stats = user.statistics.where(match: match)
+ votes = 0
+ match.users.each do |u|
+ votes += convert_place_to_votes stats.where(name: "review_from_#{u.user_name}").first.value
+ end
+ win = stats.where(name: "win" ).first.value
+ blowout = stats.where(name: "blowout").first.value
+ scores[user] = self.score_user(votes, win, blowout)
+ end
+ scores
+ end
+
+ protected
+
+ def self.score_user(votes, win, blowout)
+ fibonacci = Hash.new { |h,k| h[k] = k < 2 ? k : h[k-1] + h[k-2] }
+ fibonacci[votes+3] + (win ? blowout ? 12 : 10 : blowout ? 5 : 7)
+ end
+
+ def self.convert_place_to_votes(place)
+ (place == 0 or place == 1) ? 1 : 0
+ end
+ end
+end
diff --git a/lib/scoring/marginal_peer.rb b/lib/scoring/marginal_peer.rb
new file mode 100644
index 0000000..f2c0272
--- /dev/null
+++ b/lib/scoring/marginal_peer.rb
@@ -0,0 +1,16 @@
+module Scoring
+ module MarginalPeer
+ def self.stats_needed(match)
+ return ["rating", "win"]
+ end
+
+ def self.score(match)
+ scores = {}
+ match.users.each do |user|
+ stats = Statistic.where(user: user, match: match)
+ scores[user] = stats.where(name: "rating").first.value
+ end
+ scores
+ end
+ end
+end
diff --git a/lib/scoring/winner_takes_all.rb b/lib/scoring/winner_takes_all.rb
new file mode 100644
index 0000000..6cffb28
--- /dev/null
+++ b/lib/scoring/winner_takes_all.rb
@@ -0,0 +1,16 @@
+module Scoring
+ module WinnerTakesAll
+ def self.stats_needed(match)
+ return ["win"]
+ end
+
+ def self.score(match)
+ scores = {}
+ match.users.each do |user|
+ stats = Statistic.where(user: user, match: match)
+ scores[user] = stats.where(name: "win").first.value ? 1 : 0
+ end
+ scores
+ end
+ end
+end