Class: SirTracksAlot::Reports::FilterReport

Inherits:
SirTracksAlotReport show all
Defined in:
lib/sir_tracks_alot/reports/filter_report.rb

Direct Known Subclasses

RootStemReport

Defined Under Namespace

Modules: Helpers Classes: HTML

Constant Summary collapse

COLUMN_NAMES =
['title', 'page views', 'visits']

Instance Attribute Summary

Attributes inherited from SirTracksAlotReport

#all

Attributes inherited from Report

#all

Instance Method Summary collapse

Methods inherited from Report

build_rows

Instance Method Details

#setupObject

Build up reports by filtering things. Filters are applied and assigned a row title.

:filters =

'Title' => {:category => 'category', :target => /\/categories/

}



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/sir_tracks_alot/reports/filter_report.rb', line 15

def setup
  super
  
  counts = {}
  options.filters ||= {}
  options.column_names ||= COLUMN_NAMES
  
  options.filters.each do |title, options_for_find|
    Count.filter(options_for_find.merge(:owner => options.owner)).each do |count|
      count.summaries.each do |summary|
        counts[title] ||= [0,0]
        counts[title][0] += summary.visits.to_i
        counts[title][1] += summary.views.to_i
      end
    end
  end

  table = Table(options.column_names) do |t|
    counts.each do |title, n|
      t << [title, n[0], n[1]]
    end
  end
  
  table.sort_rows_by!('page views', :order => :descending)
  
  self.data = table
end