Skip to content

Instantly share code, notes, and snippets.

@jfeldstein
Created April 29, 2013 03:25
Show Gist options
  • Select an option

  • Save jfeldstein/5479549 to your computer and use it in GitHub Desktop.

Select an option

Save jfeldstein/5479549 to your computer and use it in GitHub Desktop.
Ruby script for calculating your app's retention curve: http://jfeldstein.com/?p=59
We can make this file beautiful and searchable if this error is corrected: Illegal quoting in line 10.
require 'mysql2'
require 'date'
require 'csv'
# Init values
results = []
(1..48).each do |i|
results[i] = {active_count:0, total_count: 0}
end
# Roll through raw data
lifes = CSV.read("./lifelengths.csv")
(1..48).each do |weeks|
long_enoughs = lifes.select {|l| l[4].to_i > weeks}
results[weeks][:total_count] = long_enoughs.length
results[weeks][:active_count] = (long_enoughs.select {|l| l[3].to_i > weeks}).length
end
puts results[1].keys.unshift('week').join(',')
(1..48).each do |i|
puts results[i].values.unshift(i).join(',')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment