/
abtest-dashboard.coffee
75 lines (71 loc) · 2.35 KB
/
abtest-dashboard.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
Meteor.startup ->
Template.abtests.created = ->
Meteor.subscribe "ABTests"
Template.abtests.helpers
tests: -> ABTests.find()
decFormat: (num) -> num.toFixed(2)
intFormat: (num) -> num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")
vsControlClass: ->
if this.isControl
"hidden"
else if this.vsControl > 0
"text-success"
else if this.vsControl < 0
"text-error"
else
"muted"
significantClass: ->
if this.isSignificant()
"text-success"
else
"muted"
alternatives: ->
alts = []
control = null
values = []
for alternative of this.values
values.push
name: alternative
started: this.values[alternative].started
finished: this.values[alternative].finished
rank: this.values[alternative].rank
for v in values.sort((a, b) -> a.rank - b.rank)
started = v.started
finished = v.finished
finishedRate = if started then finished * 100 / started else 0
item =
isControl: not control
isSignificant: ->
return false if not this.control or (this.finished < 10 and this.control.finished < 10)
n = this.finished + this.control.finished
d = Math.abs this.finished - this.control.finished
Math.pow(d, 2) > n
name: v.name
started: started
finished: finished
nonfinished: started - finished
finishedRate: finishedRate
vsControl: if control?.finishedRate then (finishedRate - control.finishedRate) * 100 / control.finishedRate else 0
control: control
alts.push item
control = item if not control
alts
significant: ->
return "" if this.isControl
if this.isSignificant() then "YES" else "NO"
totals: ->
started = 0
finished = 0
for alternative of this.values
started += this.values[alternative].started
finished += this.values[alternative].finished
return {
started: started
finished: finished
nonfinished: started - finished
finishedRate: if started then finished * 100 / started else 0
}
Template.abtests.events
'click #resetTest': ->
if confirm("Are you sure you want to delete test: \n#{this.name}")
ABTest.reset this.name