From 1512dfafba22473830118db37a55ef42ed2bd0d7 Mon Sep 17 00:00:00 2001 From: AndrewMurrell Date: Sat, 19 Apr 2014 23:05:44 -0400 Subject: Added ScoringAlgorithms to lib --- lib/scoring_algorithms/Recommended.rb | 8 ++++++++ lib/scoring_algorithms/ScoringAlgorithm.rb | 6 ++++++ 2 files changed, 14 insertions(+) create mode 100644 lib/scoring_algorithms/Recommended.rb create mode 100644 lib/scoring_algorithms/ScoringAlgorithm.rb (limited to 'lib/scoring_algorithms') diff --git a/lib/scoring_algorithms/Recommended.rb b/lib/scoring_algorithms/Recommended.rb new file mode 100644 index 0000000..c871fd4 --- /dev/null +++ b/lib/scoring_algorithms/Recommended.rb @@ -0,0 +1,8 @@ +class Recommended #< ScoringAlgorithm + def self.score(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 +end + +#puts Recommended.score(4, true, false) diff --git a/lib/scoring_algorithms/ScoringAlgorithm.rb b/lib/scoring_algorithms/ScoringAlgorithm.rb new file mode 100644 index 0000000..ab7c81b --- /dev/null +++ b/lib/scoring_algorithms/ScoringAlgorithm.rb @@ -0,0 +1,6 @@ +class ScoringAlgorithm + + def score(*args) + end + +end -- cgit v1.2.3-2-g168b From 4a492f3036ad05718e16289436f9840b4fa5331e Mon Sep 17 00:00:00 2001 From: AndrewMurrell Date: Sat, 19 Apr 2014 23:31:43 -0400 Subject: Added some more scoring functions in ScoringAlgorithms.rb --- lib/scoring_algorithms/Recommended.rb | 2 +- lib/scoring_algorithms/ScoringAlgorithm.rb | 6 ------ lib/scoring_algorithms/ScoringAlgorithms.rb | 28 ++++++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 7 deletions(-) delete mode 100644 lib/scoring_algorithms/ScoringAlgorithm.rb create mode 100644 lib/scoring_algorithms/ScoringAlgorithms.rb (limited to 'lib/scoring_algorithms') diff --git a/lib/scoring_algorithms/Recommended.rb b/lib/scoring_algorithms/Recommended.rb index c871fd4..8033bd2 100644 --- a/lib/scoring_algorithms/Recommended.rb +++ b/lib/scoring_algorithms/Recommended.rb @@ -1,4 +1,4 @@ -class Recommended #< ScoringAlgorithm +class Recommended def self.score(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) diff --git a/lib/scoring_algorithms/ScoringAlgorithm.rb b/lib/scoring_algorithms/ScoringAlgorithm.rb deleted file mode 100644 index ab7c81b..0000000 --- a/lib/scoring_algorithms/ScoringAlgorithm.rb +++ /dev/null @@ -1,6 +0,0 @@ -class ScoringAlgorithm - - def score(*args) - end - -end diff --git a/lib/scoring_algorithms/ScoringAlgorithms.rb b/lib/scoring_algorithms/ScoringAlgorithms.rb new file mode 100644 index 0000000..7f8ec12 --- /dev/null +++ b/lib/scoring_algorithms/ScoringAlgorithms.rb @@ -0,0 +1,28 @@ +class ScoringAlgorithm + def self.score(*args) + end +end + +class FibonacciPeerWithBlowout < ScoringAlgorithm + def self.score(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 +end + +class WinnerTakesAll < ScoringAlgorithm + def self.score(win) + win.nil? ? 0.5 : win ? 1 : 0 + end +end + +class MarginalPeer < ScoringAlgorithm + def self.score(rating) + rating + end +end + + +#puts Recommended.score(4, true, false) +#puts WinnerTakesAll.score(nil) +#puts WinnerTakesAll.score(true) -- cgit v1.2.3-2-g168b