From 5aba48adb5fc188efeddc38675abd5e1e3a88844 Mon Sep 17 00:00:00 2001 From: Date: Mon, 5 May 2008 19:33:06 -0400 Subject: [PATCH] Ordered pref tables so that the smallest margin of vicotry appears first and the largest margin of victory appears last. --- app/controllers/application.rb | 2 +- app/controllers/quickvote_controller.rb | 3 ++- app/views/common/_pref_tables.rhtml | 15 +++++++++------ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/app/controllers/application.rb b/app/controllers/application.rb index 7a725ba..1387b29 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -49,7 +49,7 @@ class ApplicationController < ActionController::Base def sort_candidates @vote = Vote.find(params[:id]) - + @vote.rankings.each do |ranking| ranking.rank = params['rankings-list'].index(ranking.candidate.id.to_s) + 1 ranking.save diff --git a/app/controllers/quickvote_controller.rb b/app/controllers/quickvote_controller.rb index fbf53d3..768bdea 100644 --- a/app/controllers/quickvote_controller.rb +++ b/app/controllers/quickvote_controller.rb @@ -138,6 +138,7 @@ class QuickvoteController < ApplicationController end def confirm + # we need the election to verify that we have the right voter election = QuickVote.ident_to_quickvote(params[:ident]) @@ -145,7 +146,7 @@ class QuickvoteController < ApplicationController @voter = QuickVoter.find(:all, :conditions => ["session_id = ? and election_id = ?", session.session_id, election.id])[0] - + if not @voter # we have not seen this voter before. something is wrong, try # again diff --git a/app/views/common/_pref_tables.rhtml b/app/views/common/_pref_tables.rhtml index 567873b..3a53144 100644 --- a/app/views/common/_pref_tables.rhtml +++ b/app/views/common/_pref_tables.rhtml @@ -2,7 +2,6 @@ <% 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.

@@ -47,13 +46,16 @@ parenthesis.

<% candidates.each do |victor| %> <%= white_list(@names[victor]) %> - <% victories[victor].keys.each do |loser| %> - <% margin = victories[victor][loser]%> - <%= white_list(@names[loser]) %> - <% if margin == 0%> + + <% sorted = victories[victor].sort { |first,second| first[1] <=> second[1] }%> + <% sorted.each do |loserpair| %> + <%= white_list(@names[loserpair[0]]) %> + <% if loserpair[1] == 0%> Tied! <% else -%> - (<%= margin%>) + (<%= loserpair[1] %>) <% end -%> <% end -%> @@ -62,3 +64,4 @@ parenthesis.

+ -- 2.30.2