dg iz limiting to one month, added contacts sharing with count
This commit is contained in:
parent
288d20b6e8
commit
7fb26c4390
3 changed files with 55 additions and 7 deletions
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
.span-24.last
|
||||
%h1
|
||||
= "Correlations between with Sign In Count"
|
||||
= "Correlations with Sign In Count:"
|
||||
%ul
|
||||
- @correlations_hash.keys.each do |k|
|
||||
%li
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ class Statistics
|
|||
FROM users
|
||||
JOIN people ON people.owner_id = users.id
|
||||
LEFT OUTER JOIN posts ON people.id = posts.author_id
|
||||
#{self.where_clause_sql}
|
||||
GROUP BY users.id
|
||||
SQL
|
||||
end
|
||||
|
|
@ -25,6 +26,7 @@ SQL
|
|||
SELECT users.id AS id, count(invitations.id) AS count
|
||||
FROM users
|
||||
LEFT OUTER JOIN invitations ON users.id = invitations.sender_id
|
||||
#{self.where_clause_sql}
|
||||
GROUP BY users.id
|
||||
SQL
|
||||
end
|
||||
|
|
@ -34,6 +36,7 @@ SQL
|
|||
SELECT users.id AS id, count(tag_followings.id) AS count
|
||||
FROM users
|
||||
LEFT OUTER JOIN tag_followings on users.id = tag_followings.user_id
|
||||
#{self.where_clause_sql}
|
||||
GROUP BY users.id
|
||||
SQL
|
||||
end
|
||||
|
|
@ -44,6 +47,18 @@ SQL
|
|||
FROM users
|
||||
JOIN people on users.id = people.owner_id
|
||||
LEFT OUTER JOIN mentions on people.id = mentions.person_id
|
||||
#{self.where_clause_sql}
|
||||
GROUP BY users.id
|
||||
SQL
|
||||
end
|
||||
|
||||
def contacts_sharing_with_count_sql
|
||||
<<SQL
|
||||
SELECT users.id AS id, count(contacts.id) AS count
|
||||
FROM users
|
||||
JOIN contacts on contacts.user_id = users.id
|
||||
JOIN aspect_memberships on aspect_memberships.contact_id = contacts.id
|
||||
#{self.where_clause_sql}
|
||||
GROUP BY users.id
|
||||
SQL
|
||||
end
|
||||
|
|
@ -52,6 +67,7 @@ SQL
|
|||
<<SQL
|
||||
SELECT users.id AS id, users.sign_in_count AS count
|
||||
FROM users
|
||||
#{self.where_clause_sql}
|
||||
SQL
|
||||
end
|
||||
|
||||
|
|
@ -75,7 +91,7 @@ SQL
|
|||
def generate_correlations
|
||||
result = {}
|
||||
[:posts_count, :invites_sent_count, :tags_followed_count,
|
||||
:mentions_count].each do |metric|
|
||||
:mentions_count, :contacts_sharing_with_count].each do |metric|
|
||||
result[metric] = self.correlate(metric,:sign_in_count)
|
||||
end
|
||||
result
|
||||
|
|
@ -95,6 +111,10 @@ SQL
|
|||
end
|
||||
|
||||
protected
|
||||
def where_clause_sql
|
||||
"where users.created_at > FROM_UNIXTIME(#{(Time.now - 1.month).to_i})"
|
||||
end
|
||||
|
||||
def week_created(n)
|
||||
User.where("username IS NOT NULL").where("created_at > ? and created_at < ?", Time.now - (n+1).weeks, Time.now - n.weeks)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -10,8 +10,7 @@ describe Statistics do
|
|||
{"id" => bob.id , "count" => 1 },
|
||||
{"id" => eve.id , "count" => 0 },
|
||||
{"id" => local_luke.id , "count" => 0 },
|
||||
{"id" => local_leia.id , "count" => 0 },
|
||||
]
|
||||
{"id" => local_leia.id , "count" => 0 }]
|
||||
end
|
||||
|
||||
describe '#posts_count_sql' do
|
||||
|
|
@ -43,6 +42,20 @@ describe Statistics do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#contacts_sharing_with_count_sql' do
|
||||
it "pulls back an array of mentions following counts and ids" do
|
||||
# bob is sharing with alice and eve in the spec setup
|
||||
alice.share_with(eve.person, alice.aspects.first)
|
||||
@result = [{"id" => alice.id , "count" => 2 },
|
||||
{"id" => bob.id , "count" => 2 },
|
||||
{"id" => eve.id , "count" => 1 },
|
||||
{"id" => local_luke.id , "count" => 2 },
|
||||
{"id" => local_leia.id , "count" => 2 }]
|
||||
|
||||
User.connection.select_all(@stats.contacts_sharing_with_count_sql).should =~ @result
|
||||
end
|
||||
end
|
||||
|
||||
describe '#sign_in_count_sql' do
|
||||
it "pulls back an array of sign_in_counts and ids" do
|
||||
bob.sign_in_count = 1
|
||||
|
|
@ -51,6 +64,24 @@ describe Statistics do
|
|||
end
|
||||
end
|
||||
|
||||
["posts_count", "invites_sent_count", "tags_followed_count",
|
||||
"mentions_count", "sign_in_count", "contacts_sharing_with_count" ].each do |method|
|
||||
|
||||
it "#{method}_sql calls where_sql" do
|
||||
@stats.should_receive(:where_clause_sql)
|
||||
|
||||
@stats.send("#{method}_sql".to_sym)
|
||||
end
|
||||
|
||||
if method != "sign_in_count"
|
||||
it "#generate_correlations calss correlate with #{method} and sign_in_count" do
|
||||
@stats.stub(:correlate).and_return(0.5)
|
||||
@stats.should_receive(:correlate).with(method.to_sym,:sign_in_count).and_return(0.75)
|
||||
@stats.generate_correlations
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#correlation" do
|
||||
it 'returns the correlation coefficient' do
|
||||
@stats.correlation([1,2],[1,2]).to_s.should == 1.0.to_s
|
||||
|
|
@ -92,9 +123,6 @@ describe Statistics do
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
context 'todos' do
|
||||
before do
|
||||
pending
|
||||
|
|
|
|||
Loading…
Reference in a new issue