]> projects.mako.cc - selectricity/commitdiff
Finished organzing preferential vote tables into one partial. Also changed RubyVote...
author<jlsharps@mit.edu> <>
Tue, 21 Aug 2007 16:57:40 +0000 (12:57 -0400)
committer<jlsharps@mit.edu> <>
Tue, 21 Aug 2007 16:57:40 +0000 (12:57 -0400)
app/controllers/graph_controller.rb
app/views/quickvote/_pref_tables.rhtml [moved from app/views/quickvote/_pref_table.rhtml with 50% similarity]
app/views/quickvote/_victories_ties.rhtml [deleted file]
app/views/quickvote/results.rhtml
lib/rubyvote/condorcet.rb

index 442bb65db975b9e4b650bd18815b560561595277..c72da85a6dea19732d070710ff42fb330fbc2c1a 100644 (file)
@@ -99,6 +99,7 @@ class GraphController < ApplicationController
     legend = Hash.new   
     alldata, labels = get_positions_info(@election)    
     @election.results unless @election.condorcet_result || @election.ssd_result
     legend = Hash.new   
     alldata, labels = get_positions_info(@election)    
     @election.results unless @election.condorcet_result || @election.ssd_result
+    ranked_candidates = @election.condorcet_result.ranked_candidates.flatten
     
     names = Hash.new
     candidates = @election.candidates.sort.collect {|candidate| candidate.id}
     
     names = Hash.new
     candidates = @election.candidates.sort.collect {|candidate| candidate.id}
@@ -106,7 +107,6 @@ class GraphController < ApplicationController
       names[candidate]= (Candidate.find(candidate)).name
     end
     
       names[candidate]= (Candidate.find(candidate)).name
     end
     
-    ranked_candidates = @election.condorcet_result.ranked_candidates.flatten
     ranked_candidates.each_with_index \
     {|candidate, index| legend[names[candidate]] = alldata[index]}
     
     ranked_candidates.each_with_index \
     {|candidate, index| legend[names[candidate]] = alldata[index]}
     
@@ -119,6 +119,15 @@ class GraphController < ApplicationController
     send_data(*graph.output) 
   end
   
     send_data(*graph.output) 
   end
   
+  def plurality_pie
+    @election = Election.find(params[:id])
+    
+    
+    
+    pie = GruffGraff.new ( :graph_type => Gruff::Pie,
+                           :data =>   ,
+                           :title => "Percentage of First Plce Votes")
+  
  private 
   def get_positions_info(election)
     buckets = Hash.new
  private 
   def get_positions_info(election)
     buckets = Hash.new
similarity index 50%
rename from app/views/quickvote/_pref_table.rhtml
rename to app/views/quickvote/_pref_tables.rhtml
index 011fcbe8ac2d29aa7b2147797e249f99c3b57389..66e0cbf2df1fbf7870581ca6ed849b66db2c7f21 100644 (file)
@@ -1,17 +1,19 @@
-<% candidates = @election.candidates.sort.collect {|candidate| candidate.id}-%>
+<% candidates = @election.condorcet_result.ranked_candidates.flatten -%>
 <% voters = @election.voters.size %>
 <% matrix = @election.condorcet_result.matrix %>
 <% voters = @election.voters.size %>
 <% matrix = @election.condorcet_result.matrix %>
-<% names = Hash.new -%>
-<% candidates.each do |candidate| -%>
-       <%names[candidate] = Candidate.find(candidate).name -%>
-<% end -%>
+<% victories = @election.condorcet_result.victories_and_ties %>
+<% names = @election.names_by_id %>
+
+
+<!-- This table shows how many times each choice was ranked above the other, 
+       with percentages-->
 <table class="voterbox">
   <tr>
        <td> </td>
        <% candidates.each do |candidate| -%>
          <th><%=h names[candidate] -%></th>
   <% end -%>
 <table class="voterbox">
   <tr>
        <td> </td>
        <% candidates.each do |candidate| -%>
          <th><%=h names[candidate] -%></th>
   <% end -%>
-</tr>
+ </tr>
 
 <% candidates.each do |winner| -%>
   <tr>
 
 <% candidates.each do |winner| -%>
   <tr>
  </tr>
 <% end -%>
 </table>
  </tr>
 <% end -%>
 </table>
+
+<!-- This table generates a margin of victory -->
+<table class="voterbox">
+  <% candidates.each do |victor| %>
+  <tr>
+    <th><%=h names[victor] %></th>
+       <% victories[victor].keys.each do |loser| %>
+       <% margin = victories[victor][loser]%>
+       <td><%=h names[loser] %> 
+           <% if margin == 0%>
+                 Tied!
+               <% else -%>
+                 (<%= margin%>)
+               <% end -%>
+                 </td>
+       <% end -%>
+  </tr>
+  <% end -%>
+</table>
+
diff --git a/app/views/quickvote/_victories_ties.rhtml b/app/views/quickvote/_victories_ties.rhtml
deleted file mode 100644 (file)
index 993caa8..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-<% victories, tied = @election.condorcet_result.victories_and_ties %>
-<% names = @election.names_by_id %>
-<% %>
-<table class="voterbox">
-  <% victories.keys.each do |victor| %>
-  <tr>
-    <th><%=h names[victor] %></th>
-       <% victories[victor].keys.each do |loser| %>
-       <td><%=h names[loser] %> (<%= victories[victor][loser] %>)</td>
-       <% end -%>
-  </tr>
-  <% end -%>
-</table>
-               
-       
-       
-
index 2999e6b1bd1d150925387911221b77631503f841..874f725f7b85972522ca1094159b56f4ef30e887 100644 (file)
@@ -176,8 +176,7 @@ by several other names.</p>
 <% end %>
 </table>
 
 <% end %>
 </table>
 
-<%= render :partial => 'victories_ties' %>
-<%= render :partial => 'pref_table' %>
+<%= render :partial => 'pref_tables' %>
 
 <%=image_tag( graph_url( :action => 'votes_per_interval', :id => @election ))%>
 <br />
 
 <%=image_tag( graph_url( :action => 'votes_per_interval', :id => @election ))%>
 <br />
index d0210efe19cfbf4fd09f9feb9dc82e4678583b74..0cc169647b4526202347e74054f0173b5d994a69 100644 (file)
@@ -124,32 +124,29 @@ class CondorcetResult < ElectionResult
   
   def victories_and_ties
     victors = Array.new
   
   def victories_and_ties
     victors = Array.new
-    ties = Array.new
-    victories = Hash.new
+    victories_ties = Hash.new
     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]
-        elsif diff == 0 && ties.include?([challenger, candidate]) == false
-          ties << [candidate, challenger] 
+        if diff >= 0 
+          victors << [candidate, challenger, diff] 
         end
       end
     end  
     
     victors.each do |list|
         end
       end
     end  
     
     victors.each do |list|
-      if victories.has_key?(list[0])
-        victories[list[0]][list[1]] = list[2]       
+      if victories_ties.has_key?(list[0])
+        victories_ties[list[0]][list[1]] = list[2]       
       else
       else
-        victories[list[0]] = Hash.new
-        victories[list[0]][list[1]] = list[2]
+        victories_ties[list[0]] = Hash.new
+        victories_ties[list[0]][list[1]] = list[2]
       end
     end
     
       end
     end
     
-    return victoriesties    
+    return victories_ties    
   end
 
   def ranked_candidates
   end
 
   def ranked_candidates

Benjamin Mako Hill || Want to submit a patch?