summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortkimia <tkimia@purdue.edu>2014-04-28 22:54:35 -0400
committertkimia <tkimia@purdue.edu>2014-04-28 22:54:35 -0400
commit40c112d42922c14063759d381f834724f22a340d (patch)
tree2f43a624e715ee68a7e79312c1eba25d097ec2b7
parentdd4c9e16c529bdbf0d055b279ed2dadc0c2aae13 (diff)
made svg smaller
-rw-r--r--app/controllers/brackets_controller.rb1
-rw-r--r--app/models/bracket.rb9
-rw-r--r--app/views/brackets/show.html.erb20
-rw-r--r--app/views/common/_show_tournament.html.erb5
-rw-r--r--lib/scheduling/elimination.rb5
5 files changed, 29 insertions, 11 deletions
diff --git a/app/controllers/brackets_controller.rb b/app/controllers/brackets_controller.rb
index b91a2c4..e202c96 100644
--- a/app/controllers/brackets_controller.rb
+++ b/app/controllers/brackets_controller.rb
@@ -11,6 +11,7 @@ class BracketsController < ApplicationController
# GET /brackets/1
# GET /brackets/1.json
def show
+ @results = (@tournament.status == 4)? @bracket.calcResult : nil;
@matches = @tournament.stages.order(:id).first.matches_ordered
@numTeams = @tournament.min_teams_per_match
@logBase = @numTeams
diff --git a/app/models/bracket.rb b/app/models/bracket.rb
index fc3e10e..48414c3 100644
--- a/app/models/bracket.rb
+++ b/app/models/bracket.rb
@@ -20,4 +20,13 @@ class Bracket < ActiveRecord::Base
end
return true
end
+
+
+ def calcResults
+ results = Array.new
+ (0..bracket_matches.count-1).each do |i|
+ results.push(bracket_matches.order(:match_id)[i].predicted_winner == tournament.stages.order(:id).first.matches.order(:id).winner)
+ end
+ return results
+ end
end
diff --git a/app/views/brackets/show.html.erb b/app/views/brackets/show.html.erb
index a3eb000..24b19fe 100644
--- a/app/views/brackets/show.html.erb
+++ b/app/views/brackets/show.html.erb
@@ -1,7 +1,8 @@
<h2><%= @bracket.name %></h2>
-<h4> Make your prediction for the tournament by clicking on the teams you think will win </h4>
-
+<% if !@results %>
+ <h4> Make your prediction for the tournament by clicking on the teams you think will win </h4>
+<% end %>
<svg id="prediction-svg" version="1.1" baseProfile="full"
xmlns="http://www.w3.org/2000/svg"
@@ -71,7 +72,7 @@
while t <= @numTeams %>
<rect width="<%= rw-5 %>%" height="<%= rh*Float(30)/(@matchHeight) %>%" x="<%= rx + 2.5 %>%" y="<%= ry + (Float(t-1)/@numTeams)*rh + 1 %>%" fill="white" />
<text id="svg-match-<%= i %>-team-<%= t-1 %>" x="<%= rx + rw/4 %>%" y="<%= ry + (Float(t-1)/@numTeams + Float(33)/(@matchHeight))*rh %>%" font-size="150%"
- <% if @matches[i].teams[t-1] %>
+ <% if @matches[i].teams[t-1] && !@results %>
onclick="chooseWinner(<%= @matches[i].id%>, <%= @matches[i].teams[t-1].id %>)"
<% end %>
>
@@ -97,12 +98,13 @@
<% end %>
</SVG>
-<%= form_tag(tournament_bracket_path(@tournament, @bracket), method: 'put') do %>
- <input type="hidden" name="update_action" value="predict">
- <% for i in 1..@matches.length %>
- <%= hidden_field_tag("bracket[matches][#{@matches[i].id.to_s}]", value = nil) %>
+<% if !@results %>
+ <%= form_tag(tournament_bracket_path(@tournament, @bracket), method: 'put') do %>
+ <input type="hidden" name="update_action" value="predict">
+ <% for i in 1..@matches.length %>
+ <%= hidden_field_tag("bracket[matches][#{@matches[i].id.to_s}]", value = nil) %>
+ <% end %>
+ <%= submit_tag("Submit Prediction", disabled: true, id: "bracket-submit") %>
<% end %>
- <%= submit_tag("Submit Prediction", disabled: true, id: "bracket-submit") %>
<% end %>
-
<%= link_to 'Back', tournaments_path %>
diff --git a/app/views/common/_show_tournament.html.erb b/app/views/common/_show_tournament.html.erb
index f4d02ec..c0237b1 100644
--- a/app/views/common/_show_tournament.html.erb
+++ b/app/views/common/_show_tournament.html.erb
@@ -38,6 +38,11 @@
<%= form_tag(tournament_brackets_path(target), method: "post") do %>
<%= submit_tag("Make Bracket") %>
<% end %>
+ <% elsif @user_bracket && target.status == 4 %>
+ <%= form_tag(tournament_bracket_path(@tournament, @bracket), method: 'put') do %>
+ <input type="hidden" name="update_action" value="results">
+ <%= submit_tag("Bracket Results") %>
+ <% end %>
<% end %>
<% end %>
</div>
diff --git a/lib/scheduling/elimination.rb b/lib/scheduling/elimination.rb
index 4518cff..73aefb4 100644
--- a/lib/scheduling/elimination.rb
+++ b/lib/scheduling/elimination.rb
@@ -52,6 +52,7 @@ module Scheduling
# height of SVG
matchHeight = 50*logBase;
height = [(matchHeight+50) * logBase**(depth-1) + 100, 500].max;
+ height = height/2;
str = <<-STRING
<svg version="1.1" baseProfile="full"
@@ -109,10 +110,10 @@ module Scheduling
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 + 1 }%\" fill=\"#{color}\" />\n"
if matches[i].teams[t-1]
- str += "\t\t<text x=\"#{rx + rw/4}%\" y=\"#{ry + (Float(t-1)/numTeams + Float(33)/(matchHeight))*rh}%\" font-size=\"200%\">Team #{matches[i].teams[t-1].id}</text>\n"
+ str += "\t\t<text x=\"#{rx + rw/4}%\" y=\"#{ry + (Float(t-1)/numTeams + Float(33)/(matchHeight))*rh}%\" font-size=\"120%\">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(t)/numTeams)*rh + 1}%\" font-size=\"200%\"> VS </text>\n"
+ str += "\t\t<text x=\"#{rx + 1.3*rw/3}%\" y=\"#{ry + (Float(t)/numTeams)*rh + 1}%\" font-size=\"120%\"> VS </text>\n"
end
t = t + 1
end