added comment count correlation
This commit is contained in:
parent
5f324f73a0
commit
6a5f448853
2 changed files with 22 additions and 3 deletions
|
|
@ -21,6 +21,17 @@ class Statistics
|
|||
SQL
|
||||
end
|
||||
|
||||
def comments_count_sql
|
||||
<<SQL
|
||||
SELECT users.id AS id, count(comments.id) AS count
|
||||
FROM users
|
||||
JOIN people ON people.owner_id = users.id
|
||||
LEFT OUTER JOIN comments ON people.id = comments.author_id
|
||||
#{self.where_clause_sql}
|
||||
GROUP BY users.id
|
||||
SQL
|
||||
end
|
||||
|
||||
def invites_sent_count_sql
|
||||
<<SQL
|
||||
SELECT users.id AS id, count(invitations.id) AS count
|
||||
|
|
@ -90,13 +101,12 @@ SQL
|
|||
|
||||
def generate_correlations
|
||||
result = {}
|
||||
[:posts_count, :invites_sent_count, #:tags_followed_count,
|
||||
[:posts_count, :comments_count, :invites_sent_count, #:tags_followed_count,
|
||||
:mentions_count, :contacts_sharing_with_count].each do |metric|
|
||||
result[metric] = self.correlate(metric,:sign_in_count)
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
|
||||
def correlation(x_array, y_array)
|
||||
x = x_array.to_scale
|
||||
|
|
|
|||
|
|
@ -20,6 +20,15 @@ describe Statistics do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#comments_count_sql' do
|
||||
it "pulls back an array of post counts and ids" do
|
||||
sm = Factory.create(:status_message, :author => alice.person)
|
||||
bob.comment("sup", :post => sm)
|
||||
User.connection.select_all(@stats.comments_count_sql).should =~ @result
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
describe '#invites_sent_count_sql' do
|
||||
it "pulls back an array of invite counts and ids" do
|
||||
Invitation.batch_invite(["a@a.com"], :sender => bob, :aspect => bob.aspects.first, :service => 'email')
|
||||
|
|
@ -64,7 +73,7 @@ describe Statistics do
|
|||
end
|
||||
end
|
||||
|
||||
["posts_count", "invites_sent_count", "tags_followed_count",
|
||||
["posts_count", "comments_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
|
||||
|
|
|
|||
Loading…
Reference in a new issue