From: John Dong Date: Thu, 16 Aug 2007 21:15:06 +0000 (-0400) Subject: Merge Justin X-Git-Url: https://projects.mako.cc/source/selectricity/commitdiff_plain/baf9ff0ec39c13f52ee8d4f087641dc5fcc9c53b?hp=166ed711409f6200467a3aa879fb165f59fc8cec Merge Justin --- diff --git a/app/views/quickvote/_defeats_list.rhtml b/app/views/quickvote/_defeats_list.rhtml new file mode 100644 index 0000000..248c294 --- /dev/null +++ b/app/views/quickvote/_defeats_list.rhtml @@ -0,0 +1,15 @@ +<% 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.
+<% end -%> + +<% tied.each do |tie| -%> +<%= names[tie[0]]%> tied with <%= names[tie[1]]%>
+<% end -%> diff --git a/app/views/quickvote/_pref_table.rhtml b/app/views/quickvote/_pref_table.rhtml index dfcb6cc..32f5de4 100644 --- a/app/views/quickvote/_pref_table.rhtml +++ b/app/views/quickvote/_pref_table.rhtml @@ -1,13 +1,17 @@ -<% 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 -%> <% candidates.each do |candidate| -%> - + <% end -%> <% candidates.each do |winner| -%> - + <% candidates.each do |loser| -%> <% if winner == loser -%> @@ -16,4 +20,5 @@ <% end -%> <% end -%> -<%end -%> \ No newline at end of file +<% end -%> + diff --git a/app/views/quickvote/results.rhtml b/app/views/quickvote/results.rhtml index f53bf3f..24a9beb 100644 --- a/app/views/quickvote/results.rhtml +++ b/app/views/quickvote/results.rhtml @@ -175,6 +175,7 @@ by several other names.

<% end %>
<%= candidate -%><%= names[candidate] -%>
<%= winner %><%= names[winner] %> --
+<%= render :partial => 'defeats_list' %> <%= render :partial => 'pref_table' %> <%= image_tag( graph_url( :action => 'votes_per_day', :id => @election ) ) %>
diff --git a/lib/rubyvote/condorcet.rb b/lib/rubyvote/condorcet.rb index bf4e548..7153995 100644 --- a/lib/rubyvote/condorcet.rb +++ b/lib/rubyvote/condorcet.rb @@ -153,7 +153,29 @@ class CondorcetResult < ElectionResult 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 @@ -182,7 +204,7 @@ class PureCondorcetResult < CondorcetResult end protected - + def condorcet votes = @election.votes candidates = @election.candidates