diff --git a/app/views/admins/correlations.haml b/app/views/admins/correlations.haml index 7deffb129..499b27bbe 100644 --- a/app/views/admins/correlations.haml +++ b/app/views/admins/correlations.haml @@ -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 diff --git a/lib/statistics.rb b/lib/statistics.rb index 89f05d387..d8d25d10f 100644 --- a/lib/statistics.rb +++ b/lib/statistics.rb @@ -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 + < 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 diff --git a/spec/lib/statistics_spec.rb b/spec/lib/statistics_spec.rb index afee71c2f..f2144bbe5 100644 --- a/spec/lib/statistics_spec.rb +++ b/spec/lib/statistics_spec.rb @@ -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