def churn_count_past_days(self, days=31): ''' Very simple, just the number of people who delete their subscription within a period (now-30d and now). ''' start = epoch_utc(datetime.now() - timedelta(days=days)) end = epoch_utc(datetime.now()) return len([churn for churn in self.churns if start < churn['created'] < end])
def churn_count_past_days(self, days=31): ''' Very simple, just the number of people who delete their subscription within a period (now-30d and now). ''' start = epoch_utc(datetime.now() - timedelta(days=days)) end = epoch_utc(datetime.now()) return len( [churn for churn in self.churns if start < churn['created'] < end])
def periods(self, days=31): customers = list(self.customers) churns = list(self.churns) now = datetime.now().replace(hour=0, minute=0, second=0) periods = [{ 'timestamp': epoch_utc(now - timedelta(days=i)) } for i in reversed(range(1, days + 1))] for period in periods: period_customers = [ cust for cust in customers if cust['created'] < period['timestamp'] ] period_churns = [ churn for churn in churns if churn['created'] > period['timestamp'] ] period['customers'] = len(period_customers) + len(period_churns) period['monthly_revenue'] = sum(c['subscription']['plan']['amount'] for c in period_customers) period['monthly_revenue'] += sum( e['data']['object'].get('plan', {}).get('amount', 0) for e in period_churns) period['monthly_revenue'] = period['monthly_revenue'] / float(100) return periods
def periods(self, days=31): customers = list(self.customers) churns = list(self.churns) now = datetime.now().replace(hour=0, minute=0, second=0) periods = [{'timestamp': epoch_utc(now - timedelta(days=i))} for i in reversed(range(1, days+1))] for period in periods: period_customers = [cust for cust in customers if cust['created'] < period['timestamp']] period_churns = [churn for churn in churns if churn['created'] > period['timestamp']] period['customers'] = len(period_customers) + len(period_churns) period['monthly_revenue'] = sum(c['subscription']['plan']['amount'] for c in period_customers) period['monthly_revenue'] += sum(e['data']['object'].get('plan', {}).get('amount', 0) for e in period_churns) period['monthly_revenue'] = period['monthly_revenue'] / float(100) return periods