Module: ActiveReporter::Report::Metrics

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

Instance Method Summary collapse

Instance Method Details

#aggregatorsObject



10
11
12
# File 'lib/active_reporter/report/metrics.rb', line 10

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

#all_aggregatorsObject



60
61
62
# File 'lib/active_reporter/report/metrics.rb', line 60

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

#base_relationObject



32
33
34
# File 'lib/active_reporter/report/metrics.rb', line 32

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

#calculatorsObject



48
49
50
# File 'lib/active_reporter/report/metrics.rb', line 48

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

#dimensionsObject



6
7
8
# File 'lib/active_reporter/report/metrics.rb', line 6

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

#evaluatorsObject



56
57
58
# File 'lib/active_reporter/report/metrics.rb', line 56

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

#fieldsObject



64
65
66
# File 'lib/active_reporter/report/metrics.rb', line 64

def fields
  [groupers, calculators.keys, trackers.keys, evaluators.keys].inject(&:merge)
end

#filtersObject



24
25
26
# File 'lib/active_reporter/report/metrics.rb', line 24

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

#grouper_namesObject



14
15
16
17
18
# File 'lib/active_reporter/report/metrics.rb', line 14

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



20
21
22
# File 'lib/active_reporter/report/metrics.rb', line 20

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

#groupsObject



44
45
46
# File 'lib/active_reporter/report/metrics.rb', line 44

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

#recordsObject



40
41
42
# File 'lib/active_reporter/report/metrics.rb', line 40

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

#relationObject



36
37
38
# File 'lib/active_reporter/report/metrics.rb', line 36

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

#relatorsObject



28
29
30
# File 'lib/active_reporter/report/metrics.rb', line 28

def relators
  filters | groupers
end

#total_reportObject



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

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

#trackersObject



52
53
54
# File 'lib/active_reporter/report/metrics.rb', line 52

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