Extended the COLORS array in graph controller so that elections with multiple
[selectricity] / app / views / quickvote / _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 <% if candidates.size <= 7 -%>
7 <!-- This table shows how many times each choice was ranked above the other, 
8         with percentages-->
9 <table class="preftable">
10 <caption>Each number shows how many times the candidate on the left beat the 
11 matching candidate on the top. The Schulze/Condorcet winner is on the top of the 
12 left column.</caption>
13   <tr>
14         <td></td>
15         <% candidates.each do |candidate| -%>
16           <th><%=h @names[candidate] -%></th>
17   <% end -%>
18  </tr>
19
20 <% candidates.each do |winner| -%>
21   <tr>
22         <th><%=h @names[winner] %></th>
23   <% candidates.each do |loser| -%> 
24     <% if winner == loser -%>
25       <td> -- </td>
26     <% else %>        
27       <td><% wins = matrix[winner][loser] unless matrix[winner].nil?%>
28           <%= wins %>
29               <%= sparkline_tag [(wins.to_f/voters.to_f)*100.0], :type => 'pie', 
30                                  :diameter => 25, :share_color => '#74ce00' %>
31           </td>
32     <% end -%>
33   <% end -%>
34  </tr>
35 <% end -%>
36 </table>
37 <br />
38 <!-- This table generates a margin of victory -->
39 <table class="preftable">
40 <caption>A simplification of the above data. The winner is on the left; each cell
41 names the defeated candidate and the magnitude of the victory in parenthesis.
42 </caption>
43   <% candidates.each do |victor| %>
44   <tr>
45     <th><%=h @names[victor] %></th>
46         <% victories[victor].keys.each do |loser| %>
47         <% margin = victories[victor][loser]%>
48         <td><%=h @names[loser] %> 
49             <% if margin == 0%>
50                   Tied!
51                 <% else -%>
52                   (<%= margin%>)
53                 <% end -%>
54         </td>
55         <% end -%>
56   </tr>
57   <% end -%>
58 </table>
59 <% end -%>
60

Benjamin Mako Hill || Want to submit a patch?