send_data(g.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "gruff.png")
end
- #The following section has been pasted directly fromworking pollarize graphs
- #and hasn't been adopted to fit Selectricity yet
-
+ #I've started to modify the following section to fit Selectricity, still
+ #desn't seem towork, issue seems tobe realted to path
def day_votes
- @poll = Poll.find(params[:id])
+
+ @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("#{@poll.name}", voter_days["voters_per_day"] )
+ 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"
end
def voter_days
- @poll = Poll.find(params[:id])
+ @election = Election.find(params[:id])
voter_times = Array.new
unique_days = Array.new
voters_per_day = Array.new
days_hash = Hash.new
- @poll.questions.each do |qstn|
- qstn.votes.each do |vote|
+ @election.votes.each do |vote|
voter_times << vote.time unless voter_times.any? {|utime| utime == vote.time}
- end
end
+
voter_times.sort!
- #find all times in voter_times with the same date, and then concatenate
- #that number onto votes_per_day
- #
- #doesn't work jsut yet
+
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) }
return { "voters_per_day" => voters_per_day, "days_hash" => days_hash }
end
- #end copy/pasted section
+ #end section
end
else
# record the ip address for posterity
- @voter.ipaddress = request.env["HTTP_X_FORWARDED_FOR"]
+ @voter.ipaddress = request.env["BLAH"]
@voter.save
- # toggle the confirmation bit
+ # save the time the vote was made for statistical use, it doesn't
+ #work here unless I use a method that will save it to the db
+ @voter.vote.time = Time.now
+
+ # toggle the confirmation bit
@voter.vote.confirm!
+
@voter.reload
render :action => 'thanks'
end
model :user, :election, :account
def index
- @quickvotes = QuickVote.find_all(["quickvote = 1"]).sort {|a,b| b.enddate <=> a.enddate}[0..1]
+ @quickvotes = QuickVote.find(:all, ["quickvote = 1"]).sort {|a,b| b.enddate <=> a.enddate}[0..1]
# if the person claims they are logged in
if session[:user]
# check to see that we actually have record of them
- if User.find_all(["id = ?", session[:user].id]).length == 1
+ if User.find(:all, ["id = ?", session[:user].id]).length == 1
# if we have record of them, grab the list of their elections
session[:user] = User.find(session[:user])
@current_elections = session[:user].elections.sort do |a,b|
def startdate
read_attribute( :startdate ) || Time.now
end
-
+
def enddate
date = read_attribute( :enddate ) || Time.now + 14
date - 1.second
super(date)
end
+ def votes
+ votes = Array.new
+ self.voters.each do |voter|
+ votes << voter.vote
+ end
+ return votes
+ end
+
def destroy
self.candidates.each do |candidate|
candidate.destroy
after_update :save_rankings
before_destroy :destroy_rankings
+
+
def to_s
votes.join("")
end
rankings.each { |ranking| ranking.destroy }
end
+ def settime
+ self.time = Time.now
+ self.save
+ end
+
def confirm!
self.confirmed = 1
self.save
<div id="links">
<% if session[:user] %>
-<% breakpoint %>
Welcome <strong><%= User.find(session[:user]).login.capitalize %></strong>
<% else %>
<%= link_to("Login", :controller => "account", :action => "login")
<% end %>
<%= link_to("Help/About", :controller => "site", :action => "about") %>
+ <%= link_to( "Home", :controller => 'site', :action => 'index' )%>
</div>
</div>
- <% if @flash[:notice]%>
- <div id="notice"><%= @flash[:notice] %></div>
+ <% if flash[:notice]%>
+ <div id="notice"><%= flash[:notice] %></div>
<% end%>
<div id="main">
</tr>
<% end %>
</table>
+<img src="<% url_for(:controller => 'graphs', :action => 'day_votes', :id => @election ) %>" />
<%= form_tag :controller => 'voter', :action => 'index' %>
<%= text_field :vote, :password %>
<%= submit_tag "Log In" %>
-<%= end_form_tag %>
+
<p><%= link_to 'Lost or forgot your token?', :controller => 'voter', :action => 'forgot_password' %></p>
<% if session[:user] %>
require 'uniq_token'
require 'randarray'
require 'rubyvote'
+require 'gruff'
class String
# alternate capitalization method that does not lowercase the rest of