Class: SplitCat::GoalSubject
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- SplitCat::GoalSubject
- Defined in:
- app/models/split_cat/goal_subject.rb
Class Method Summary collapse
-
.subject_counts(experiment) ⇒ Object
Returns a hash of goal name => hypothesis name => count.
Class Method Details
.subject_counts(experiment) ⇒ Object
Returns a hash of goal name => hypothesis name => count
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/models/split_cat/goal_subject.rb', line 6 def self.subject_counts( experiment ) counts = HashWithIndifferentAccess.new # Run the query sql = subject_count_sql( experiment ) ActiveRecord::Base.connection.execute( sql ).each do |row| subject_count_row( counts, row ) end # Translate ID keys to name symbols experiment.goals.each do |goal| unless hash = counts[ goal.name ] = counts.delete( goal.id ) counts[ goal.name ] = HashWithIndifferentAccess.new else experiment.hypotheses.each do |h| hash[ h.name ] = hash.delete( h.id ) end end end return counts end |