Refactored quickvotes result calculator from the controller to the model. TODO: Run...
[selectricity] / app / controllers / quickvote_controller.rb
index f5ab58128caa2d0a8ae03a67fa9994ab0119a2ed..acbf012ff5cb3df503371f59f4b8d71c466e567f 100644 (file)
@@ -143,33 +143,8 @@ class QuickvoteController < ApplicationController
 
   def results
     @election = ident_to_quickvote(params[:ident])
-
-    # initalize the tallies to empty arrays
-    preference_tally = Array.new
-    plurality_tally = Array.new
-    approval_tally = Array.new
-
-    @election.voters.each do |voter|
-      # skip if the voter has not voted or has an unconfirmed vote
-      next unless voter.voted?
-      
-      plurality_tally << voter.vote.rankings.sort[0].candidate.id
-      approval_tally << voter.vote.rankings.sort[0..1].collect \
-        { |ranking| ranking.candidate.id }
-      preference_tally << voter.vote.rankings.sort.collect \
-        { |ranking| ranking.candidate.id }
-    end
-    @plurality_result = PluralityVote.new(plurality_tally).result
-    @approval_result = ApprovalVote.new(approval_tally).result
-    @condorcet_result = PureCondorcetVote.new(preference_tally).result
-    @ssd_result = CloneproofSSDVote.new(preference_tally).result
-    @borda_result = BordaVote.new(preference_tally).result
-    #@runoff_result = InstantRunoffVote.new(preference_tally).result
-    #@runoff_results = PluralityVote.new(preference_tally).result
-
-
-    @candidates = {} 
+    @election.results
+    @candidates = {}
     @election.candidates.each {|c| @candidates[c.id] = c}
   end
 

Benjamin Mako Hill || Want to submit a patch?