From: Date: Wed, 16 Aug 2006 19:30:18 +0000 (-0400) Subject: Added processing and presentatin of results. X-Git-Url: https://projects.mako.cc/source/selectricity/commitdiff_plain/dc7d60a0de460c72d292b43616eb97a8b34741c8?ds=sidebyside Added processing and presentatin of results. --- diff --git a/app/controllers/elections_controller.rb b/app/controllers/elections_controller.rb index 4a85c29..4cb72bc 100644 --- a/app/controllers/elections_controller.rb +++ b/app/controllers/elections_controller.rb @@ -1,8 +1,8 @@ class ElectionsController < ApplicationController model :raw_voter_list, :voter, :vote, :candidate - - # general methods for dealing with elections + ## general methods for dealing with elections + #################################################################### def index list render :action => 'list' @@ -12,8 +12,10 @@ class ElectionsController < ApplicationController @election_pages, @elections = paginate :elections, :per_page => 10 end - # methods for displaying, creating, and manipulating election overview - # data + ## methods for displaying, creating, + ## and manipulating election overview data + #################################################################### + def show @election = Election.find(params[:id]) end @@ -53,6 +55,7 @@ class ElectionsController < ApplicationController # methods fod display, adding, deleting, and manipulating candidate # information for elections + #################################################################### def new_candidates @election = Election.find( params[:id] ) end @@ -75,8 +78,9 @@ class ElectionsController < ApplicationController @election = Election.find( params[:id] ) end - # methods for displaying, adding, deleting, and manipulating voters - # for a particular election + ## methods for displaying, adding, deleting, and manipulating voters + ## for a particular election + #################################################################### def new_voters @election = Election.find( params[:id] ) if params.has_key?[:raw_voter_list] @@ -100,15 +104,33 @@ class ElectionsController < ApplicationController voter.destroy end - def summary_results + ## methods for computing and printing results + #################################################################### + def results + @election = Election.find( params[:id] ) + votes = [] + + @election.voters.each do |voter| + if voter.vote and voter.vote.confirmed? + votes << voter.vote.rankings.sort.collect {|vote| vote.candidate_id} + end + end + + @voteobj = CloneproofSSDVote.new(votes) + @resultobj = @voteobj.result + @winners = @resultobj.winners + + @candidates_by_id = {} + @election.candidates.each {|cand| @candidates_by_id[cand.id] = cand} end def detailed_results - @election = Election.find( params[:id] ) - + + self.results + breakpoint @voter_list = [] @vote_list = [] - @election.voters.each do |voter| + @election.voters. each do |voter| if voter.vote and voter.vote.confirmed? @voter_list << voter.email @vote_list << voter.vote @@ -117,13 +139,11 @@ class ElectionsController < ApplicationController @vote_list.sort! @vote_list.sort! { |a,b| a.token <=> b.token } - #breakpoint - end - + + ## private methods + #################################################################### private - def randomize_order - end def process_incoming_voters(raw_voter_list) incoming_voters = RawVoterList.new( raw_voter_list ) diff --git a/app/models/vote.rb b/app/models/vote.rb index 82f34a9..429e212 100644 --- a/app/models/vote.rb +++ b/app/models/vote.rb @@ -36,7 +36,7 @@ class Vote < ActiveRecord::Base destroy_rankings self.votes.each_with_index do |candidate, index| ranking = Ranking.new - ranking.rank = index + 1 + ranking.rank = index ranking.candidate = Candidate.find(candidate) self.rankings << ranking end diff --git a/app/views/elections/_winner.rhtml b/app/views/elections/_winner.rhtml new file mode 100644 index 0000000..531e0d2 --- /dev/null +++ b/app/views/elections/_winner.rhtml @@ -0,0 +1,21 @@ +<% %> + +<% if @winners.length > 1 %> +

There were multiple winners for the election. The winners (tied) + were: + +

+ +<% else %> + + <% winner = @winners[0] %> +

The winner of the election was: + <%= @candidates_by_id[winner].name %> +

+ +<% end %> + diff --git a/app/views/elections/_winner_details.rhtml b/app/views/elections/_winner_details.rhtml new file mode 100644 index 0000000..0903952 --- /dev/null +++ b/app/views/elections/_winner_details.rhtml @@ -0,0 +1,28 @@ +<% %> +

The matrix listing the number of times that any candidate was +preferred to any other candidates is listed here:

+ + + + +<% for candidate in @election.candidates.sort %> + +<% end %> + +<% for cand1 in @election.candidates.sort %> + + + <% for cand2 in @election.candidates.sort %> + + <% end %> + +<% end %> +
<%= candidate.name %>
<%= cand1.name %> + <% if cand1 == cand2 %> + N/A + <% next %> + <% else %> + <%= @voteobj.votes[cand1.id][cand2.id] %> + <% end %> +
+ diff --git a/app/views/elections/detailed_results.rhtml b/app/views/elections/detailed_results.rhtml index cfb0e5a..4668570 100644 --- a/app/views/elections/detailed_results.rhtml +++ b/app/views/elections/detailed_results.rhtml @@ -1,10 +1,25 @@ <% %> +

Result

+ +<%= render_partial 'winner' %> + +

Result Details

+ +<%= render_partial 'winner_details' %> + +

Election Rolls for Voter Verification

+

The voting rolls -- displayed here in alphabetical order -- for the last election are are follows.

-

Voters

- +

Information is displayed here to help voters verify that their own +vote was recorded correctly and that the election was not tampered +with.

+ +

Voters

+
+ <% for email in @voter_list %> @@ -12,26 +27,28 @@ last election are are follows.

<% end %>
Voters (A-Z)
<%= email %>
-

Votes (by Token)

+

Votes by Token

The votes, listed in alphabetical order by token.

- + + <% for candidate in @election.candidates.sort.reverse %> <% end %> + <% for vote in @vote_list %> - - -<% for ranking in vote.rankings %> - -<% end %> - + + + <% for ranking in vote.rankings %> + + <% end %> + <% end %>
TokenToken (0-9, A-Z) Rank of Candidates
<%= candidate %>
<%= vote.token %><%= ranking %>
<%= vote.token %><%= ranking %>
diff --git a/config/environment.rb b/config/environment.rb index de8cbaf..a0ed78e 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -52,3 +52,4 @@ end require 'uniq_token' require 'randarray' +require 'rubyvote'