merged in from code from the other master
[selectricity] / app / views / common / _pref_tables.rhtml
1 <!-- first, process the results -->
2 <% @election.results! %>
3
4 <!-- create the necessary variables -->
5 <% candidates = @election.ssd_result.ranked_candidates.flatten -%>
6 <% voters = @election.voters.size %>
7 <% matrix = @election.ssd_result.matrix %>
8 <% victories = @election.ssd_result.victories_and_ties %>
9 <% @names = @election.names_by_id %>
10
11 <p>Each number in the table below shows how many times the candidate on
12 the left beat the matching candidate on the top. The winner is on the
13 top of the left column.</p>
14
15 <!-- This table shows how many times each choice was ranked above the other, 
16         with percentages-->
17 <div class="result_table">
18 <table class="preftable">
19   <tr>
20         <td></td>
21         <% candidates.each do |candidate| -%>
22           <th><%= white_list(@names[candidate]) -%></th>
23   <% end -%>
24  </tr>
25
26 <% candidates.each do |winner| -%>
27   <tr>
28         <th><%= white_list(@names[winner]) %></th>
29   <% candidates.each do |loser| -%> 
30     <% if winner == loser -%>
31       <td> -- </td>
32     <% else %>        
33       <td><% wins = matrix[winner][loser] unless matrix[winner].nil?%>
34           <%= wins %>
35               <%= sparkline_tag [(wins.to_f/voters.to_f)*100.0], :type => 'pie', 
36                                  :diameter => 25, :share_color => '#74ce00' %>
37           </td>
38     <% end -%>
39   <% end -%>
40  </tr>
41 <% end -%>
42 </table>
43 </div>
44 <!-- This table generates a margin of victory -->
45
46 <p>A simplification of the above data. The winner is on the left; each
47 cell names the defeated candidate and the magnitude of the victory in
48 parenthesis.</p>
49
50 <div class="result_table">
51 <table class="preftable">
52   <% candidates.each do |victor| %>
53   <tr>
54     <th><%= white_list(@names[victor]) %></th>
55 <!-- This is a pretty logic heavy section - think about trying to move it to 
56         backend eventually. Change the order of first and second to change the order 
57         that things are sorted in. -->
58         <% sorted = victories[victor].sort { |first,second| first[1] <=> second[1] }%>
59         <% sorted.each do |loserpair| %>
60         <td><%= white_list(@names[loserpair[0]]) %> 
61             <% if loserpair[1] == 0%>
62                   Tied!
63                 <% else -%>
64                   (<%= loserpair[1] %>)
65                 <% end -%>
66         </td>
67         <% end -%>
68   </tr>
69   <% end -%>
70 </table>
71 </div>
72
73

Benjamin Mako Hill || Want to submit a patch?