|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author Oleg Krivtsov <[email protected]> |
|
4
|
|
|
* @date 12 October 2016 |
|
5
|
|
|
* @copyright (c) 2016, Web Marketing ROI |
|
6
|
|
|
*/ |
|
7
|
|
|
namespace WebMarketingROI\OptimizelyPHP\Resource\v2; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Optimizely datapoint. |
|
11
|
|
|
*/ |
|
12
|
|
|
class Datapoint |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* The confidence interval measures the uncertainty around improvement. It |
|
16
|
|
|
* starts out wide and shrinks as more data comes in. Significance means |
|
17
|
|
|
* that the confidence interval is completely above or completely below 0. |
|
18
|
|
|
* If the result is significant and positive, the confidence interval will |
|
19
|
|
|
* be above 0. If the result is significant and negative, confidence interval |
|
20
|
|
|
* will be below 0. If the result is inconclusive, confidence interval includes 0. |
|
21
|
|
|
* @var array[number] |
|
22
|
|
|
*/ |
|
23
|
|
|
private $confidenceInterval; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Indicates that this is the best performing variant for this metric. |
|
27
|
|
|
* Also referred to as the 'Winner' |
|
28
|
|
|
* @var boolean |
|
29
|
|
|
*/ |
|
30
|
|
|
private $isMostConclusive; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Indicates if significance is above your confidence threshold |
|
34
|
|
|
* @var boolean |
|
35
|
|
|
*/ |
|
36
|
|
|
private $isSignificant; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* The likelihood that the observed difference in conversion rate is not due to chance. |
|
40
|
|
|
* @var number |
|
41
|
|
|
*/ |
|
42
|
|
|
private $significance; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* The relative improvement for this variant over the baseline variant. |
|
46
|
|
|
* @var number |
|
47
|
|
|
*/ |
|
48
|
|
|
private $value; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* The number of estimated visitors remaining before result becomes statistically significant |
|
52
|
|
|
* @var integer |
|
53
|
|
|
*/ |
|
54
|
|
|
private $visitorsRemaining; |
|
55
|
|
|
/** |
|
56
|
|
|
* Constructor. |
|
57
|
|
|
*/ |
|
58
|
3 |
|
public function __construct($options = array()) |
|
59
|
|
|
{ |
|
60
|
3 |
|
foreach ($options as $name=>$value) { |
|
61
|
|
|
switch ($name) { |
|
62
|
3 |
|
case 'confidence_interval': $this->setConfidenceInterval($value); break; |
|
|
|
|
|
|
63
|
3 |
|
case 'is_most_conclusive': $this->setIsMostConclusive($value); break; |
|
|
|
|
|
|
64
|
3 |
|
case 'is_significant': $this->setIsSignificant($value); break; |
|
|
|
|
|
|
65
|
3 |
|
case 'significance': $this->setSignificance($value); break; |
|
|
|
|
|
|
66
|
3 |
|
case 'value': $this->setValue($value); break; |
|
|
|
|
|
|
67
|
3 |
|
case 'visitors_remaining': $this->setVisitorsRemaining($value); break; |
|
|
|
|
|
|
68
|
|
|
default: |
|
69
|
|
|
throw new \Exception('Unknown option: ' . $name); |
|
70
|
|
|
} |
|
71
|
3 |
|
} |
|
72
|
3 |
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Returns this object as array. |
|
76
|
|
|
*/ |
|
77
|
1 |
|
public function toArray() |
|
78
|
|
|
{ |
|
79
|
|
|
$options = array( |
|
80
|
1 |
|
'confidence_interval' => $this->getConfidenceInterval(), |
|
81
|
1 |
|
'is_most_conclusive' => $this->getIsMostConclusive(), |
|
82
|
1 |
|
'is_significant' => $this->getIsSignificant(), |
|
83
|
1 |
|
'significance' => $this->getSignificance(), |
|
84
|
1 |
|
'value' => $this->getValue(), |
|
85
|
1 |
|
'visitors_remaining' => $this->getVisitorsRemaining(), |
|
86
|
1 |
|
); |
|
87
|
|
|
|
|
88
|
|
|
// Remove options with empty values |
|
89
|
1 |
|
$cleanedOptions = array(); |
|
90
|
1 |
|
foreach ($options as $name=>$value) { |
|
91
|
1 |
|
if ($value!==null) |
|
92
|
1 |
|
$cleanedOptions[$name] = $value; |
|
93
|
1 |
|
} |
|
94
|
|
|
|
|
95
|
1 |
|
return $cleanedOptions; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
1 |
|
public function getConfidenceInterval() |
|
99
|
|
|
{ |
|
100
|
1 |
|
return $this->confidenceInterval; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
3 |
|
public function setConfidenceInterval($confidenceInterval) |
|
104
|
|
|
{ |
|
105
|
3 |
|
$this->confidenceInterval = $confidenceInterval; |
|
106
|
3 |
|
} |
|
107
|
|
|
|
|
108
|
1 |
|
public function getIsMostConclusive() |
|
109
|
|
|
{ |
|
110
|
1 |
|
return $this->isMostConclusive; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
3 |
|
public function setIsMostConclusive($isMostConclusive) |
|
114
|
|
|
{ |
|
115
|
3 |
|
$this->isMostConclusive = $isMostConclusive; |
|
116
|
3 |
|
} |
|
117
|
|
|
|
|
118
|
1 |
|
public function getIsSignificant() |
|
119
|
|
|
{ |
|
120
|
1 |
|
return $this->isSignificant; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
3 |
|
public function setIsSignificant($isSignificant) |
|
124
|
|
|
{ |
|
125
|
3 |
|
$this->isSignificant = $isSignificant; |
|
126
|
3 |
|
} |
|
127
|
|
|
|
|
128
|
1 |
|
public function getSignificance() |
|
129
|
|
|
{ |
|
130
|
1 |
|
return $this->significance; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
3 |
|
public function setSignificance($significance) |
|
134
|
|
|
{ |
|
135
|
3 |
|
$this->significance = $significance; |
|
136
|
3 |
|
} |
|
137
|
|
|
|
|
138
|
1 |
|
public function getValue() |
|
139
|
|
|
{ |
|
140
|
1 |
|
return $this->value; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
3 |
|
public function setValue($value) |
|
144
|
|
|
{ |
|
145
|
3 |
|
$this->value = $value; |
|
146
|
3 |
|
} |
|
147
|
|
|
|
|
148
|
1 |
|
public function getVisitorsRemaining() |
|
149
|
|
|
{ |
|
150
|
1 |
|
return $this->visitorsRemaining; |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
3 |
|
public function setVisitorsRemaining($visitorsRemaining) |
|
154
|
|
|
{ |
|
155
|
3 |
|
$this->visitorsRemaining = $visitorsRemaining; |
|
156
|
3 |
|
} |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
|
|
160
|
|
|
|
|
161
|
|
|
|
|
162
|
|
|
|
|
163
|
|
|
|
|
164
|
|
|
|
|
165
|
|
|
|
|
166
|
|
|
|
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.