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

Benjamin Mako Hill || Want to submit a patch?