Class: SplitCat::HypothesisSubject

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/split_cat/hypothesis_subject.rb

Class Method Summary collapse

Class Method Details

.subject_counts(experiment) ⇒ Object

Returns a hash of name => count



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/models/split_cat/hypothesis_subject.rb', line 6

def self.subject_counts( experiment )
  counts = HashWithIndifferentAccess.new

  # Run the query and load the results into a hash of hypothesis id => counts

  sql = subject_count_sql( experiment )
  ActiveRecord::Base.connection.execute( sql ).each do |row|
    subject_count_row( counts, row )
  end

  # Translate ID keys to name keys

  experiment.hypotheses.each do |hypothesis|
    counts[ hypothesis.name.to_sym ] = counts.delete( hypothesis.id ) || 0
 end

  return counts
end