Commit e691b72dd0a973603c48999f00860dccead48f46
1 parent
fd5da224
Exists in
master
and in
1 other branch
add active_loser scope for votes
irregular appearances test was using the active scope which was ensuring the winner was active, but we want to examine all losing choices that are active
Showing
2 changed files
with
4 additions
and
1 deletions
Show diff stats
app/models/vote.rb
... | ... | @@ -17,6 +17,7 @@ class Vote < ActiveRecord::Base |
17 | 17 | named_scope :with_question, lambda { |*args| {:conditions => {:question_id => args.first }} } |
18 | 18 | named_scope :with_voter_ids, lambda { |*args| {:conditions => {:voter_id=> args.first }} } |
19 | 19 | named_scope :active, :include => :choice, :conditions => { 'choices.active' => true } |
20 | + named_scope :active_loser, :include => :loser_choice, :conditions => { 'choices.active' => true } | |
20 | 21 | |
21 | 22 | default_scope :conditions => "#{table_name}.valid_record = 1" |
22 | 23 | ... | ... |
lib/tasks/test_api.rake
... | ... | @@ -545,13 +545,14 @@ namespace :test_api do |
545 | 545 | end |
546 | 546 | return error_message.blank? ? [success_message, false] : [error_message, true] |
547 | 547 | end |
548 | + | |
548 | 549 | def check_each_choice_appears_within_n_stddevs(question) |
549 | 550 | error_message ="" |
550 | 551 | success_message = "Each choice has appeared n times, where n falls within 6 stddevs of the mean number of appearances for a question " + |
551 | 552 | "(Note: this applies only to seed choices (not user submitted) and choices currently marked active)" |
552 | 553 | |
553 | 554 | wins_by_choice_id = question.votes.active.count(:group => :choice_id) |
554 | - losses_by_choice_id= question.votes.active.count(:conditions => "loser_choice_id IS NOT NULL", :group => :loser_choice_id) | |
555 | + losses_by_choice_id= question.votes.active_loser.count(:group => :loser_choice_id) | |
555 | 556 | |
556 | 557 | #Rails returns an ordered hash, which doesn't allow for blocks to change merging logic. |
557 | 558 | #A little hack to create a normal hash |
... | ... | @@ -579,6 +580,7 @@ namespace :test_api do |
579 | 580 | |
580 | 581 | return error_message.blank? ? [success_message, false] : [error_message, true] |
581 | 582 | end |
583 | + | |
582 | 584 | def check_each_choice_equally_likely_to_appear_left_or_right(question) |
583 | 585 | error_message = "" |
584 | 586 | success_message = "All choices have equal probability of appearing on left or right (within error params)" | ... | ... |