impressiongram 0.0.0 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,68 +0,0 @@
1
- module Impressionist
2
- module Impressionable
3
- def is_impressionable
4
- has_many :impressions, :as=>:impressionable
5
- include InstanceMethods
6
- end
7
-
8
- module InstanceMethods
9
- def impressionable?
10
- true
11
- end
12
-
13
- def impressionist_count(options={})
14
- options.reverse_merge!(:filter=>:request_hash, :start_date=>nil, :end_date=>Time.now)
15
- imps = options[:start_date].blank? ? impressions : impressions.where("created_at>=? and created_at<=?",options[:start_date],options[:end_date])
16
- if options[:filter]!=:all
17
- imps = imps.select(options[:filter]).group(options[:filter])
18
- end
19
- imps.all.size
20
- end
21
-
22
- def impression_gram(millisecond=false, time_format="seconds", graph_label="", minute_increments, hours_covered, hour_offset)
23
- time_formatter = case time_format
24
- when "seconds" then "%s"
25
- when "hour/minute" then "%h:%M %p"
26
- end
27
- def key_formatter(millisecond, time_formatter, minute_increments)
28
- key = minute_increments.minutes.ago.strftime(time_formatter).to_i
29
- if millisecond
30
- key = key*1000
31
- end
32
- return key
33
- end
34
- hits_label = {:label => graph_label}
35
- hits_by_interval = []
36
- minute = 0 + offset*60
37
- while minute < (offset+60*hours_covered)
38
- if minute == offset*60
39
- hits_by_interval << [ key_formatter(millisecond, time_formatter, minute_increments), impressions.where("created_at >= ?", minute_increments.minutes.ago).count]
40
- else
41
- 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 ]
42
- end
43
- minute += minute_increments
44
- end
45
- hits_hash = {:data => hits_by_hour}
46
- return hits_label.merge!(hits_hash)
47
- end
48
-
49
-
50
- # OLD METHODS - DEPRECATE IN V0.5
51
- def impression_count(start_date=nil,end_date=Time.now)
52
- impressionist_count({:start_date=>start_date, :end_date=>end_date, :filter=>:all})
53
- end
54
-
55
- def unique_impression_count(start_date=nil,end_date=Time.now)
56
- impressionist_count({:start_date=>start_date, :end_date=>end_date, :filter=> :request_hash})
57
- end
58
-
59
- def unique_impression_count_ip(start_date=nil,end_date=Time.now)
60
- impressionist_count({:start_date=>start_date, :end_date=>end_date, :filter=> :ip_address})
61
- end
62
-
63
- def unique_impression_count_session(start_date=nil,end_date=Time.now)
64
- impressionist_count({:start_date=>start_date, :end_date=>end_date, :filter=> :session_hash})
65
- end
66
- end
67
- end
68
- end