Added the Gruff library to the lib/ directory of the the rails folder, and the
[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
6 <!-- This table shows how many times each choice was ranked above the other, 
7         with percentages-->
8 <table class="preftable">
9   <tr>
10         <td></td>
11         <% candidates.each do |candidate| -%>
12           <th><%=h @names[candidate] -%></th>
13   <% end -%>
14  </tr>
15
16 <% candidates.each do |winner| -%>
17   <tr>
18         <th><%=h @names[winner] %></th>
19   <% candidates.each do |loser| -%> 
20     <% if winner == loser -%>
21       <td> -- </td>
22     <% else %>        
23       <td><% wins = matrix[winner][loser] unless matrix[winner].nil?%>
24           <%= wins %>
25               <%= sparkline_tag [(wins.to_f/voters.to_f)*100.0], :type => 'pie', 
26                                  :diameter => 25, :share_color => '#74ce00' %>
27           </td>
28     <% end -%>
29   <% end -%>
30  </tr>
31 <% end -%>
32 </table>
33
34 <!-- This table generates a margin of victory -->
35 <table class="preftable">
36   <% candidates.each do |victor| %>
37   <tr>
38     <th><%=h @names[victor] %></th>
39         <% victories[victor].keys.each do |loser| %>
40         <% margin = victories[victor][loser]%>
41         <td><%=h @names[loser] %> 
42             <% if margin == 0%>
43                   Tied!
44                 <% else -%>
45                   (<%= margin%>)
46                 <% end -%>
47         </td>
48         <% end -%>
49   </tr>
50   <% end -%>
51 </table>

Benjamin Mako Hill || Want to submit a patch?