Last active
December 16, 2015 08:08
-
-
Save micho/5403255 to your computer and use it in GitHub Desktop.
Describes activity rates by organization with subscription.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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