Ordered pref tables so that the smallest margin of vicotry appears first and the...
author<jlsharps@mit.edu> <>
Mon, 5 May 2008 23:33:06 +0000 (19:33 -0400)
committer<jlsharps@mit.edu> <>
Mon, 5 May 2008 23:33:06 +0000 (19:33 -0400)
app/controllers/application.rb
app/controllers/quickvote_controller.rb
app/views/common/_pref_tables.rhtml

index 7a725ba0f5e6df21d2585be0a6cfe3791040e1da..1387b29b10dd1e53e8b7252ef258164ec9e2ebf4 100644 (file)
@@ -49,7 +49,7 @@ class ApplicationController < ActionController::Base
   def sort_candidates
     
     @vote = Vote.find(params[:id])
-
+    
     @vote.rankings.each do |ranking|
       ranking.rank = params['rankings-list'].index(ranking.candidate.id.to_s) + 1
       ranking.save
index fbf53d3f0f3347e06c18dc61ec92a42a27f6f5fa..768bdea261ba28000363e25e4da6d3c24b61e7e9 100644 (file)
@@ -138,6 +138,7 @@ class QuickvoteController < ApplicationController
   end
 
   def confirm
+    
     # we need the election to verify that we have the right voter
     election = QuickVote.ident_to_quickvote(params[:ident])
 
@@ -145,7 +146,7 @@ class QuickvoteController < ApplicationController
     @voter = QuickVoter.find(:all,
       :conditions => ["session_id = ? and election_id = ?", 
                       session.session_id, election.id])[0]
-  
+   
     if not @voter
       # we have not seen this  voter before. something is wrong, try
       # again
index 567873b594652cb624a32ed3faeb6d6d503a84b0..3a53144068b601556d16b79f12d516fed90535ea 100644 (file)
@@ -2,7 +2,6 @@
 <% voters = @election.voters.size %>
 <% matrix = @election.ssd_result.matrix %>
 <% victories = @election.ssd_result.victories_and_ties %>
-
 <p>Each number in the table below shows how many times the candidate on
 the left beat the matching candidate on the top. The winner is on the
 top of the left column.</p>
@@ -47,13 +46,16 @@ parenthesis.</p>
   <% candidates.each do |victor| %>
   <tr>
     <th><%= white_list(@names[victor]) %></th>
-       <% victories[victor].keys.each do |loser| %>
-       <% margin = victories[victor][loser]%>
-       <td><%= white_list(@names[loser]) %> 
-           <% if margin == 0%>
+<!-- This is a pretty logic heavy section - think about trying to move it to 
+       backend eventually. Change the order of first and second to change the order 
+       that things are sorted in. -->
+       <% sorted = victories[victor].sort { |first,second| first[1] <=> second[1] }%>
+       <% sorted.each do |loserpair| %>
+       <td><%= white_list(@names[loserpair[0]]) %> 
+           <% if loserpair[1] == 0%>
                  Tied!
                <% else -%>
-                 (<%= margin%>)
+                 (<%= loserpair[1] %>)
                <% end -%>
        </td>
        <% end -%>
@@ -62,3 +64,4 @@ parenthesis.</p>
 </table>
 </div>
 
+

Benjamin Mako Hill || Want to submit a patch?