Fix admin dashboard monthly churn

Monthly churn = cancelled during last month / total at beginning of
month
This commit is contained in:
Matt Lott 2015-05-01 17:26:22 -07:00
parent afc3689dcc
commit dce8005169
2 changed files with 4 additions and 4 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
div.description Monthly Churn (cancelled / total)
div.count #{monthlyChurn.toFixed(1)}%
each graph in analytics.graphs

View file

@ -129,14 +129,14 @@ module.exports = class AnalyticsSubscriptionsView extends RootView
ended: subDayMap[day]['end'] or 0
@subs.sort (a, b) -> a.day.localeCompare(b.day)
startedLastMonth = 0
totalLastMonth = 0
for sub, i in @subs
@total += sub.started
@total -= sub.ended
@cancelled += sub.cancelled
sub.total = @total
startedLastMonth += sub.started if @subs.length - i < 31
@monthlyChurn = @cancelled / startedLastMonth * 100.0 if startedLastMonth > 0
totalLastMonth = @total if @subs.length - i is 31
@monthlyChurn = @cancelled / 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