From 41e2a181bac54c965ef2bf7181289c21a83883f6 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 22 Apr 2014 17:05:06 -0400 Subject: I HATE CODE --- lib/scheduling/elimination.rb | 80 +++++++++++++++++++++++++++++++++++--- lib/scheduling/elimination.svg.erb | 72 ---------------------------------- 2 files changed, 74 insertions(+), 78 deletions(-) delete mode 100644 lib/scheduling/elimination.svg.erb (limited to 'lib') diff --git a/lib/scheduling/elimination.rb b/lib/scheduling/elimination.rb index 519d08a..e718d54 100644 --- a/lib/scheduling/elimination.rb +++ b/lib/scheduling/elimination.rb @@ -43,13 +43,81 @@ module Scheduling end def graph - require 'erb' - erb_filename = File.join(File.dirname(__FILE__), 'elimination.svg.erb') + matches = @tournament_stage.matches_ordered + # depth of SVG tree + depth = Math.log2(matches.count).floor+1; + # height of SVG + height = [200 * 2**Math.log2(matches.count).floor + 100, 500].max; + lastrx = 0 + lastry = 0 + lastrh = 0 + lastrw = 0 - erb = ERB.new(File.read(erb_filename)) - erb.filename = erb_filename - return erb.result - end + str = <<-STRING + + + + + + + +STRING + (1..matches.count).each do |i| + rh = 100/(2**(depth-1)+1) - 5 + rw = 100/(depth+1) - 5 + 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\t\n" + if matches[i].teams.first + str += '\t\tTeam #{matches[i].teams.first.id}\n' + end + + str += "\t\t VS \n" + + 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" + end + + if i > 1 + str += "\t\t\n" + end + if Math.log2(i+1) == Math.log2(i+1).ceil + lastrx = rx + lastry = ry + lastrh = rh + lastrw = rw + end + str += "\n" + end + str += '' + + return str + end end end diff --git a/lib/scheduling/elimination.svg.erb b/lib/scheduling/elimination.svg.erb deleted file mode 100644 index 91b8f6a..0000000 --- a/lib/scheduling/elimination.svg.erb +++ /dev/null @@ -1,72 +0,0 @@ -<% - -matches = @tournament_stage.matches_ordered -# depth of SVG tree -depth = Math.log2(matches.count).floor+1; -# height of SVG -height = 200 * 2**Math.log2(matches.count).floor + 100; -lastrx = 0 -lastry = 0 -lastrh = 0 -lastrw = 0 - -%> - <% %> - - - - - - - <% (1..matches.count).each do |i| %> - - - <% when 0 %> - <% if matches[i-1].teams.count < @tournament_stage.tournament.min_teams_per_match %> - stroke="red" - fill-opacity="0.6" - <% else %> - stroke="green" - <% end %> - <% when 1 %> - stroke="orange" - <% when 2 %> - stroke="yellow" - <% when 3 %> - stroke="grey" - <% end %> /> - " /> - - <% if matches[i-1].teams.first %> - Team <%= matches[i-1].teams.first.id %> - <% end %> - - VS - " /> - - <% if matches[i-1].teams[1] %> - Team <%= matches[i-1].teams[1].id %> - <% end %> - - <% if i > 1 %> - - <% end %> - <% if Math.log2(i+1) == Math.log2(i+1).ceil %> - <% lastrx = rx - lastry = ry - lastrh = rh - lastrw = rw %> - <% end %> - - <% end %> - -- cgit v1.2.3-54-g00ecf From 72c938c505e6c159d824c6d555779fe1a9eba071 Mon Sep 17 00:00:00 2001 From: AndrewMurrell Date: Tue, 22 Apr 2014 17:33:02 -0400 Subject: Added all the folders to lib --- lib/scoring/.FibonacciPeerWithBlowout.rb.swp | Bin 0 -> 12288 bytes lib/scoring/FibonacciPeerWithBlowout.rb | 16 ++++++++++++++++ lib/scoring/MarginalPeer.rb | 15 +++++++++++++++ lib/scoring/ScoringAlgorithm.rb | 8 ++++++++ lib/scoring/WinnerTakesAll.rb | 16 ++++++++++++++++ lib/scoring_algorithms/FibonacciPeerWithBlowout.rb | 16 ---------------- lib/scoring_algorithms/MarginalPeer.rb | 15 --------------- lib/scoring_algorithms/ScoringAlgorithm.rb | 8 -------- lib/scoring_algorithms/WinnerTakesAll.rb | 16 ---------------- 9 files changed, 55 insertions(+), 55 deletions(-) create mode 100644 lib/scoring/.FibonacciPeerWithBlowout.rb.swp create mode 100644 lib/scoring/FibonacciPeerWithBlowout.rb create mode 100644 lib/scoring/MarginalPeer.rb create mode 100644 lib/scoring/ScoringAlgorithm.rb create mode 100644 lib/scoring/WinnerTakesAll.rb delete mode 100644 lib/scoring_algorithms/FibonacciPeerWithBlowout.rb delete mode 100644 lib/scoring_algorithms/MarginalPeer.rb delete mode 100644 lib/scoring_algorithms/ScoringAlgorithm.rb delete mode 100644 lib/scoring_algorithms/WinnerTakesAll.rb (limited to 'lib') diff --git a/lib/scoring/.FibonacciPeerWithBlowout.rb.swp b/lib/scoring/.FibonacciPeerWithBlowout.rb.swp new file mode 100644 index 0000000..49504ab Binary files /dev/null and b/lib/scoring/.FibonacciPeerWithBlowout.rb.swp differ diff --git a/lib/scoring/FibonacciPeerWithBlowout.rb b/lib/scoring/FibonacciPeerWithBlowout.rb new file mode 100644 index 0000000..19ac9a7 --- /dev/null +++ b/lib/scoring/FibonacciPeerWithBlowout.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/MarginalPeer.rb b/lib/scoring/MarginalPeer.rb new file mode 100644 index 0000000..0e1cfa8 --- /dev/null +++ b/lib/scoring/MarginalPeer.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/ScoringAlgorithm.rb b/lib/scoring/ScoringAlgorithm.rb new file mode 100644 index 0000000..6277da8 --- /dev/null +++ b/lib/scoring/ScoringAlgorithm.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/WinnerTakesAll.rb b/lib/scoring/WinnerTakesAll.rb new file mode 100644 index 0000000..ad2471b --- /dev/null +++ b/lib/scoring/WinnerTakesAll.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 diff --git a/lib/scoring_algorithms/FibonacciPeerWithBlowout.rb b/lib/scoring_algorithms/FibonacciPeerWithBlowout.rb deleted file mode 100644 index 19ac9a7..0000000 --- a/lib/scoring_algorithms/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_algorithms/MarginalPeer.rb b/lib/scoring_algorithms/MarginalPeer.rb deleted file mode 100644 index 0e1cfa8..0000000 --- a/lib/scoring_algorithms/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_algorithms/ScoringAlgorithm.rb b/lib/scoring_algorithms/ScoringAlgorithm.rb deleted file mode 100644 index 6277da8..0000000 --- a/lib/scoring_algorithms/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_algorithms/WinnerTakesAll.rb b/lib/scoring_algorithms/WinnerTakesAll.rb deleted file mode 100644 index ad2471b..0000000 --- a/lib/scoring_algorithms/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 -- cgit v1.2.3-54-g00ecf From 241fced528cecfc4c181c24b3563d56d81bf44a9 Mon Sep 17 00:00:00 2001 From: AndrewMurrell Date: Tue, 22 Apr 2014 17:39:11 -0400 Subject: Added default PairingAlgorithm --- lib/pairing/PairingAlgorithm.rb | 6 ++++++ lib/playing/.keep | 0 2 files changed, 6 insertions(+) create mode 100644 lib/pairing/PairingAlgorithm.rb create mode 100644 lib/playing/.keep (limited to 'lib') diff --git a/lib/pairing/PairingAlgorithm.rb b/lib/pairing/PairingAlgorithm.rb new file mode 100644 index 0000000..778e2ae --- /dev/null +++ b/lib/pairing/PairingAlgorithm.rb @@ -0,0 +1,6 @@ +module Leaguer + class PairingAlgorithm + def pair(matches, players) + end + end +end diff --git a/lib/playing/.keep b/lib/playing/.keep new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3-54-g00ecf From 42aa0fe7fdfc51f79cda90c4d71621a797995a6c Mon Sep 17 00:00:00 2001 From: guntasgrewal Date: Tue, 22 Apr 2014 17:41:11 -0400 Subject: Did a thing --- lib/pairing/PairingAlgorithm.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pairing/PairingAlgorithm.rb b/lib/pairing/PairingAlgorithm.rb index 778e2ae..c3d7f7b 100644 --- a/lib/pairing/PairingAlgorithm.rb +++ b/lib/pairing/PairingAlgorithm.rb @@ -1,6 +1,6 @@ module Leaguer class PairingAlgorithm - def pair(matches, players) + def self.pair(matches, players) end end end -- cgit v1.2.3-54-g00ecf