]> projects.mako.cc - selectricity-live/blob - app/controllers/application.rb
upgraded to latest version of rubyvote in svn
[selectricity-live] / app / controllers / application.rb
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.
3
4 class ApplicationController < ActionController::Base
5   include AuthenticatedSystem
6   helper :user
7   model :user
8   
9   def day_votes
10   
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
20     line.draw
21     send_data(line.to_blob,
22               :disposition => 'inline',
23               :type => 'image/png',
24               :filename => "dayvotes#{@poll.id}.png")
25   end
26   
27   def voter_days
28     @election = Election.find(params[:id])
29     voter_times = Array.new
30     unique_days = Array.new
31     voters_per_day = Array.new
32     days_hash = Hash.new
33     
34     @election.votes.each do |vote|
35         voter_times << vote.time unless voter_times.any? {|utime| utime == vote.time}
36     end
37     
38     voter_times.sort!
39   
40     voter_times.each_with_index do |time, index| 
41       count = 1
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
46       end      
47     end
48     
49     unique_days.each_with_index do |fmtdate, index|
50       days_hash[index] = fmtdate
51     end    
52   return { "voters_per_day" => voters_per_day, "days_hash" => days_hash }
53    
54   end
55 end

Benjamin Mako Hill || Want to submit a patch?