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
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
<% 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">
</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' ) ) %>
# 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',
# 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'
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; }