From da6c29f53b3598a6d2d9959df277b0340bc54cee Mon Sep 17 00:00:00 2001 From: Date: Wed, 6 Feb 2008 01:38:47 -0500 Subject: [PATCH] added support for results for full elections this included a full details page, a pop-up preferences tables, some general reorganization of things due to new reusing, and several typo and bug fixing --- app/controllers/voter_controller.rb | 61 +++++++++++++++---- app/models/vote.rb | 12 +--- .../_methodinfo_approval.rhtml | 0 .../_methodinfo_borda.rhtml | 0 .../_methodinfo_condorcet.rhtml | 11 +++- .../_methodinfo_plurality.rhtml | 0 .../_methodinfo_runoff.rhtml | 0 app/views/common/_methodinfo_ssd.rhtml | 36 +++++++++++ .../{quickvote => common}/_pref_tables.rhtml | 3 - app/views/{quickvote => common}/_result.rhtml | 0 .../{quickvote => common}/_result_box.rhtml | 4 +- .../{voter => common}/_sortable_vote.rhtml | 8 --- app/views/common/pref_tables.rhtml | 1 + app/views/layouts/basic.rhtml | 24 ++++++++ app/views/layouts/frontpage.rhtml | 4 +- app/views/layouts/main.rhtml | 2 +- app/views/quickvote/_methodinfo_ssd.rhtml | 15 ----- app/views/quickvote/_results_sidebar.rhtml | 39 +----------- app/views/quickvote/index.rhtml | 2 +- app/views/quickvote/results.rhtml | 6 +- app/views/voter/_results_sidebar.rhtml | 7 +++ app/views/voter/_vote_sidebar.rhtml | 10 +++ app/views/voter/details.rhtml | 50 +++++++++++++++ app/views/voter/results.rhtml | 43 +++++++++++++ public/stylesheets/common.css | 33 ++++++++++ public/stylesheets/main.css | 30 --------- 26 files changed, 275 insertions(+), 126 deletions(-) rename app/views/{quickvote => common}/_methodinfo_approval.rhtml (100%) rename app/views/{quickvote => common}/_methodinfo_borda.rhtml (100%) rename app/views/{quickvote => common}/_methodinfo_condorcet.rhtml (58%) rename app/views/{quickvote => common}/_methodinfo_plurality.rhtml (100%) rename app/views/{quickvote => common}/_methodinfo_runoff.rhtml (100%) create mode 100644 app/views/common/_methodinfo_ssd.rhtml rename app/views/{quickvote => common}/_pref_tables.rhtml (97%) rename app/views/{quickvote => common}/_result.rhtml (100%) rename app/views/{quickvote => common}/_result_box.rhtml (79%) rename app/views/{voter => common}/_sortable_vote.rhtml (66%) create mode 100644 app/views/common/pref_tables.rhtml create mode 100644 app/views/layouts/basic.rhtml delete mode 100644 app/views/quickvote/_methodinfo_ssd.rhtml create mode 100644 app/views/voter/_results_sidebar.rhtml create mode 100644 app/views/voter/_vote_sidebar.rhtml create mode 100644 app/views/voter/details.rhtml create mode 100644 app/views/voter/results.rhtml diff --git a/app/controllers/voter_controller.rb b/app/controllers/voter_controller.rb index 461be29..ac57f1b 100644 --- a/app/controllers/voter_controller.rb +++ b/app/controllers/voter_controller.rb @@ -7,20 +7,33 @@ class VoterController < ApplicationController def index if params[:urlpassword] password = params[:urlpassword] - else - password = nil - end - if @voter = FullVoter.find(:all, :conditions => - [ "password = ?", password ] )[0] - @voter.vote = Vote.new if @voter.vote.nil? - @voter.vote.set_defaults! if @voter.vote.rankings.empty? + if @voter = FullVoter.find(:all, + :conditions => [ "password = ?", password ] )[0] - @election = @voter.election - @sidebar_content = render_to_string(:partial => 'sortable_vote') - render :action => 'full_vote' - elsif params[:urlpassword] - redirect_to :action => 'index' + @voter.vote = Vote.new if @voter.vote.nil? + @voter.vote.set_defaults! if @voter.vote.rankings.empty? + + @election = @voter.election + + # if the election is now finished + if @election.enddate < Time.now + # compute and display results + + @results = @election.results + @candidates = {} + @election.candidates.each {|c| @candidates[c.id] = c} + @names = @election.names_by_id + + @sidebar_content = render_to_string(:partial => 'results_sidebar') + render :action => 'results' + else + @sidebar_content = render_to_string(:partial => 'vote_sidebar') + render :action => 'full_vote' + end + elsif params[:urlpassword] + redirect_to :action => 'index' + end end end @@ -32,6 +45,30 @@ class VoterController < ApplicationController end end + def pref_tables + if authenticate + @election = @voter.election + @results = @election.results + @candidates = {} + @election.candidates.each {|c| @candidates[c.id] = c} + @names = @election.names_by_id + render :template => 'common/pref_tables', :layout => 'basic' + else + redirect_to :action => 'index' + end + end + + def details + if authenticate + @election = @voter.election + @votes = @election.votes.select {|v| v.confirmed? }.randomize + @voters = @votes.collect {|v| v.voter}.randomize + render :action => 'details' + else + redirect_to :action => 'index' + end + end + def review if authenticate @voter.vote.time = Time.now diff --git a/app/models/vote.rb b/app/models/vote.rb index 8852fa5..21b5408 100644 --- a/app/models/vote.rb +++ b/app/models/vote.rb @@ -71,16 +71,6 @@ class Vote < ActiveRecord::Base confirmed == 1 end - def votestring=(string="") - candidate_ids = voter.election.candidates.sort.collect \ - { |candidate| candidate.id.to_i } - - rel_votes = string.split("").collect { |vote| vote.to_i } - - # covert relative orders to absolute candidate ids - self.votes = rel_votes.collect { |vote| candidate_ids[ vote - 1 ] } - end - def votestring # create a mapping of candidates ids and the relative order of the # candidates as they appear when sorted alphabetically @@ -90,7 +80,7 @@ class Vote < ActiveRecord::Base end # assemble the votestring - self.votes.collect {|v| cand_relnums[v]}.join("") + self.votes.collect {|v| (cand_relnums[v] + 64).chr}.join("") end # the following subroutine is used for quickvotes, but need for elections now diff --git a/app/views/quickvote/_methodinfo_approval.rhtml b/app/views/common/_methodinfo_approval.rhtml similarity index 100% rename from app/views/quickvote/_methodinfo_approval.rhtml rename to app/views/common/_methodinfo_approval.rhtml diff --git a/app/views/quickvote/_methodinfo_borda.rhtml b/app/views/common/_methodinfo_borda.rhtml similarity index 100% rename from app/views/quickvote/_methodinfo_borda.rhtml rename to app/views/common/_methodinfo_borda.rhtml diff --git a/app/views/quickvote/_methodinfo_condorcet.rhtml b/app/views/common/_methodinfo_condorcet.rhtml similarity index 58% rename from app/views/quickvote/_methodinfo_condorcet.rhtml rename to app/views/common/_methodinfo_condorcet.rhtml index b1e7005..5fb29e0 100644 --- a/app/views/quickvote/_methodinfo_condorcet.rhtml +++ b/app/views/common/_methodinfo_condorcet.rhtml @@ -11,6 +11,15 @@ will be the winner.

"Simple Condorcet" to distinguish it from the Schulze method which is another Condorcet system.

-<%= render :partial => 'pref_tables' %> +<% candidates = @election.ssd_result.ranked_candidates.flatten -%> +<% if candidates.size <= 7 -%> + <%= render_partial 'common/pref_tables' %> +<% else %> + + There are too many candidates in your elections to show the result + tables. <%= link_to "Click here", { :action => 'pref_tables', :id => + @voter.password }, :popup => [] %> to view details. + +<% end -%> diff --git a/app/views/quickvote/_methodinfo_plurality.rhtml b/app/views/common/_methodinfo_plurality.rhtml similarity index 100% rename from app/views/quickvote/_methodinfo_plurality.rhtml rename to app/views/common/_methodinfo_plurality.rhtml diff --git a/app/views/quickvote/_methodinfo_runoff.rhtml b/app/views/common/_methodinfo_runoff.rhtml similarity index 100% rename from app/views/quickvote/_methodinfo_runoff.rhtml rename to app/views/common/_methodinfo_runoff.rhtml diff --git a/app/views/common/_methodinfo_ssd.rhtml b/app/views/common/_methodinfo_ssd.rhtml new file mode 100644 index 0000000..0c8dc95 --- /dev/null +++ b/app/views/common/_methodinfo_ssd.rhtml @@ -0,0 +1,36 @@ +

The full results of this election ranked the candidates in order of +preference (from most preferred to least preferred):

+ +
    +<% @election.ssd_result.ranked_candidates.each do |place| %> +
  1. <%= h(place.collect {|c| @names[c].capitalize}.join( " and " )) %> + <%= "(TIE)" if place.length > 1 %>
  2. +<% end %> +
+ + +
+

About the Schulze Method

+ +

The <%= link_to "Schulze method", +"http://en.wikipedia.org/wiki/Schulze_method" %> is a preferential +voting system. It is based on the Condorcet method but includes a set of +methods for resolving "circular" defeats.

+ +

The Schulze method is also known as Schwartz Sequential Dropping +(SSD), Cloneproof Schwartz Sequential Dropping (CSSD), Beatpath Method, +Beatpath Winner, Path Voting, and Path Winner.

+
+ + +<% candidates = @election.ssd_result.ranked_candidates.flatten -%> +<% if candidates.size <= 7 -%> + <%= render_partial 'common/pref_tables' %> +<% else %> + + There are too many candidates in your elections to show the result + tables. <%= link_to "Click here", { :action => 'pref_tables', :id => + @voter.password }, :popup => [] %> to view details. + +<% end -%> + diff --git a/app/views/quickvote/_pref_tables.rhtml b/app/views/common/_pref_tables.rhtml similarity index 97% rename from app/views/quickvote/_pref_tables.rhtml rename to app/views/common/_pref_tables.rhtml index b9d41ec..7701985 100644 --- a/app/views/quickvote/_pref_tables.rhtml +++ b/app/views/common/_pref_tables.rhtml @@ -3,8 +3,6 @@ <% matrix = @election.ssd_result.matrix %> <% victories = @election.ssd_result.victories_and_ties %> -<% if candidates.size <= 7 -%> -

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.

@@ -63,5 +61,4 @@ parenthesis.

<% end -%> -<% end -%> diff --git a/app/views/quickvote/_result.rhtml b/app/views/common/_result.rhtml similarity index 100% rename from app/views/quickvote/_result.rhtml rename to app/views/common/_result.rhtml diff --git a/app/views/quickvote/_result_box.rhtml b/app/views/common/_result_box.rhtml similarity index 79% rename from app/views/quickvote/_result_box.rhtml rename to app/views/common/_result_box.rhtml index 917dbd4..528885d 100644 --- a/app/views/quickvote/_result_box.rhtml +++ b/app/views/common/_result_box.rhtml @@ -10,9 +10,9 @@ <% unless @election.election_method == method -%> -<%= render :partial => 'result', :object => @results[method]%> +<%= render :partial => 'common/result', :object => @results[method]%> <% end -%> -<%= render :partial => 'methodinfo_' + method, +<%= render :partial => 'common/methodinfo_' + method, :object => @results[method] %> diff --git a/app/views/voter/_sortable_vote.rhtml b/app/views/common/_sortable_vote.rhtml similarity index 66% rename from app/views/voter/_sortable_vote.rhtml rename to app/views/common/_sortable_vote.rhtml index 2452476..6876966 100644 --- a/app/views/voter/_sortable_vote.rhtml +++ b/app/views/common/_sortable_vote.rhtml @@ -1,8 +1,3 @@ -

Your Vote

- -

Please vote by dragging items in the list below into your preferred -order.

-
    <% for ranking in @voter.vote.rankings %> @@ -18,6 +13,3 @@ order.

    :url => { :action => "sort_candidates", :id => @voter.vote.id }, :complete => visual_effect(:highlight, 'rankings-list') %> -
    -<%= button_to "Confirm Vote", :action => 'review', :id => @voter.password %> -
    diff --git a/app/views/common/pref_tables.rhtml b/app/views/common/pref_tables.rhtml new file mode 100644 index 0000000..1215c7b --- /dev/null +++ b/app/views/common/pref_tables.rhtml @@ -0,0 +1 @@ +<%= render_partial 'common/pref_tables' %> diff --git a/app/views/layouts/basic.rhtml b/app/views/layouts/basic.rhtml new file mode 100644 index 0000000..a7e9327 --- /dev/null +++ b/app/views/layouts/basic.rhtml @@ -0,0 +1,24 @@ + + + + <%= @page_title || "Selectricity" %> + <%= stylesheet_link_tag "common", :media => "all" %> + <%= stylesheet_link_tag *(@stylesheets) %> + <%begin%> + <%= stylesheet_link_tag "ie6hacks", :media => "all" if + request.user_agent =~ /msie\s(5\.[5-9]|[6]\.[0-9]*).*(win)/i %> + <%rescue NoMethodError%> + <%end%> + <%= javascript_include_tag "prototype", "effects", "dragdrop", "controls" %> + + + +
    + <%= @content_for_layout %> +
    + +
    + <%= render_partial 'layouts/footer' %> +
+ + diff --git a/app/views/layouts/frontpage.rhtml b/app/views/layouts/frontpage.rhtml index e227e87..570a4f3 100644 --- a/app/views/layouts/frontpage.rhtml +++ b/app/views/layouts/frontpage.rhtml @@ -13,10 +13,10 @@