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