]> projects.mako.cc - selectricity-live/commitdiff
Put in a pie graph for Plurality votes. ALso slimmed down victories_and_ties method...
author<jlsharps@mit.edu> <>
Tue, 21 Aug 2007 17:56:23 +0000 (13:56 -0400)
committer<jlsharps@mit.edu> <>
Tue, 21 Aug 2007 17:56:23 +0000 (13:56 -0400)
app/controllers/graph_controller.rb
app/views/quickvote/results.rhtml
lib/rubyvote/condorcet.rb

index c72da85a6dea19732d070710ff42fb330fbc2c1a..69577c6df84e1cf80566748993209eb145965027 100644 (file)
@@ -121,12 +121,21 @@ class GraphController < ApplicationController
   
   def plurality_pie
     @election = Election.find(params[:id])
   
   def plurality_pie
     @election = Election.find(params[:id])
+    @election.results unless @election.plurality_result || @election.approval_result
+    votes = @election.votes.size
+    data = Hash.new
+    names = @election.names_by_id
     
     
-    
-    
+    @election.plurality_result.points.each do |candidate, votes|
+      data[names[candidate]] = votes
+    end
+     
     pie = GruffGraff.new ( :graph_type => Gruff::Pie,
     pie = GruffGraff.new ( :graph_type => Gruff::Pie,
-                           :data =>   ,
-                           :title => "Percentage of First Plce Votes")
+                           :title => "Percentage of First Place Votes",
+                           :data => data)
+    send_data(*pie.output)
+                           
+  end
   
  private 
   def get_positions_info(election)
   
  private 
   def get_positions_info(election)
index 874f725f7b85972522ca1094159b56f4ef30e887..3d5468ce7782bd2d9095033fcde95a545abde31d 100644 (file)
@@ -181,4 +181,5 @@ by several other names.</p>
 <%=image_tag( graph_url( :action => 'votes_per_interval', :id => @election ))%>
 <br />
 <%= image_tag( graph_url( :action => 'borda_bar', :id => @election ) ) %><br />
 <%=image_tag( graph_url( :action => 'votes_per_interval', :id => @election ))%>
 <br />
 <%= image_tag( graph_url( :action => 'borda_bar', :id => @election ) ) %><br />
-<%= image_tag( graph_url( :action => 'choices_positions', :id => @election ) ) %>
+<%= image_tag( graph_url( :action => 'choices_positions', :id => @election ) ) %><br />
+<%= image_tag(graph_url( :action => 'plurality_pie', :id => @election ) )%>
index 0cc169647b4526202347e74054f0173b5d994a69..0c6fd5647bd921e5543838b42ddc297b57ca72cd 100644 (file)
@@ -123,27 +123,18 @@ class CondorcetResult < ElectionResult
   end
   
   def victories_and_ties
   end
   
   def victories_and_ties
-    victors = Array.new
-    victories_ties = Hash.new
+    victories_ties = {}
     candidates = @matrix.keys.sort
     
     candidates.each do |candidate|
       candidates.each do |challenger|
         next if candidate == challenger
         diff = @matrix[candidate][challenger] - @matrix[challenger][candidate]
     candidates = @matrix.keys.sort
     
     candidates.each do |candidate|
       candidates.each do |challenger|
         next if candidate == challenger
         diff = @matrix[candidate][challenger] - @matrix[challenger][candidate]
-        if diff >= 0 
-          victors << [candidate, challenger, diff] 
+        victories_ties[candidate] = {} unless victories_ties.key?(candidate)
+        if diff >= 0
+          victories_ties[candidate][challenger] = diff
         end
       end
         end
       end
-    end  
-    
-    victors.each do |list|
-      if victories_ties.has_key?(list[0])
-        victories_ties[list[0]][list[1]] = list[2]       
-      else
-        victories_ties[list[0]] = Hash.new
-        victories_ties[list[0]][list[1]] = list[2]
-      end
     end
     
     return victories_ties    
     end
     
     return victories_ties    

Benjamin Mako Hill || Want to submit a patch?