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:
Sarah Mei 2011-01-21 22:03:21 -08:00
parent a3bc8932d4
commit 225e5fc9d7
2 changed files with 47 additions and 55 deletions

View file

@ -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

View file

@ -1,24 +1,23 @@
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(); @sql = ActiveRecord::Base.connection
end
def users_with_x_posts(count) def users_with_x_posts(count)
@sql.execute( @sql.execute(
@ -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=invitations, count=#{@invitations}"
puts "event=statistic, type=contacts, active_count=#{contacts_active}" puts "event=statistic, type=contacts, active_count=#{@contacts_active}"
puts "event=statistic, type=contacts, pending_count=#{contacts_pending}" puts "event=statistic, type=contacts, pending_count=#{@contacts_pending}"
puts "event=statistic, type=aspect, count=#{aspects}" puts "event=statistic, type=aspect, count=#{@aspects}"
end end
end end