Use real cancellations for 1st month on subs dashboard

We have the data now, so no need to approximate anymore.
This commit is contained in:
Matt Lott 2015-08-23 15:32:44 -07:00
parent e8a4fd9336
commit b171a55876
2 changed files with 15 additions and 20 deletions

View file

@ -132,6 +132,8 @@ block content
td
td
td
if !showMoreCancellations
button.btn.btn-sm.btn-show-more-cancellations Show More Cancellations
h2 Subscriptions
if !subs || subs.length < 1

View file

@ -12,8 +12,12 @@ module.exports = class AnalyticsSubscriptionsView extends RootView
template: template
targetSubCount: 1200
events:
'click .btn-show-more-cancellations': 'onClickShowMoreCancellations'
constructor: (options) ->
super options
@showMoreCancellations = false
@resetSubscriptionsData()
if me.isAdmin()
@refreshData()
@ -22,7 +26,8 @@ module.exports = class AnalyticsSubscriptionsView extends RootView
getRenderData: ->
context = super()
context.analytics = @analytics ? graphs: []
context.cancellations = @cancellations ? []
context.cancellations = if @showMoreCancellations then @cancellations else (@cancellations ? []).slice(0, 40)
context.showMoreCancellations = @showMoreCancellations
context.subs = _.cloneDeep(@subs ? []).reverse()
context.subscribers = @subscribers ? []
context.subscriberCancelled = _.find context.subscribers, (subscriber) -> subscriber.cancel
@ -39,6 +44,10 @@ module.exports = class AnalyticsSubscriptionsView extends RootView
super()
@updateAnalyticsGraphs()
onClickShowMoreCancellations: (e) ->
@showMoreCancellations = true
@render?()
resetSubscriptionsData: ->
@analytics = graphs: []
@subs = []
@ -93,7 +102,7 @@ module.exports = class AnalyticsSubscriptionsView extends RootView
getCancellationEvents: (done) ->
cancellationEvents = []
earliestEventDate = new Date()
earliestEventDate.setUTCMonth(earliestEventDate.getUTCMonth() - 1)
earliestEventDate.setUTCMonth(earliestEventDate.getUTCMonth() - 2)
earliestEventDate.setUTCDate(earliestEventDate.getUTCDate() - 8)
nextBatch = (starting_after, done) =>
@updateFetchDataState "Fetching cancellations #{cancellationEvents.length}..."
@ -555,28 +564,15 @@ module.exports = class AnalyticsSubscriptionsView extends RootView
## Cancelled
# TODO: move this average cancelled stuff up the chain
averageCancelled = 0
# Build line data
levelPoints = []
cancelled = []
for sub, i in @subs[@subs.length - 30...]
cancelled.push sub.cancelled
for sub, i in @subs
levelPoints.push
x: @subs.length - 30 + i
y: sub.cancelled
day: sub.day
pointID: "#{cancelledSubsID}#{@subs.length - 30 + i}"
values: []
averageCancelled = cancelled.reduce((a, b) -> a + b) / cancelled.length
for sub, i in @subs[0...-30]
levelPoints.splice i, 0,
x: i
y: averageCancelled
day: sub.day
pointID: "#{cancelledSubsID}#{i}"
values: []
# Ensure points for each day
for day, i in days
@ -608,10 +604,7 @@ module.exports = class AnalyticsSubscriptionsView extends RootView
sevenNets = []
for sub, i in @subs
net = 0
if i >= @subs.length - 30
sevenNets.push sub.started - sub.cancelled
else
sevenNets.push sub.started - averageCancelled
sevenNets.push sub.started - sub.cancelled
if sevenNets.length > 7
sevenNets.shift()
if sevenNets.length is 7