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
- #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
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_aggregators ⇒ Object
60 61 62 |
# File 'lib/active_reporter/report/metrics.rb', line 60 def all_aggregators aggregators.merge(calculators).merge(trackers).merge(evaluators) end |
#base_relation ⇒ Object
32 33 34 |
# File 'lib/active_reporter/report/metrics.rb', line 32 def base_relation params.fetch(:relation, report_model.all) end |
#calculators ⇒ Object
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 |
#dimensions ⇒ Object
6 7 8 |
# File 'lib/active_reporter/report/metrics.rb', line 6 def dimensions @dimensions ||= build_axes(self.class.dimensions) end |
#evaluators ⇒ Object
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 |
#fields ⇒ Object
64 65 66 |
# File 'lib/active_reporter/report/metrics.rb', line 64 def fields [groupers, calculators.keys, trackers.keys, evaluators.keys].inject(&:merge) end |
#filters ⇒ Object
24 25 26 |
# File 'lib/active_reporter/report/metrics.rb', line 24 def filters @filters ||= dimensions.values.select(&:filtering?) end |
#grouper_names ⇒ Object
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 |
#groupers ⇒ Object
20 21 22 |
# File 'lib/active_reporter/report/metrics.rb', line 20 def groupers @groupers ||= dimensions.values_at(*grouper_names) end |
#groups ⇒ Object
44 45 46 |
# File 'lib/active_reporter/report/metrics.rb', line 44 def groups @groups ||= groupers.reduce(records) { |relation, dimension| dimension.group(relation) } end |
#records ⇒ Object
40 41 42 |
# File 'lib/active_reporter/report/metrics.rb', line 40 def records @records ||= filters.reduce(relation) { |relation, dimension| dimension.filter(relation) } end |
#relation ⇒ Object
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 |
#relators ⇒ Object
28 29 30 |
# File 'lib/active_reporter/report/metrics.rb', line 28 def relators filters | groupers end |
#total_report ⇒ Object
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 |
#trackers ⇒ Object
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 |