added support for results for full elections
[selectricity-live] / app / views / common / _pref_tables.rhtml
1 <% candidates = @election.ssd_result.ranked_candidates.flatten -%>
2 <% voters = @election.voters.size %>
3 <% matrix = @election.ssd_result.matrix %>
4 <% victories = @election.ssd_result.victories_and_ties %>
5
6 <p>Each number in the table below shows how many times the candidate on
7 the left beat the matching candidate on the top. The winner is on the
8 top of the left column.</p>
9
10 <!-- This table shows how many times each choice was ranked above the other, 
11         with percentages-->
12 <div class="result_table">
13 <table class="preftable">
14   <tr>
15         <td></td>
16         <% candidates.each do |candidate| -%>
17           <th><%=h @names[candidate] -%></th>
18   <% end -%>
19  </tr>
20
21 <% candidates.each do |winner| -%>
22   <tr>
23         <th><%=h @names[winner] %></th>
24   <% candidates.each do |loser| -%> 
25     <% if winner == loser -%>
26       <td> -- </td>
27     <% else %>        
28       <td><% wins = matrix[winner][loser] unless matrix[winner].nil?%>
29           <%= wins %>
30               <%= sparkline_tag [(wins.to_f/voters.to_f)*100.0], :type => 'pie', 
31                                  :diameter => 25, :share_color => '#74ce00' %>
32           </td>
33     <% end -%>
34   <% end -%>
35  </tr>
36 <% end -%>
37 </table>
38 </div>
39 <!-- This table generates a margin of victory -->
40
41 <p>A simplification of the above data. The winner is on the left; each
42 cell names the defeated candidate and the magnitude of the victory in
43 parenthesis.</p>
44
45 <div class="result_table">
46 <table class="preftable">
47   <% candidates.each do |victor| %>
48   <tr>
49     <th><%=h @names[victor] %></th>
50         <% victories[victor].keys.each do |loser| %>
51         <% margin = victories[victor][loser]%>
52         <td><%=h @names[loser] %> 
53             <% if margin == 0%>
54                   Tied!
55                 <% else -%>
56                   (<%= margin%>)
57                 <% end -%>
58         </td>
59         <% end -%>
60   </tr>
61   <% end -%>
62 </table>
63 </div>
64

Benjamin Mako Hill || Want to submit a patch?