Module: ActiveReporter::Report::Metrics

Included in:
ActiveReporter::Report
Defined in:
lib/active_reporter/report/metrics.rb

Instance Method Summary collapse

Instance Method Details

#aggregatorsObject



12
13
14
# File 'lib/active_reporter/report/metrics.rb', line 12

def aggregators
  @aggregators ||= build_axes(self.class.aggregators.slice(*Array(params.fetch(:aggregators, self.class.aggregators.keys)).collect(&:to_sym)))
end

#all_aggregatorsObject



62
63
64
# File 'lib/active_reporter/report/metrics.rb', line 62

def all_aggregators
  aggregators.merge(calculators).merge(trackers).merge(evaluators)
end

#base_relationObject



34
35
36
# File 'lib/active_reporter/report/metrics.rb', line 34

def base_relation
  params.fetch(:relation, report_model.all)
end

#calculatorsObject



50
51
52
# File 'lib/active_reporter/report/metrics.rb', line 50

def calculators
  @calculators ||= build_axes(self.class.calculators.slice(*(Array(params[:calculators]) + Array(params[:aggregators])).collect(&:to_sym).uniq))
end

#dimensionsObject



8
9
10
# File 'lib/active_reporter/report/metrics.rb', line 8

def dimensions
  @dimensions ||= build_axes(self.class.dimensions)
end

#evaluatorsObject



58
59
60
# File 'lib/active_reporter/report/metrics.rb', line 58

def evaluators
  @evaluators ||= build_axes(self.class.evaluators.slice(*(Array(params[:evaluators]) + Array(params[:aggregators])).collect(&:to_sym).uniq))
end

#fieldsObject

The grouper dimensions followed by the calculator, tracker, and evaluator names that appear alongside them in report rows.



68
69
70
# File 'lib/active_reporter/report/metrics.rb', line 68

def fields
  [groupers, calculators.keys, trackers.keys, evaluators.keys].flatten
end

#filtersObject



26
27
28
# File 'lib/active_reporter/report/metrics.rb', line 26

def filters
  @filters ||= dimensions.values.select(&:filtering?)
end

#grouper_namesObject



16
17
18
19
20
# File 'lib/active_reporter/report/metrics.rb', line 16

def grouper_names
  names = params.fetch(:groupers, [dimensions.except(:totals).keys.first])
  names = names.is_a?(Hash) ? names.values : Array.wrap(names).compact
  names.map(&:to_sym)
end

#groupersObject



22
23
24
# File 'lib/active_reporter/report/metrics.rb', line 22

def groupers
  @groupers ||= dimensions.values_at(*grouper_names)
end

#groupsObject



46
47
48
# File 'lib/active_reporter/report/metrics.rb', line 46

def groups
  @groups ||= groupers.reduce(records) { |relation, dimension| dimension.group(relation) }
end

#recordsObject



42
43
44
# File 'lib/active_reporter/report/metrics.rb', line 42

def records
  @records ||= filters.reduce(relation) { |relation, dimension| dimension.filter(relation) }
end

#relationObject



38
39
40
# File 'lib/active_reporter/report/metrics.rb', line 38

def relation
  @relation ||= relators.reduce(base_relation) { |relation, dimension| dimension.relate(relation) }
end

#relatorsObject



30
31
32
# File 'lib/active_reporter/report/metrics.rb', line 30

def relators
  filters | groupers
end

#total_reportObject



72
73
74
# File 'lib/active_reporter/report/metrics.rb', line 72

def total_report
  @total_report ||= self.class.new(@params.except(:calculators).merge({ groupers: :totals })) unless @total_data.present?
end

#trackersObject



54
55
56
# File 'lib/active_reporter/report/metrics.rb', line 54

def trackers
  @trackers ||= build_axes(self.class.trackers.slice(*(Array(params[:trackers]) + Array(params[:aggregators])).collect(&:to_sym).uniq))
end