merged in from code from the other master
[selectricity] / app / views / common / _pref_tables.rhtml
index 7701985ec49b5e5a3c7a1ce965c410242e046c75..3edc05a1811c4da80c04aa764ac301e12bd65c62 100644 (file)
@@ -1,7 +1,12 @@
+<!-- first, process the results -->
+<% @election.results! %>
+
+<!-- create the necessary variables -->
 <% candidates = @election.ssd_result.ranked_candidates.flatten -%>
 <% voters = @election.voters.size %>
 <% matrix = @election.ssd_result.matrix %>
 <% victories = @election.ssd_result.victories_and_ties %>
+<% @names = @election.names_by_id %>
 
 <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
@@ -14,13 +19,13 @@ top of the left column.</p>
   <tr>
        <td></td>
        <% candidates.each do |candidate| -%>
-         <th><%=h @names[candidate] -%></th>
+         <th><%= white_list(@names[candidate]) -%></th>
   <% end -%>
  </tr>
 
 <% candidates.each do |winner| -%>
   <tr>
-       <th><%=h @names[winner] %></th>
+       <th><%= white_list(@names[winner]) %></th>
   <% candidates.each do |loser| -%> 
     <% if winner == loser -%>
       <td> -- </td>
@@ -46,14 +51,17 @@ parenthesis.</p>
 <table class="preftable">
   <% 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%>
+    <th><%= white_list(@names[victor]) %></th>
+<!-- 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 +70,4 @@ parenthesis.</p>
 </table>
 </div>
 
+

Benjamin Mako Hill || Want to submit a patch?