Class: SirTracksAlot::Reports::ActorActivityReport

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

Defined Under Namespace

Modules: Helpers Classes: HTML

Constant Summary collapse

COLUMN_NAMES =
['target', '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



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/sir_tracks_alot/reports/actor_activity_report.rb', line 9

def setup
  super
  counts = {}
  options.column_names ||= COLUMN_NAMES
  
  activities = Activity.find(:owner => options.owner, :actor => options.actor)
  
  activities.each do |activity|
    counts[activity.target] ||= [0,0]
    counts[activity.target][0] += activity.views
    counts[activity.target][1] += activity.visits(options.session_duration)          
  end

  table = Table(options.column_names) do |t|
    counts.each do |target, count|
      t << [target, count[0], count[1]]
    end          
  end

  table.sort_rows_by!('page views', :order => :descending)

  self.data = table
end