Modified the methods in graphs controller so they would work for Selectricity, but...
author<jlsharps@mit.edu> <>
Mon, 6 Aug 2007 23:56:39 +0000 (19:56 -0400)
committer<jlsharps@mit.edu> <>
Mon, 6 Aug 2007 23:56:39 +0000 (19:56 -0400)
app/controllers/graphs_controller.rb
app/controllers/quickvote_controller.rb
app/controllers/site_controller.rb
app/models/election.rb
app/models/vote.rb
app/views/layouts/hc.rhtml
app/views/quickvote/results.rhtml
app/views/site/index.rhtml
config/environment.rb

index c8108536b214262130f3f5f96134ffced3abaa54..101dc6d6d185ddde9bd184a3b161d981a7643117 100644 (file)
@@ -29,15 +29,15 @@ class GraphsController < ApplicationController
     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"
@@ -50,22 +50,18 @@ class GraphsController < ApplicationController
   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) }
@@ -81,7 +77,7 @@ class GraphsController < ApplicationController
   return { "voters_per_day" => voters_per_day, "days_hash" => days_hash }
    
   end
-  #end copy/pasted section
+  #end section
 
 
 end
index 10815b3c590ac19af542240d3cf8ec6d420cb9e9..e7a285b7d45e7d0d8f8c22d2808b33a031a115ed 100644 (file)
@@ -105,11 +105,16 @@ class QuickvoteController < ApplicationController
       
     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
index dd049f7311d2bf0d95e03b7212bacc2b3565f12e..f6b36a774b141fb4cc0c8ddd07084ed65120f6fb 100644 (file)
@@ -3,12 +3,12 @@ class SiteController < ApplicationController
   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|
index 0907e68a4cfc7e5796ef9920bbfca09a4b0cd0bd..ebd623a6b186d4006d54c2f144557d0003a169fa 100755 (executable)
@@ -10,7 +10,7 @@ class Election < ActiveRecord::Base
   def startdate
     read_attribute( :startdate ) || Time.now
   end
-
+  
   def enddate
     date = read_attribute( :enddate ) || Time.now + 14
     date - 1.second
@@ -22,6 +22,14 @@ class Election < ActiveRecord::Base
     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
index f263a75bb687d332527bc5ce938ada35ab4eb9b2..62944e3301a5b6f07f77f475e1ef85ae8d314cc6 100755 (executable)
@@ -8,6 +8,8 @@ class Vote < ActiveRecord::Base
   after_update :save_rankings
   before_destroy :destroy_rankings
 
+  
+
   def to_s
     votes.join("")
   end
@@ -51,6 +53,11 @@ class Vote < ActiveRecord::Base
     rankings.each { |ranking| ranking.destroy }
   end
 
+  def settime
+    self.time = Time.now
+    self.save
+  end
+
   def confirm!
     self.confirmed = 1
     self.save
index 13b2e729109fc1d704d242418b840284a3f2d791..604673539b2fcbfc7b508907f91b5a136f6d3a32 100755 (executable)
@@ -17,7 +17,6 @@
 
            <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">
index 8ce400aebe5e397393d0f46df1426f3a495f0dce..321dbbca3d1266eac4b32b32ff228db5d1b58104 100755 (executable)
@@ -161,3 +161,4 @@ by several other names.</p>
   </tr>
 <% end %>
 </table>
+<img src="<% url_for(:controller => 'graphs', :action => 'day_votes', :id => @election ) %>" />
index f2f5700e71b8bb0a3ea560a126e479c00915ae10..eb009b31db9a155f2bbfe29113e3e25368b73238 100755 (executable)
@@ -43,7 +43,7 @@ ongoing election, you can log in to vote using your token here.</p>
 <%= 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] %>
index 7d3657ec46f66e5066d4b8f3b0b94481b6492037..77d020c81efd5ccc126a529c6855f5161d05468b 100644 (file)
@@ -64,6 +64,7 @@ MAIL_CONFIG = { :from => 'Selectricity <info@selectricity.media.mit.edu>'}
 require 'uniq_token'
 require 'randarray'
 require 'rubyvote'
+require 'gruff'
 
 class String
   # alternate capitalization method that does not lowercase the rest of

Benjamin Mako Hill || Want to submit a patch?