From e691b72dd0a973603c48999f00860dccead48f46 Mon Sep 17 00:00:00 2001 From: Luke Baker Date: Thu, 22 Sep 2011 16:43:31 -0400 Subject: [PATCH] add active_loser scope for votes --- app/models/vote.rb | 1 + lib/tasks/test_api.rake | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/models/vote.rb b/app/models/vote.rb index 015279f..e69cd29 100644 --- a/app/models/vote.rb +++ b/app/models/vote.rb @@ -17,6 +17,7 @@ class Vote < ActiveRecord::Base named_scope :with_question, lambda { |*args| {:conditions => {:question_id => args.first }} } named_scope :with_voter_ids, lambda { |*args| {:conditions => {:voter_id=> args.first }} } named_scope :active, :include => :choice, :conditions => { 'choices.active' => true } + named_scope :active_loser, :include => :loser_choice, :conditions => { 'choices.active' => true } default_scope :conditions => "#{table_name}.valid_record = 1" diff --git a/lib/tasks/test_api.rake b/lib/tasks/test_api.rake index af4a366..a3c256a 100644 --- a/lib/tasks/test_api.rake +++ b/lib/tasks/test_api.rake @@ -545,13 +545,14 @@ namespace :test_api do end return error_message.blank? ? [success_message, false] : [error_message, true] end + def check_each_choice_appears_within_n_stddevs(question) error_message ="" success_message = "Each choice has appeared n times, where n falls within 6 stddevs of the mean number of appearances for a question " + "(Note: this applies only to seed choices (not user submitted) and choices currently marked active)" wins_by_choice_id = question.votes.active.count(:group => :choice_id) - losses_by_choice_id= question.votes.active.count(:conditions => "loser_choice_id IS NOT NULL", :group => :loser_choice_id) + losses_by_choice_id= question.votes.active_loser.count(:group => :loser_choice_id) #Rails returns an ordered hash, which doesn't allow for blocks to change merging logic. #A little hack to create a normal hash @@ -579,6 +580,7 @@ namespace :test_api do return error_message.blank? ? [success_message, false] : [error_message, true] end + def check_each_choice_equally_likely_to_appear_left_or_right(question) error_message = "" success_message = "All choices have equal probability of appearing on left or right (within error params)" -- libgit2 0.21.2