This much untested code makes me sad. But I fixed the bug whereby no rake tasks worked because of the require line.
This commit is contained in:
parent
a3bc8932d4
commit
225e5fc9d7
2 changed files with 47 additions and 55 deletions
|
|
@ -44,14 +44,6 @@ GIT
|
||||||
carrierwave (0.5.0)
|
carrierwave (0.5.0)
|
||||||
activesupport (~> 3.0)
|
activesupport (~> 3.0)
|
||||||
|
|
||||||
GIT
|
|
||||||
remote: git://github.com/xiaods/lazy_high_charts.git
|
|
||||||
revision: c63f49ce10e1dad8a0b796233306742a1320e7b0
|
|
||||||
ref: c63f49ce10e1dad8a0b7
|
|
||||||
specs:
|
|
||||||
lazy_high_charts (1.0.8)
|
|
||||||
bundler (~> 1.0)
|
|
||||||
|
|
||||||
PATH
|
PATH
|
||||||
remote: vendor/gems/jasmine
|
remote: vendor/gems/jasmine
|
||||||
specs:
|
specs:
|
||||||
|
|
@ -390,7 +382,6 @@ DEPENDENCIES
|
||||||
jasmine!
|
jasmine!
|
||||||
json (= 1.4.6)
|
json (= 1.4.6)
|
||||||
launchy
|
launchy
|
||||||
lazy_high_charts!
|
|
||||||
mini_magick (= 3.2)
|
mini_magick (= 3.2)
|
||||||
mocha
|
mocha
|
||||||
mongrel
|
mongrel
|
||||||
|
|
|
||||||
|
|
@ -1,31 +1,30 @@
|
||||||
namespace :statistics do
|
namespace :statistics do
|
||||||
|
|
||||||
require 'config/environment'
|
|
||||||
|
|
||||||
desc 'on users: total, active'
|
desc 'on users: total, active'
|
||||||
|
|
||||||
namespace :users do
|
namespace :users do
|
||||||
users = User.where(:getting_started => false).count
|
def set_up_user_stats
|
||||||
incomplete = User.where("getting_started = TRUE AND sign_in_count >= 0").count
|
@users = User.where(:getting_started => false).count
|
||||||
invitations = Invitation.count
|
@incomplete = User.where("getting_started = TRUE AND sign_in_count >= 0").count
|
||||||
contacts_active = Contact.where(:pending => false).count
|
@invitations = Invitation.count
|
||||||
contacts_pending = Contact.count - contacts_active
|
@contacts_active = Contact.where(:pending => false).count
|
||||||
aspects = Aspect.count
|
@contacts_pending = Contact.count - @contacts_active
|
||||||
last_24_hrs = User.where("current_sign_in_at > '#{(Time.now - 1.day).to_date}'").count
|
@aspects = Aspect.count
|
||||||
last_7_d = User.where("current_sign_in_at > '#{(Time.now - 7.days).to_date}'").count
|
@last_24_hrs = User.where("current_sign_in_at > '#{(Time.now - 1.day).to_date}'").count
|
||||||
|
@last_7_d = User.where("current_sign_in_at > '#{(Time.now - 7.days).to_date}'").count
|
||||||
|
|
||||||
notification_off = User.where(:disable_mail=>true).count
|
@notification_off = User.where(:disable_mail=>true).count
|
||||||
notification_off_per = notification_off.to_f / users
|
@notification_off_per = @notification_off.to_f / @users
|
||||||
no_invites = User.where(:invites => 0).count
|
@no_invites = User.where(:invites => 0).count
|
||||||
|
|
||||||
|
@sql = ActiveRecord::Base.connection
|
||||||
|
end
|
||||||
|
|
||||||
@sql = ActiveRecord::Base.connection();
|
|
||||||
|
|
||||||
def users_with_x_posts(count)
|
def users_with_x_posts(count)
|
||||||
@sql.execute(
|
@sql.execute(
|
||||||
"SELECT COUNT(*) FROM (SELECT `people`.guid, COUNT(*) AS posts_sum FROM `people` LEFT JOIN `posts` ON `people`.id = `posts`.person_id GROUP BY `people`.guid) AS t1 WHERE t1.posts_sum = #{count};"
|
"SELECT COUNT(*) FROM (SELECT `people`.guid, COUNT(*) AS posts_sum FROM `people` LEFT JOIN `posts` ON `people`.id = `posts`.person_id GROUP BY `people`.guid) AS t1 WHERE t1.posts_sum = #{count};"
|
||||||
).first[0]
|
).first[0]
|
||||||
end
|
end
|
||||||
|
|
||||||
def users_with_x_posts_today(count)
|
def users_with_x_posts_today(count)
|
||||||
@sql.execute(
|
@sql.execute(
|
||||||
"SELECT COUNT(*) FROM (SELECT `people`.guid, COUNT(*) AS posts_sum FROM `people` LEFT JOIN `posts` ON `people`.id = `posts`.person_id AND `post`.created_at > '#{(Time.now - 1.days).to_date}' GROUP BY `people`.guid) AS t1 WHERE t1.posts_sum = #{count};"
|
"SELECT COUNT(*) FROM (SELECT `people`.guid, COUNT(*) AS posts_sum FROM `people` LEFT JOIN `posts` ON `people`.id = `posts`.person_id AND `post`.created_at > '#{(Time.now - 1.days).to_date}' GROUP BY `people`.guid) AS t1 WHERE t1.posts_sum = #{count};"
|
||||||
|
|
@ -39,12 +38,13 @@ namespace :statistics do
|
||||||
end
|
end
|
||||||
|
|
||||||
task :human => :environment do
|
task :human => :environment do
|
||||||
puts "Users: %i and %i incomplete" % [users, incomplete]
|
set_up_user_stats
|
||||||
puts "Invitations sent: %i" % invitations
|
puts "Users: %i and %i incomplete" % [@users, @incomplete]
|
||||||
puts "Contacts: %i and %i pending" % [contacts_active, contacts_pending]
|
puts "Invitations sent: %i" % @invitations
|
||||||
puts "Aspects: %i" % aspects
|
puts "Contacts: %i and %i pending" % [@contacts_active, @contacts_pending]
|
||||||
puts "Users signed in in last 24h: %i" % last_24_hrs
|
puts "Aspects: %i" % @aspects
|
||||||
puts "Users signed in in last 7d: %i" % last_7_d
|
puts "Users signed in in last 24h: %i" % @last_24_hrs
|
||||||
|
puts "Users signed in in last 7d: %i" % @last_7_d
|
||||||
|
|
||||||
puts "Users with more than one post: %i" % users_with_x_posts(1)
|
puts "Users with more than one post: %i" % users_with_x_posts(1)
|
||||||
puts "Users with more than five post: %i" % users_with_x_posts(5)
|
puts "Users with more than five post: %i" % users_with_x_posts(5)
|
||||||
|
|
@ -65,20 +65,21 @@ namespace :statistics do
|
||||||
end
|
end
|
||||||
|
|
||||||
task :splunk => :environment do
|
task :splunk => :environment do
|
||||||
puts "event=statistic, type=users, count=#{users}, "+
|
set_up_user_stats
|
||||||
"incomplete=#{incomplete}, " +
|
puts "event=statistic, type=users, count=#{@users}, "+
|
||||||
"last_1d=#{last_24_hrs}, "+
|
"incomplete=#{@incomplete}, " +
|
||||||
"last_7d=#{last_7_d}, " +
|
"last_1d=#{@last_24_hrs}, "+
|
||||||
"notification_off=#{notification_off}, "+
|
"last_7d=#{@last_7_d}, " +
|
||||||
"notification_off_%=#{notification_off_per}, "+
|
"notification_off=#{@notification_off}, "+
|
||||||
"no_invites=#{no_invites}"
|
"notification_off_%=#{@notification_off_per}, "+
|
||||||
|
"no_invites=#{@no_invites}"
|
||||||
|
|
||||||
|
|
||||||
puts "event=statistic, type=invitations, count=#{invitations}"
|
|
||||||
puts "event=statistic, type=contacts, active_count=#{contacts_active}"
|
|
||||||
puts "event=statistic, type=contacts, pending_count=#{contacts_pending}"
|
|
||||||
|
|
||||||
puts "event=statistic, type=aspect, count=#{aspects}"
|
puts "event=statistic, type=invitations, count=#{@invitations}"
|
||||||
|
puts "event=statistic, type=contacts, active_count=#{@contacts_active}"
|
||||||
|
puts "event=statistic, type=contacts, pending_count=#{@contacts_pending}"
|
||||||
|
|
||||||
|
puts "event=statistic, type=aspect, count=#{@aspects}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -91,21 +92,21 @@ namespace :statistics do
|
||||||
puts "Comments: %i" % Comment.count
|
puts "Comments: %i" % Comment.count
|
||||||
puts "Photos: %i" % Photo.count
|
puts "Photos: %i" % Photo.count
|
||||||
end
|
end
|
||||||
|
|
||||||
task :splunk => :environment do
|
task :splunk => :environment do
|
||||||
post_count = Post.count
|
post_count = Post.count
|
||||||
public_count = Post.where(:public => true).count
|
public_count = Post.where(:public => true).count
|
||||||
public_per = public_count.to_f/post_count
|
public_per = public_count.to_f/post_count
|
||||||
posts_last_day = Post.where("created_at > '#{(Time.now - 1.days).to_date}'").count
|
posts_last_day = Post.where("created_at > '#{(Time.now - 1.days).to_date}'").count
|
||||||
posts_last_day_public = Post.where("created_at > '#{(Time.now - 1.days).to_date}' AND public = true").count
|
posts_last_day_public = Post.where("created_at > '#{(Time.now - 1.days).to_date}' AND public = true").count
|
||||||
posts_last_day_public_per = posts_last_day_public.to_f/posts_last_day
|
posts_last_day_public_per = posts_last_day_public.to_f/posts_last_day
|
||||||
|
|
||||||
puts "event=statistic, type=posts, count=#{post_count}, " +
|
puts "event=statistic, type=posts, count=#{post_count}, " +
|
||||||
"public_count=#{public_count}, " +
|
"public_count=#{public_count}, " +
|
||||||
"public_%=#{public_per}, " +
|
"public_%=#{public_per}, " +
|
||||||
"last_day=#{posts_last_day}, " +
|
"last_day=#{posts_last_day}, " +
|
||||||
"last_day_public_count=#{posts_last_day_public}, " +
|
"last_day_public_count=#{posts_last_day_public}, " +
|
||||||
"last_day_public_%=#{posts_last_day_public_per}"
|
"last_day_public_%=#{posts_last_day_public_per}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue