From 7deb9c1c7acadf9a5b638313f51ba9dc60624672 Mon Sep 17 00:00:00 2001 From: AndrewMurrell Date: Tue, 22 Apr 2014 18:17:13 -0400 Subject: made naming conventions consistent --- lib/scoring/FibonacciPeerWithBlowout.rb | 16 ---------------- lib/scoring/MarginalPeer.rb | 15 --------------- lib/scoring/ScoringAlgorithm.rb | 8 -------- lib/scoring/WinnerTakesAll.rb | 16 ---------------- lib/scoring/fibonacci_peer_with_blowout.rb | 16 ++++++++++++++++ lib/scoring/marginal_peer.rb | 15 +++++++++++++++ lib/scoring/scoring_algorithm.rb | 8 ++++++++ lib/scoring/winner_takes_all.rb | 16 ++++++++++++++++ 8 files changed, 55 insertions(+), 55 deletions(-) delete mode 100644 lib/scoring/FibonacciPeerWithBlowout.rb delete mode 100644 lib/scoring/MarginalPeer.rb delete mode 100644 lib/scoring/ScoringAlgorithm.rb delete mode 100644 lib/scoring/WinnerTakesAll.rb create mode 100644 lib/scoring/fibonacci_peer_with_blowout.rb create mode 100644 lib/scoring/marginal_peer.rb create mode 100644 lib/scoring/scoring_algorithm.rb create mode 100644 lib/scoring/winner_takes_all.rb (limited to 'lib') diff --git a/lib/scoring/FibonacciPeerWithBlowout.rb b/lib/scoring/FibonacciPeerWithBlowout.rb deleted file mode 100644 index 19ac9a7..0000000 --- a/lib/scoring/FibonacciPeerWithBlowout.rb +++ /dev/null @@ -1,16 +0,0 @@ -require 'ScoringAlgorithm' - -class FibonacciPeerWithBlowout < ScoringAlgorithm - - def self.score(match, interface) - match.players.each do |player| - scores[player.user_name] = scoreUser(interface.getStatistic(match, player, :votes), match.win?(player), match.blowout) - end - scores - end - - def self.scoreUser(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 \ No newline at end of file diff --git a/lib/scoring/MarginalPeer.rb b/lib/scoring/MarginalPeer.rb deleted file mode 100644 index 0e1cfa8..0000000 --- a/lib/scoring/MarginalPeer.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'ScoringAlgorithm' - -class MarginalPeer < ScoringAlgorithm - - def self.score(match, interface) - match.players.each do |player| - scores[player.user_name] = scoreUser(interface.getStatistic(match, player, rating)) - end - scores - end - - def self.score(rating) - rating - end -end \ No newline at end of file diff --git a/lib/scoring/ScoringAlgorithm.rb b/lib/scoring/ScoringAlgorithm.rb deleted file mode 100644 index 6277da8..0000000 --- a/lib/scoring/ScoringAlgorithm.rb +++ /dev/null @@ -1,8 +0,0 @@ -module Leaguer - module Scoring - class ScoringAlgorithm - def self.score(match, interface) - end - end - end -end \ No newline at end of file diff --git a/lib/scoring/WinnerTakesAll.rb b/lib/scoring/WinnerTakesAll.rb deleted file mode 100644 index ad2471b..0000000 --- a/lib/scoring/WinnerTakesAll.rb +++ /dev/null @@ -1,16 +0,0 @@ -require 'ScoringAlgorithm' - -class WinnerTakesAll < ScoringAlgorithm - - def self.score(match, interface) - match.players.each do |player| - scores[player.user_name] = scoreUser(match.win?(player)) - end - scores - end - - - def self.score(win) - win.nil? ? 0.5 : win ? 1 : 0 - end -end \ No newline at end of file diff --git a/lib/scoring/fibonacci_peer_with_blowout.rb b/lib/scoring/fibonacci_peer_with_blowout.rb new file mode 100644 index 0000000..19ac9a7 --- /dev/null +++ b/lib/scoring/fibonacci_peer_with_blowout.rb @@ -0,0 +1,16 @@ +require 'ScoringAlgorithm' + +class FibonacciPeerWithBlowout < ScoringAlgorithm + + def self.score(match, interface) + match.players.each do |player| + scores[player.user_name] = scoreUser(interface.getStatistic(match, player, :votes), match.win?(player), match.blowout) + end + scores + end + + def self.scoreUser(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 \ No newline at end of file diff --git a/lib/scoring/marginal_peer.rb b/lib/scoring/marginal_peer.rb new file mode 100644 index 0000000..0e1cfa8 --- /dev/null +++ b/lib/scoring/marginal_peer.rb @@ -0,0 +1,15 @@ +require 'ScoringAlgorithm' + +class MarginalPeer < ScoringAlgorithm + + def self.score(match, interface) + match.players.each do |player| + scores[player.user_name] = scoreUser(interface.getStatistic(match, player, rating)) + end + scores + end + + def self.score(rating) + rating + end +end \ No newline at end of file diff --git a/lib/scoring/scoring_algorithm.rb b/lib/scoring/scoring_algorithm.rb new file mode 100644 index 0000000..6277da8 --- /dev/null +++ b/lib/scoring/scoring_algorithm.rb @@ -0,0 +1,8 @@ +module Leaguer + module Scoring + class ScoringAlgorithm + def self.score(match, interface) + end + end + end +end \ No newline at end of file diff --git a/lib/scoring/winner_takes_all.rb b/lib/scoring/winner_takes_all.rb new file mode 100644 index 0000000..ad2471b --- /dev/null +++ b/lib/scoring/winner_takes_all.rb @@ -0,0 +1,16 @@ +require 'ScoringAlgorithm' + +class WinnerTakesAll < ScoringAlgorithm + + def self.score(match, interface) + match.players.each do |player| + scores[player.user_name] = scoreUser(match.win?(player)) + end + scores + end + + + def self.score(win) + win.nil? ? 0.5 : win ? 1 : 0 + end +end \ No newline at end of file -- cgit v1.2.3-2-g168b From b4bc055585dee532653a8c64e45385e085ec22a8 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 22 Apr 2014 18:29:17 -0400 Subject: I hate code --- lib/scheduling/elimination.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/scheduling/elimination.rb b/lib/scheduling/elimination.rb index e718d54..5ce71ca 100644 --- a/lib/scheduling/elimination.rb +++ b/lib/scheduling/elimination.rb @@ -1,5 +1,7 @@ + module Scheduling class Elimination + include Rails.application.routes.url_helpers def initialize(tournament_stage) @tournament_stage = tournament_stage @@ -21,9 +23,9 @@ module Scheduling match_num = num_matches-1 team_num = 0 # for each grouping of min_players_per_team - self.tournament.players.each_slice(min_players_per_team) do |team_members| + self.tournament.players.each_slice(self.tournament.min_players_per_team) do |team_members| # if the match is full, move to the next match, otherwise move to the next team - if (team_num == min_teams_per_match) + if (team_num == self.tournament.min_teams_per_match) match_num -= 1 team_num = 0 else @@ -42,7 +44,7 @@ module Scheduling end end - def graph + def graph(current_user) matches = @tournament_stage.matches_ordered # depth of SVG tree depth = Math.log2(matches.count).floor+1; @@ -71,7 +73,7 @@ STRING rx = 50/(depth+1) + 100/(depth+1)*(depth-(Math.log2(i).floor+1)) ry = ( 100/(2**(Math.log2(i).floor)+1) + rh * 1.1 * (2**Math.log2(i).ceil-i)) - str += "\t\n" + str += "\t\n" str += "\t\t\n" if matches[i].teams.first - str += '\t\tTeam #{matches[i].teams.first.id}\n' + str += "\t\tTeam #{matches[i].teams.first.id}\n" end str += "\t\t VS \n" @@ -113,7 +115,7 @@ STRING lastrh = rh lastrw = rw end - str += "\n" + str += "\n" end str += '' -- cgit v1.2.3-2-g168b From 7bb14aca1a6881e37c4bc6c1bd89fc2f126386db Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 22 Apr 2014 18:33:41 -0400 Subject: fix paren thing --- lib/scheduling/elimination.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/scheduling/elimination.rb b/lib/scheduling/elimination.rb index 5ce71ca..055fdbd 100644 --- a/lib/scheduling/elimination.rb +++ b/lib/scheduling/elimination.rb @@ -92,7 +92,7 @@ STRING end str += "/>\n" - color = matches[i].teams.first and matches[i].teams.first.users.include?(current_user) ? "#BCED91" : "white" + color = (matches[i].teams[0] and matches[i].teams[0].users.include?(current_user)) ? "#BCED91" : "white" str += "\t\t\n" if matches[i].teams.first str += "\t\tTeam #{matches[i].teams.first.id}\n" @@ -100,7 +100,7 @@ STRING str += "\t\t VS \n" - color = matches[i].teams[1] and matches[i].teams[1].users.include?(current_user) ? "#BCED91" : "white" + color = (matches[i].teams[1] and matches[i].teams[1].users.include?(current_user)) ? "#BCED91" : "white" str += "\t\t\n" if matches[i].teams[1] str += "\t\tTeam #{matches[i].teams[1].id}\n" -- cgit v1.2.3-2-g168b