summaryrefslogtreecommitdiff
path: root/lib/scheduling/elimination.rb
diff options
context:
space:
mode:
authornfoy <nfoy@purdue.edu>2014-04-24 19:03:41 -0400
committernfoy <nfoy@purdue.edu>2014-04-24 19:03:41 -0400
commit1b11684986136ee87da6242c3ba6aba5ef581510 (patch)
treed7ec999baced4836a9b3b7b31eee39cfe09410c9 /lib/scheduling/elimination.rb
parent9823642115ef52f0a21b9466cef412098a124f3d (diff)
parentdb073045ff7cf5d8a2fb4a3349ed6a9a6ac019d3 (diff)
Merge branch 'master' of https://github.com/LukeShu/leaguer
Diffstat (limited to 'lib/scheduling/elimination.rb')
-rw-r--r--lib/scheduling/elimination.rb60
1 files changed, 34 insertions, 26 deletions
diff --git a/lib/scheduling/elimination.rb b/lib/scheduling/elimination.rb
index 1ac696d..cf0d625 100644
--- a/lib/scheduling/elimination.rb
+++ b/lib/scheduling/elimination.rb
@@ -17,7 +17,7 @@ module Scheduling
def create_matches
num_teams = (self.tournament.players.count/self.tournament.min_players_per_team).floor
- num_matches = num_teams - 1
+ num_matches = (Float(num_teams - tournament.min_teams_per_match)/(tournament.min_teams_per_match - 1)).ceil + 1
for i in 1..num_matches
self.tournament_stage.matches.create(status: 0, submitted_peer_evaluations: 0)
end
@@ -32,7 +32,7 @@ module Scheduling
# if the match is full, move to the next match, otherwise move to the next team
if (team_num == self.tournament.min_teams_per_match)
match_num -= 1
- team_num = 0
+ team_num = 1
else
team_num += 1
end
@@ -51,10 +51,16 @@ module Scheduling
def graph(current_user)
matches = @tournament_stage.matches_ordered
+ numTeams = @tournament_stage.tournament.min_teams_per_match
+ logBase = numTeams
+
# depth of SVG tree
- depth = Math.log2(matches.count).floor+1;
+ depth = Math.log(matches.count*(logBase-1),logBase).floor+1;
+
# height of SVG
- height = [200 * 2**Math.log2(matches.count).floor + 100, 500].max;
+ matchHeight = 50*logBase;
+ height = [(matchHeight+50) * logBase**(depth-1) + 100, 500].max;
+
lastrx = 0
lastry = 0
lastrh = 0
@@ -73,10 +79,12 @@ module Scheduling
</defs>
STRING
(1..matches.count).each do |i|
- rh = 100/(2**(depth-1)+1) - 5
+ matchDepth = Math.log(i*(logBase-1), logBase).floor+1
+ base = (logBase**(matchDepth-1)/(logBase-1)).ceil
+ rh = 100 / (logBase**(depth-1)+1) - 100/height;
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))
+ rx = 50/(depth+1) + 100/(depth+1)*(depth-matchDepth)
+ ry = 100/(logBase**(matchDepth-1)+1) * (i-base+1) - rh/2
str += "\t<a id=\"svg-match-#{i}\" xlink:href=\"#{match_path(matches[i])}\"><g>\n"
str += "\t\t<rect height=\"#{rh}%\" width=\"#{rw}%\" x=\"#{rx}%\" y=\"#{ry}%\" fill=\"url(#gradMatch)\" rx=\"5px\" stroke-width=\"2\""
@@ -95,30 +103,29 @@ STRING
when 3
str += ' stroke="grey"'
end
- str += "/>\n"
- color = (matches[i].teams[0] and matches[i].teams[0].users.include?(current_user)) ? "#BCED91" : "white"
- str += "\t\t<rect width=\"#{rw-5}%\" height=\"#{rh/4}%\" x=\"#{rx + 2.5}%\" y=\"#{ry + rh/6}%\" fill=\"#{color}\" />\n"
- if matches[i].teams.first
- str += "\t\t<text x=\"#{rx + rw/4}%\" y=\"#{ry + rh/3}%\" font-size=\"#{rh}\">Team #{matches[i].teams.first.id}</text>\n"
- end
-
- str += "\t\t<text x=\"#{rx + 1.3*rw/3}%\" y=\"#{ry + 5.2*rh/9}%\" font-size=\"#{rh}\"> VS </text>\n"
+ str += "/>\n"
- color = (matches[i].teams[1] and matches[i].teams[1].users.include?(current_user)) ? "#BCED91" : "white"
- str += "\t\t<rect width=\"#{rw-5}%\" height=\"#{rh/4}%\" x=\"#{rx + 2.5}%\" y=\"#{ry + 3*rh/5}%\" fill=\"#{color}\" />\n"
- if matches[i].teams[1]
- str += "\t\t<text x=\"#{rx + rw/4}%\" y=\"#{ry + 4*rh/5}%\" font-size=\"#{rh}\">Team #{matches[i].teams[1].id}</text>\n"
+ t = 1
+ while t <= numTeams
+ color = (matches[i].teams[t-1] and matches[i].teams[t-1].users.include?(current_user)) ? "#5BC0DE" : "white"
+ str += "\t\t<rect width=\"#{rw-5}%\" height=\"#{rh*Float(30)/(matchHeight)}%\" x=\"#{rx + 2.5}%\" y=\"#{ry + (Float(t-1)/numTeams)*rh + 2 }%\" fill=\"#{color}\" />\n"
+ if matches[i].teams[t-1]
+ str += "\t\t<text x=\"#{rx + rw/4}%\" y=\"#{ry + (Float(t-1)/numTeams + Float(30)/(matchHeight))*rh}%\" font-size=\"#{rh}\">Team #{matches[i].teams[t-1].id}</text>\n"
+ end
+ if (t < numTeams)
+ str += "\t\t<text x=\"#{rx + 1.3*rw/3}%\" y=\"#{ry + (Float(20+35*(t))/matchHeight)*rh}%\" font-size=\"#{rh}\"> VS </text>\n"
+ end
+ t = t + 1
end
if i > 1
- str += "\t\t<line x1=\"#{rx+rw}%\" y1=\"#{ry+rh/2}%\" x2=\"#{lastrx}%\" y2=\"#{lastry+lastrh/2}%\" stroke=\"black\" stroke-width=\"2\" >\n"
- end
- if Math.log2(i+1) == Math.log2(i+1).ceil
- lastrx = rx
- lastry = ry
- lastrh = rh
- lastrw = rw
+ parent = (i+logBase-2)/logBase
+ pDepth = Math.log(parent*(logBase-1), logBase).floor+1
+ pBase = (logBase**(pDepth-1)/(logBase-1)).ceil
+ lastrx = 50/(depth+1) + 100/(depth+1)*(depth-pDepth)
+ lastry = 100/(logBase**(pDepth-1)+1) * (parent-pBase+1) - rh/2
+ str += "\t\t<line x1=\"#{rx+rw}%\" y1=\"#{ry+rh/2}%\" x2=\"#{lastrx}%\" y2=\"#{lastry+rh/2}%\" stroke=\"white\" stroke-width=\"2\" >\n"
end
str += "</g></a>\n"
end
@@ -126,5 +133,6 @@ STRING
return str
end
+
end
end