0d2b020f654c6de57a5f145d009da14c28e8d5d8
[selectricity] / app / views / quickvote / _pref_tables.rhtml
1 <% candidates = @election.condorcet_result.ranked_candidates.flatten -%>
2 <% voters = @election.voters.size %>
3 <% matrix = @election.condorcet_result.matrix %>
4 <% victories = @election.condorcet_result.victories_and_ties %>
5 <% names = @election.names_by_id %>
6
7 <!-- This table shows how many times each choice was ranked above the other, 
8         with percentages-->
9 <table class="voterbox">
10   <tr>
11         <td> </td>
12         <% candidates.each do |candidate| -%>
13           <th><%=h names[candidate] -%></th>
14   <% end -%>
15  </tr>
16
17 <% candidates.each do |winner| -%>
18   <tr>
19         <th><%=h names[winner] %></th>
20   <% candidates.each do |loser| -%> 
21     <% if winner == loser -%>
22       <td> -- </td>
23     <% else %>        
24       <td><% wins = matrix[winner][loser] unless matrix[winner].nil?%>
25           <%= wins %>
26               <%= sparkline_tag [(wins.to_f/voters.to_f)*100.0], :type => 'pie', 
27                                  :diameter => 25, :share_color => '#74ce00' %>
28           </td>
29     <% end -%>
30   <% end -%>
31  </tr>
32 <% end -%>
33 </table>
34
35 <!-- This table generates a margin of victory -->
36 <table class="voterbox">
37   <% candidates.each do |victor| %>
38   <tr>
39     <th><%=h names[victor] %></th>
40         <% victories[victor].keys.each do |loser| %>
41         <% margin = victories[victor][loser]%>
42         <td><%=h names[loser] %> 
43             <% if margin == 0%>
44                   Tied!
45                 <% else -%>
46                   (<%= margin%>)
47                 <% end -%>
48         </td>
49         <% end -%>
50   </tr>
51   <% end -%>
52 </table>

Benjamin Mako Hill || Want to submit a patch?