1 # Filters added to this controller will be run for all controllers in the application.
2 # Likewise, all the methods added will be available for all controllers.
4 class ApplicationController < ActionController::Base
5 include AuthenticatedSystem
11 @election = Election.find(params[:id])
12 line = Gruff::Line.new
13 line.title = "Voters Per Day"
14 line.font = File.expand_path('/usr/X11R6/lib/X11/fonts/TTF/Vera.ttf', RAILS_ROOT)
15 line.data("#{@election.name}", voter_days["voters_per_day"] )
16 line.labels = voter_days["days_hash"]
17 line.x_axis_label = "Date"
18 line.y_axis_label = "Number of Votes"
19 line.minimum_value = 0.0
21 send_data(line.to_blob,
22 :disposition => 'inline',
24 :filename => "dayvotes#{@poll.id}.png")
28 @election = Election.find(params[:id])
29 voter_times = Array.new
30 unique_days = Array.new
31 voters_per_day = Array.new
34 @election.votes.each do |vote|
35 voter_times << vote.time unless voter_times.any? {|utime| utime == vote.time}
40 voter_times.each_with_index do |time, index|
42 unless unique_days.any? { |d1| d1.eql?(time.mon.to_s+"/"+time.day.to_s) }
43 unique_days << (time.mon.to_s+"/"+time.day.to_s)
44 count += (voter_times[(index+1)..-1].find_all {|t| t.mon == time.mon && t.day == time.day}).size
45 voters_per_day << count
49 unique_days.each_with_index do |fmtdate, index|
50 days_hash[index] = fmtdate
52 return { "voters_per_day" => voters_per_day, "days_hash" => days_hash }