From eaf661eb6a8571bc24b180cfc731f3b9b38a8fff Mon Sep 17 00:00:00 2001 From: Date: Tue, 7 Aug 2007 17:07:16 -0400 Subject: [PATCH] Changed the Selectricity header into a link, and modified the config/routes.rb file to include a new named route: "graph." Use graph_url syntax to call a Gruff method from the graphs controller. Currently about to troubleshoot the user system. --- app/controllers/application.rb | 47 +++++++++++++++++++++++++ app/controllers/quickvote_controller.rb | 2 +- app/views/layouts/hc.rhtml | 5 +-- app/views/quickvote/results.rhtml | 5 ++- config/routes.rb | 11 +++++- public/stylesheets/hc.css | 1 + 6 files changed, 66 insertions(+), 5 deletions(-) diff --git a/app/controllers/application.rb b/app/controllers/application.rb index a5bb108..bab76f9 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -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 diff --git a/app/controllers/quickvote_controller.rb b/app/controllers/quickvote_controller.rb index e7a285b..5482a25 100644 --- a/app/controllers/quickvote_controller.rb +++ b/app/controllers/quickvote_controller.rb @@ -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 diff --git a/app/views/layouts/hc.rhtml b/app/views/layouts/hc.rhtml index 6046735..c04eb87 100755 --- a/app/views/layouts/hc.rhtml +++ b/app/views/layouts/hc.rhtml @@ -11,8 +11,9 @@ <% if @page_title %>

<%= @page_title %>

<% else %> -

Selectricity
- Voting Machinery for the Masses

+ <%= link_to('

Selectricity
+ Voting Machinery for the Masses

', :controller => + 'site', :action => 'index')%>
<% end %>