--- /dev/null
+<% victories, tied =@election.condorcet_result.list_defeats -%>
+<%candidates = @election.candidates.sort.collect {|candidate| candidate.id}%>
+<% names = Hash.new -%>
+<% candidates.each do |candidate| -%>
+ <%names[candidate] = Candidate.find(candidate).name -%>
+<% end -%>
+
+<% victories.each do |victory| -%>
+<%= names[victory[0]] %> beat <%= names[victory[1]] %> by <%= victory[2]%>
+votes.<br />
+<% end -%>
+
+<% tied.each do |tie| -%>
+<%= names[tie[0]]%> tied with <%= names[tie[1]]%><br />
+<% end -%>
-<% candidates = @election.candidates.sort.collect {|candidate| candidate.id} -%>
+<% candidates = @election.candidates.sort.collect {|candidate| candidate.id}-%>
+<% names = Hash.new -%>
+<% candidates.each do |candidate| -%>
+ <%names[candidate] = Candidate.find(candidate).name -%>
+<% end -%>
<table class="voterbox">
<tr>
<td> </td>
<% candidates.each do |candidate| -%>
- <th><%= candidate -%></th>
+ <th><%= names[candidate] -%></th>
<% end -%>
<% candidates.each do |winner| -%>
<tr>
- <th><%= winner %></th>
+ <th><%= names[winner] %></th>
<% candidates.each do |loser| -%>
<% if winner == loser -%>
<td> -- </td>
<% end -%>
<% end -%>
</tr>
-<%end -%>
\ No newline at end of file
+<% end -%>
+
+<% %>
<%require 'IPAddr' %>
<h1>Results</h1>
<% end %>
</table>
+<%= render :partial => 'defeats_list' %>
<%= render :partial => 'pref_table' %>
<%= image_tag( graph_url( :action => 'votes_per_day', :id => @election ) ) %><br />
super(voteobj)
@matrix = voteobj.votes
end
-
+
+ def list_defeats
+ victors = Array.new
+ ties = Array.new
+ candidates = @matrix.keys.sort
+
+ candidates.each do |candidate|
+ candidates.each do |challenger|
+ next if candidate == challenger
+ diff = @matrix[candidate][challenger] - @matrix[challenger][candidate]
+ if diff > 0
+ victors << [candidate, challenger, diff]
+ elsif diff == 0 && ties.include?([challenger, candidate]) == false
+ ties << [candidate, challenger]
+ end
+ end
+ end
+
+ victories = victors.sort {|a,b| b[2] <=> a[2]}
+
+ return victories, ties
+ end
+
protected
def defeats(candidates=nil, votes=nil)
candidates = @election.candidates unless candidates
end
protected
-
+
def condorcet
votes = @election.votes
candidates = @election.candidates