🐛Fix subs dashboard 30 day churn

This commit is contained in:
Matt Lott 2015-08-23 20:54:39 -07:00
parent b171a55876
commit f42f34c96f
2 changed files with 4 additions and 5 deletions

View file

@ -24,7 +24,7 @@ block content
div.description 30 Day Total Growth
div.count #{monthlyGrowth.toFixed(1)}%
.col-md-5.big-stat.churn-count
div.description Monthly Churn (cancelled / total)
div.description 30 Day Churn (cancelled / total)
div.count #{monthlyChurn.toFixed(1)}%
each graph in analytics.graphs

View file

@ -33,7 +33,6 @@ module.exports = class AnalyticsSubscriptionsView extends RootView
context.subscriberCancelled = _.find context.subscribers, (subscriber) -> subscriber.cancel
context.subscriberSponsored = _.find context.subscribers, (subscriber) -> subscriber.user?.stripe?.sponsorID
context.total = @total ? 0
context.cancelled = @cancellations?.length ? @cancelled ? 0
context.monthlyChurn = @monthlyChurn ? 0.0
context.monthlyGrowth = @monthlyGrowth ? 0.0
context.outstandingCancels = @outstandingCancels ? []
@ -52,7 +51,6 @@ module.exports = class AnalyticsSubscriptionsView extends RootView
@analytics = graphs: []
@subs = []
@total = 0
@cancelled = 0
@monthlyChurn = 0.0
@monthlyGrowth = 0.0
@refreshDataState = 'Fetching dashboard data...'
@ -258,14 +256,15 @@ module.exports = class AnalyticsSubscriptionsView extends RootView
ended: subDayMap[day]['end'] or 0
@subs.sort (a, b) -> a.day.localeCompare(b.day)
cancelledThisMonth = 0
totalLastMonth = 0
for sub, i in @subs
@total += sub.started
@total -= sub.ended
@cancelled += sub.cancelled
sub.total = @total
cancelledThisMonth += sub.cancelled if @subs.length - i < 31
totalLastMonth = @total if @subs.length - i is 31
@monthlyChurn = @cancelled / totalLastMonth * 100.0 if totalLastMonth > 0
@monthlyChurn = cancelledThisMonth / totalLastMonth * 100.0 if totalLastMonth > 0
if @subs.length > 30 and @subs[@subs.length - 31].total > 0
startMonthTotal = @subs[@subs.length - 31].total
endMonthTotal = @subs[@subs.length - 1].total