2 model methods for unique impression account - based on unique ip_address & request_hash
This commit is contained in:
parent
ade9f0c3e2
commit
bfb03eeb1c
|
@ -15,6 +15,10 @@ module Impressionist
|
|||
end
|
||||
|
||||
def unique_impression_count(start_date=nil,end_date=Time.now)
|
||||
start_date.blank? ? impressions.group(:request_hash).all.size : impressions.where("created_at>=? and created_at<=?",start_date,end_date).group(:request_hash).all.size
|
||||
end
|
||||
|
||||
def unique_impression_count_ip(start_date=nil,end_date=nil)
|
||||
start_date.blank? ? impressions.group(:ip_address).all.size : impressions.where("created_at>=? and created_at<=?",start_date,end_date).group(:ip_address).all.size
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
PATH
|
||||
remote: /rails_plugins/mine/impressionist
|
||||
specs:
|
||||
impressionist (0.2.3)
|
||||
impressionist (0.2.4)
|
||||
|
||||
GEM
|
||||
remote: http://rubygems.org/
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
impression<%= i %>:
|
||||
impressionable_type: Article
|
||||
impressionable_id: 1
|
||||
request_hash: a<%=i%>
|
||||
ip_address: 127.0.0.<%=i%>
|
||||
created_at: 2011-01-01
|
||||
<% end %>
|
||||
|
@ -10,17 +11,28 @@ impression<%= i %>:
|
|||
impression8:
|
||||
impressionable_type: Article
|
||||
impressionable_id: 1
|
||||
request_hash: a1
|
||||
ip_address: 127.0.0.1
|
||||
created_at: 2010-01-01
|
||||
|
||||
impression9:
|
||||
impressionable_type: Article
|
||||
impressionable_id: 1
|
||||
request_hash: a1
|
||||
ip_address: 127.0.0.1
|
||||
created_at: 2011-01-03
|
||||
|
||||
impression10:
|
||||
impressionable_type: Article
|
||||
impressionable_id: 1
|
||||
request_hash: a9
|
||||
ip_address: 127.0.0.8
|
||||
created_at: 2010-01-01
|
||||
|
||||
impression11:
|
||||
impressionable_type: Article
|
||||
impressionable_id: 1
|
||||
request_hash: a10
|
||||
ip_address: 127.0.0.1
|
||||
created_at: 2010-01-01
|
||||
created_at: 2010-01-01
|
||||
|
|
@ -9,7 +9,7 @@ describe Impression do
|
|||
|
||||
it "should save a blank impression for an Article that has 10 impressions" do
|
||||
@article.impressions.create
|
||||
@article.impressions.size.should eq 11
|
||||
@article.impressions.size.should eq 12
|
||||
end
|
||||
|
||||
it "should save an impression with a message" do
|
||||
|
@ -17,27 +17,31 @@ describe Impression do
|
|||
@article.impressions.last.message.should eq "test message"
|
||||
end
|
||||
|
||||
it "should return the view count with no date range specified" do
|
||||
@article.impression_count.should eq 10
|
||||
it "should return the impression count with no date range specified" do
|
||||
@article.impression_count.should eq 11
|
||||
end
|
||||
|
||||
it "should return unique view count with no date range specified" do
|
||||
@article.unique_impression_count.should eq 7
|
||||
it "should return unique impression count with no date range specified" do
|
||||
@article.unique_impression_count.should eq 9
|
||||
end
|
||||
|
||||
it "should return view count with only start date specified" do
|
||||
it "should return impression count with only start date specified" do
|
||||
@article.impression_count("2011-01-01").should eq 8
|
||||
end
|
||||
|
||||
it "should return view count with whole date range specified" do
|
||||
it "should return impression count with whole date range specified" do
|
||||
@article.impression_count("2011-01-01","2011-01-02").should eq 7
|
||||
end
|
||||
|
||||
it "should return unique view count with only start date specified" do
|
||||
it "should return unique impression count with only start date specified" do
|
||||
@article.unique_impression_count("2011-01-01").should eq 7
|
||||
end
|
||||
|
||||
it "should return unique view count with date range specified" do
|
||||
it "should return unique impression count with date range specified" do
|
||||
@article.unique_impression_count("2011-01-01","2011-01-02").should eq 7
|
||||
end
|
||||
|
||||
it "should return unique impression count using ip address (which in turn eliminates duplicate request_hashes)" do
|
||||
@article.unique_impression_count_ip.should eq 8
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue