X-Git-Url: https://projects.mako.cc/source/selectricity-live/blobdiff_plain/538c52ea43285fc1ae40e3c3ff5ee78befa1c142..da6c29f53b3598a6d2d9959df277b0340bc54cee:/app/views/common/_pref_tables.rhtml diff --git a/app/views/common/_pref_tables.rhtml b/app/views/common/_pref_tables.rhtml new file mode 100644 index 0000000..7701985 --- /dev/null +++ b/app/views/common/_pref_tables.rhtml @@ -0,0 +1,64 @@ +<% candidates = @election.ssd_result.ranked_candidates.flatten -%> +<% voters = @election.voters.size %> +<% matrix = @election.ssd_result.matrix %> +<% victories = @election.ssd_result.victories_and_ties %> + +

Each number in the table below shows how many times the candidate on +the left beat the matching candidate on the top. The winner is on the +top of the left column.

+ + +
+ + + + <% candidates.each do |candidate| -%> + + <% end -%> + + +<% candidates.each do |winner| -%> + + + <% candidates.each do |loser| -%> + <% if winner == loser -%> + + <% else %> + + <% end -%> + <% end -%> + +<% end -%> +
<%=h @names[candidate] -%>
<%=h @names[winner] %> -- <% wins = matrix[winner][loser] unless matrix[winner].nil?%> + <%= wins %> + <%= sparkline_tag [(wins.to_f/voters.to_f)*100.0], :type => 'pie', + :diameter => 25, :share_color => '#74ce00' %> +
+
+ + +

A simplification of the above data. The winner is on the left; each +cell names the defeated candidate and the magnitude of the victory in +parenthesis.

+ +
+ + <% candidates.each do |victor| %> + + + <% victories[victor].keys.each do |loser| %> + <% margin = victories[victor][loser]%> + + <% end -%> + + <% end -%> +
<%=h @names[victor] %><%=h @names[loser] %> + <% if margin == 0%> + Tied! + <% else -%> + (<%= margin%>) + <% end -%> +
+
+