Module: Impressionist::Impressionable::InstanceMethods

Defined in:
app/models/impressionist/impressionable.rb

Instance Method Summary collapse

Instance Method Details

#impression_count(start_date = nil, end_date = Time.now) ⇒ Object

OLD METHODS - DEPRECATE IN V0.5



51
52
53
# File 'app/models/impressionist/impressionable.rb', line 51

def impression_count(start_date=nil,end_date=Time.now)
  impressionist_count({:start_date=>start_date, :end_date=>end_date, :filter=>:all})
end

#impression_gram(millisecond = false, time_format = "seconds", graph_label = "", minute_increments, hours_covered, hour_offset) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/models/impressionist/impressionable.rb', line 22

def impression_gram(millisecond=false, time_format="seconds", graph_label="", minute_increments, hours_covered, hour_offset)
  time_formatter = case time_format
    when "seconds" then "%s"
    when "hour/minute" then "%h:%M %p"
  end
  def key_formatter(millisecond, time_formatter, minute_increments)
    key = minute_increments.minutes.ago.strftime(time_formatter).to_i
    if millisecond 
      key = key*1000
    end
    return key
  end
  hits_label = {:label => graph_label}
  hits_by_interval = []
  minute = 0 + offset*60
  while minute < (offset+60*hours_covered)
    if minute == offset*60
      hits_by_interval << [ key_formatter(millisecond, time_formatter, minute_increments), impressions.where("created_at >= ?", minute_increments.minutes.ago).count]
    else
      hits_by_interval <<  [ key_formatter(millisecond, time_formatter, (minute_increments+minute)).minute.ago.strftime("%s").to_i*1000, impressions.where("created_at >= ?", (minute_increments+minute).minutes.ago).where("created_at <= ?", minute.minutes.ago).count ]
    end
    minute += minute_increments
  end
  hits_hash = {:data => hits_by_hour}
  return hits_label.merge!(hits_hash)
end

#impressionable?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'app/models/impressionist/impressionable.rb', line 9

def impressionable?
  true
end

#impressionist_count(options = {}) ⇒ Object



13
14
15
16
17
18
19
20
# File 'app/models/impressionist/impressionable.rb', line 13

def impressionist_count(options={})
  options.reverse_merge!(:filter=>:request_hash, :start_date=>nil, :end_date=>Time.now)
  imps = options[:start_date].blank? ? impressions : impressions.where("created_at>=? and created_at<=?",options[:start_date],options[:end_date])
  if options[:filter]!=:all
    imps = imps.select(options[:filter]).group(options[:filter])
  end
  imps.all.size
end

#key_formatter(millisecond, time_formatter, minute_increments) ⇒ Object



27
28
29
30
31
32
33
# File 'app/models/impressionist/impressionable.rb', line 27

def key_formatter(millisecond, time_formatter, minute_increments)
  key = minute_increments.minutes.ago.strftime(time_formatter).to_i
  if millisecond 
    key = key*1000
  end
  return key
end

#unique_impression_count(start_date = nil, end_date = Time.now) ⇒ Object



55
56
57
# File 'app/models/impressionist/impressionable.rb', line 55

def unique_impression_count(start_date=nil,end_date=Time.now)
  impressionist_count({:start_date=>start_date, :end_date=>end_date, :filter=> :request_hash})
end

#unique_impression_count_ip(start_date = nil, end_date = Time.now) ⇒ Object



59
60
61
# File 'app/models/impressionist/impressionable.rb', line 59

def unique_impression_count_ip(start_date=nil,end_date=Time.now)
  impressionist_count({:start_date=>start_date, :end_date=>end_date, :filter=> :ip_address})
end

#unique_impression_count_session(start_date = nil, end_date = Time.now) ⇒ Object



63
64
65
# File 'app/models/impressionist/impressionable.rb', line 63

def unique_impression_count_session(start_date=nil,end_date=Time.now)
  impressionist_count({:start_date=>start_date, :end_date=>end_date, :filter=> :session_hash})
end