]> projects.mako.cc - selectricity-live/commitdiff
Changed the Selectricity header into a link, and modified the config/routes.rb file...
author<jlsharps@mit.edu> <>
Tue, 7 Aug 2007 21:07:16 +0000 (17:07 -0400)
committer<jlsharps@mit.edu> <>
Tue, 7 Aug 2007 21:07:16 +0000 (17:07 -0400)
app/controllers/application.rb
app/controllers/quickvote_controller.rb
app/views/layouts/hc.rhtml
app/views/quickvote/results.rhtml
config/routes.rb
public/stylesheets/hc.css

index a5bb1085361dbdd7f9169c2d1a2d442384a15d3d..bab76f91062983c5e9b3472d7983b4580532acf8 100644 (file)
@@ -5,4 +5,51 @@ class ApplicationController < ActionController::Base
   include AuthenticatedSystem
   helper :user
   model :user
+  
+  def day_votes
+  
+    @election = Election.find(params[:id])
+    line = Gruff::Line.new
+    line.title = "Voters Per Day"
+    line.font = File.expand_path('/usr/X11R6/lib/X11/fonts/TTF/Vera.ttf', RAILS_ROOT)
+    line.data("#{@election.name}", voter_days["voters_per_day"] )
+    line.labels = voter_days["days_hash"]
+    line.x_axis_label = "Date"
+    line.y_axis_label = "Number of Votes"
+    line.minimum_value = 0.0
+    line.draw
+    send_data(line.to_blob,
+              :disposition => 'inline',
+              :type => 'image/png',
+              :filename => "dayvotes#{@poll.id}.png")
+  end
+  
+  def voter_days
+    @election = Election.find(params[:id])
+    voter_times = Array.new
+    unique_days = Array.new
+    voters_per_day = Array.new
+    days_hash = Hash.new
+    
+    @election.votes.each do |vote|
+        voter_times << vote.time unless voter_times.any? {|utime| utime == vote.time}
+    end
+    
+    voter_times.sort!
+  
+    voter_times.each_with_index do |time, index| 
+      count = 1
+      unless unique_days.any? { |d1| d1.eql?(time.mon.to_s+"/"+time.day.to_s) }
+        unique_days << (time.mon.to_s+"/"+time.day.to_s)
+        count += (voter_times[(index+1)..-1].find_all {|t| t.mon == time.mon && t.day == time.day}).size
+        voters_per_day << count
+      end      
+    end
+    
+    unique_days.each_with_index do |fmtdate, index|
+      days_hash[index] = fmtdate
+    end    
+  return { "voters_per_day" => voters_per_day, "days_hash" => days_hash }
+   
+  end
 end
index e7a285b7d45e7d0d8f8c22d2808b33a031a115ed..5482a25c99f3d46d12149a4c84ab02725c622f1b 100644 (file)
@@ -105,7 +105,7 @@ class QuickvoteController < ApplicationController
       
     else
       # record the ip address for posterity
-      @voter.ipaddress = request.env["BLAH"]
+      @voter.ipaddress = request.env["REMOTE_ADDR"]
       @voter.save
       
       # save the time the vote was made for statistical use, it doesn't
index 604673539b2fcbfc7b508907f91b5a136f6d3a32..c04eb87b058656a5bbd00ff1b173deefd302215a 100755 (executable)
@@ -11,8 +11,9 @@
            <% if @page_title %>
               <h3><%= @page_title %></h3>  
            <% else %>
-             <h3>Selectricity<br />
-             <font size="-1">Voting Machinery for the Masses</font></h3>
+             <span id="headertext"><%= link_to('<h3>Selectricity<br />
+             <font size="-1">Voting Machinery for the Masses</font></h3>', :controller => 
+             'site', :action => 'index')%></span>
           <% end %>
 
            <div id="links">
index 321dbbca3d1266eac4b32b32ff228db5d1b58104..7152072d4c54d26c641842f880f3c9384296ca84 100755 (executable)
@@ -161,4 +161,7 @@ by several other names.</p>
   </tr>
 <% end %>
 </table>
-<img src="<% url_for(:controller => 'graphs', :action => 'day_votes', :id => @election ) %>" />
+
+<img src="<% url_for(:action => 'day_votes', :id => @election)%>" />
+<%= image_tag( graph_url( :action => 'day_votes', :id => @election ) ) %>
+<%= image_tag( graph_url( :action => 'show' ) ) %>
index 7a7b1013c146c7564fec40abc96932d36bff9b53..a05b80376764f5dc4829db0b02f06bfc21a3961a 100644 (file)
@@ -11,7 +11,7 @@ ActionController::Routing::Routes.draw do |map|
 
   # You can have the root of your site routed by hooking up '' 
   # -- just remember to delete public/index.html.
-  map.connect '', :controller => "site"
+  map.connect '', :controller => "site", :action => "index"
  
   map.connect 'quickvote/:action/:id',
                :controller => 'quickvote',
@@ -28,6 +28,15 @@ ActionController::Routing::Routes.draw do |map|
   # instead of a file named 'wsdl'
   map.connect ':controller/service.wsdl', :action => 'wsdl'
 
+  # The following pertain to caching and accessing Gruff graphs
+  # To make caching easier, add a line like this to config/routes.rb:
+  # map.graph "graph/:action/:id/image.png", :controller => "graph"
+  #
+  # Then reference it with the named route:
+  #   image_tag graph_url(:action => 'show', :id => 42)
+  map.graph "graphs/:action/:id/image.png", :controller => "graphs"      
+  map.graph "graphs/:action/image.png", :controller => "graphs" #pics w/o id's
+  
   # Install the default route as the lowest priority.
   map.connect ':controller/:action/:id.:format'
   map.connect ':controller/:action/:id'
index d4ee379b2916abdc9841f2b6ad2260cc460f2982..86cf84b2ac856f01547ad20befc745c83d3e3fc9 100755 (executable)
@@ -14,6 +14,7 @@ h1, h2, h3, h4 {
     text-shadow: #4D801A 0.2em 0.2em 3px;
 
 }
+#headertext a {color: #FFFFFF; text-decoration: none;}
 
 a:link { font-weight: bold; color: #4D801A; text-decoration: underline; } 
 a:visited { font-weight: bold; color: #4D801A; text-decoration: underline; }

Benjamin Mako Hill || Want to submit a patch?