Class: CohortScope::BigCohort

Inherits:
Cohort
  • Object
show all
Defined in:
lib/cohort_scope/big_cohort.rb

Constant Summary

Constants inherited from Cohort

Cohort::IMPOSSIBLE

Class Method Summary collapse

Methods inherited from Cohort

#expr, #initialize

Constructor Details

This class inherits a constructor from CohortScope::Cohort

Class Method Details

.reduce_characteristics(active_record, characteristics) ⇒ Object

Reduce characteristics by removing them one by one and counting the results.

The characteristic whose removal leads to the highest record count is removed from the overall characteristic set.



6
7
8
9
10
11
12
13
14
15
# File 'lib/cohort_scope/big_cohort.rb', line 6

def self.reduce_characteristics(active_record, characteristics)
  if characteristics.keys.length < 2
    return {}
  end
  most_restrictive_characteristic = characteristics.keys.max_by do |key|
    conditions = CohortScope.conditions_for characteristics.except(key)
    active_record.where(conditions).count
  end
  characteristics.except most_restrictive_characteristic
end