Module: ActiveReporter::Report::Metrics
- Included in:
- ActiveReporter::Report
- Defined in:
- lib/active_reporter/report/metrics.rb
Instance Method Summary collapse
- #aggregators ⇒ Object
- #all_aggregators ⇒ Object
- #base_relation ⇒ Object
- #calculators ⇒ Object
- #dimensions ⇒ Object
- #evaluators ⇒ Object
-
#fields ⇒ Object
The grouper dimensions followed by the calculator, tracker, and evaluator names that appear alongside them in report rows.
- #filters ⇒ Object
- #grouper_names ⇒ Object
- #groupers ⇒ Object
- #groups ⇒ Object
- #records ⇒ Object
- #relation ⇒ Object
- #relators ⇒ Object
- #total_report ⇒ Object
- #trackers ⇒ Object
Instance Method Details
#aggregators ⇒ Object
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_aggregators ⇒ Object
62 63 64 |
# File 'lib/active_reporter/report/metrics.rb', line 62 def all_aggregators aggregators.merge(calculators).merge(trackers).merge(evaluators) end |
#base_relation ⇒ Object
34 35 36 |
# File 'lib/active_reporter/report/metrics.rb', line 34 def base_relation params.fetch(:relation, report_model.all) end |
#calculators ⇒ Object
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 |
#dimensions ⇒ Object
8 9 10 |
# File 'lib/active_reporter/report/metrics.rb', line 8 def dimensions @dimensions ||= build_axes(self.class.dimensions) end |
#evaluators ⇒ Object
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 |
#fields ⇒ Object
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 |
#filters ⇒ Object
26 27 28 |
# File 'lib/active_reporter/report/metrics.rb', line 26 def filters @filters ||= dimensions.values.select(&:filtering?) end |
#grouper_names ⇒ Object
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 |
#groupers ⇒ Object
22 23 24 |
# File 'lib/active_reporter/report/metrics.rb', line 22 def groupers @groupers ||= dimensions.values_at(*grouper_names) end |
#groups ⇒ Object
46 47 48 |
# File 'lib/active_reporter/report/metrics.rb', line 46 def groups @groups ||= groupers.reduce(records) { |relation, dimension| dimension.group(relation) } end |
#records ⇒ Object
42 43 44 |
# File 'lib/active_reporter/report/metrics.rb', line 42 def records @records ||= filters.reduce(relation) { |relation, dimension| dimension.filter(relation) } end |
#relation ⇒ Object
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 |
#relators ⇒ Object
30 31 32 |
# File 'lib/active_reporter/report/metrics.rb', line 30 def relators filters | groupers end |
#total_report ⇒ Object
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 |
#trackers ⇒ Object
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 |