Skip to content

Instantly share code, notes, and snippets.

@micho
Last active December 16, 2015 08:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save micho/5403255 to your computer and use it in GitHub Desktop.
Save micho/5403255 to your computer and use it in GitHub Desktop.
Describes activity rates by organization with subscription.
# Possible anomaly: If the org was created long ago but only active recently, project_recent will always be low
# Proposed solution: Build a semirecent_activity field and use that for projections, which will track 6-12 months
def days_ago(o); (Time.now - o.created_at) / 1.day; end
def projected_recent(o); (o.total_activities / days_ago(o)).to_i * 14; end
# Get active subscriptions with a chargify id (to exclude cancelations and manual subscriptions)
ss = Subscription.where(state: nil).reject { |s| s.payment_gateway_id.nil? }; 0
# Get orgs. Tweak the filters to restrict your results list
oo = ss.map { |s| Organization.find_by_subscription_id s.id }.compact; 0
ooo = oo.select { |o| o.total_activities >= 0 }.sort_by(&:total_activities).reverse; 0
ooo.each {|o| puts [o.total_activities, projected_recent(o), o.recent_activities, o.name].join("\t") };0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment