Skip to content

Instantly share code, notes, and snippets.

@micho
Created September 6, 2012 16:28
Show Gist options
  • Save micho/3658172 to your computer and use it in GitHub Desktop.
Save micho/3658172 to your computer and use it in GitHub Desktop.
Cohort analysis for First Steps
date = Time.parse("2012-08-15")
(8+15).times do
users = User.where("created_at > ? AND created_at < ?", date, date + 1.day); 0
puts [
date.to_date.to_s,
users.count,
users.select {|u| Array(u.settings["steps"]).length === 0 }.count,
users.select {|u| (1..3) === Array(u.settings["steps"]).length }.count,
users.select {|u| (4..6) === Array(u.settings["steps"]).length }.count,
users.select {|u| (7..10) === Array(u.settings["steps"]).length }.count,
users.select {|u| (11..200) === Array(u.settings["steps"]).length }.count,
users.select {|u| u.total_activities == 0}.count,
users.select {|u| (1..9) === u.total_activities}.count,
users.select {|u| (10..19) === u.total_activities}.count,
users.select {|u| (20..39) === u.total_activities}.count,
users.select {|u| (40..99) === u.total_activities}.count,
users.select {|u| (100..999999) === u.total_activities}.count
].join("\t")
date += 1.day
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment