|
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
|
|
|
use WebMarketingROI\OptimizelyPHP\Resource\v2\Datapoint; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Optimizely campaign variant results. |
|
14
|
|
|
*/ |
|
15
|
|
|
class VariantResults |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* The unique identifier for the Experiment this entity contains results for (if applicable). |
|
19
|
|
|
* @var integer |
|
20
|
|
|
*/ |
|
21
|
|
|
private $experimentId; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Indicates that this variant is the baseline that all other entities will |
|
25
|
|
|
* be compared against. Also referred to as the 'Control' or 'Control Group'. |
|
26
|
|
|
* @var boolean |
|
27
|
|
|
*/ |
|
28
|
|
|
private $isBaseline; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* |
|
32
|
|
|
* @var type |
|
33
|
|
|
*/ |
|
34
|
|
|
private $level; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* The relative difference in performance of this variant vs. the baseline |
|
38
|
|
|
* variant. Lift is calculated as follows: (Winning Conversion Rate % - Old |
|
39
|
|
|
* Conversion Rate %) - Old Conversion Rate % = % Improvement |
|
40
|
|
|
* @var Datapoint |
|
41
|
|
|
*/ |
|
42
|
|
|
private $lift; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* The name of the variant |
|
46
|
|
|
* @var string |
|
47
|
|
|
*/ |
|
48
|
|
|
private $name; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* |
|
52
|
|
|
* @var number |
|
53
|
|
|
*/ |
|
54
|
|
|
private $rate; |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* The scope that this variant represents. Can be 'variation', 'experiment' or 'campaign' |
|
58
|
|
|
* @var string |
|
59
|
|
|
*/ |
|
60
|
|
|
private $scope; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* |
|
64
|
|
|
* @var Datapoint |
|
65
|
|
|
*/ |
|
66
|
|
|
private $totalIncrease; |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* |
|
70
|
|
|
* @var number |
|
71
|
|
|
*/ |
|
72
|
|
|
private $value; |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* |
|
76
|
|
|
* @var string |
|
77
|
|
|
*/ |
|
78
|
|
|
private $variationId; |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* |
|
82
|
|
|
* @var type |
|
83
|
|
|
*/ |
|
84
|
|
|
private $samples; |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* |
|
88
|
|
|
* @var type |
|
89
|
|
|
*/ |
|
90
|
|
|
private $variance; |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Constructor. |
|
94
|
|
|
*/ |
|
95
|
3 |
|
public function __construct($options = array()) |
|
96
|
|
|
{ |
|
97
|
3 |
|
foreach ($options as $name=>$value) { |
|
98
|
|
|
switch ($name) { |
|
99
|
3 |
|
case 'experiment_id': $this->setExperimentId($value); break; |
|
|
|
|
|
|
100
|
3 |
|
case 'is_baseline': $this->setIsBaseline($value); break; |
|
|
|
|
|
|
101
|
3 |
|
case 'level': $this->setLevel($value); break; |
|
|
|
|
|
|
102
|
3 |
|
case 'lift': $this->setLift(new Datapoint($value)); break; |
|
|
|
|
|
|
103
|
3 |
|
case 'name': $this->setName($value); break; |
|
|
|
|
|
|
104
|
3 |
|
case 'rate': $this->setRate($value); break; |
|
|
|
|
|
|
105
|
3 |
|
case 'scope': $this->setScope($value); break; |
|
|
|
|
|
|
106
|
3 |
|
case 'total_increase': $this->setTotalIncrease(new Datapoint($value)); break; |
|
|
|
|
|
|
107
|
3 |
|
case 'value': $this->setValue($value); break; |
|
|
|
|
|
|
108
|
3 |
|
case 'variation_id': $this->setVariationId($value); break; |
|
|
|
|
|
|
109
|
|
|
case 'samples': $this->setSamples($value); break; |
|
|
|
|
|
|
110
|
|
|
case 'variance': $this->setVariance($value); break; |
|
|
|
|
|
|
111
|
|
|
default: |
|
112
|
3 |
|
throw new Exception('Unknown option found in the VariantResults entity: ' . $name); |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
3 |
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* Returns this object as array. |
|
119
|
|
|
*/ |
|
120
|
1 |
|
public function toArray() |
|
121
|
|
|
{ |
|
122
|
|
|
$options = array( |
|
123
|
1 |
|
'experiment_id' => $this->getExperimentId(), |
|
124
|
1 |
|
'is_baseline' => $this->getIsBaseline(), |
|
125
|
1 |
|
'level' => $this->getLevel(), |
|
126
|
1 |
|
'lift' => $this->getLift()?$this->getLift()->toArray():null, |
|
127
|
1 |
|
'name' => $this->getName(), |
|
128
|
1 |
|
'rate' => $this->getRate(), |
|
129
|
1 |
|
'scope' => $this->getScope(), |
|
130
|
1 |
|
'total_increase' => $this->getTotalIncrease()?$this->getTotalIncrease()->toArray():null, |
|
131
|
1 |
|
'value' => $this->getValue(), |
|
132
|
1 |
|
'variation_id' => $this->getVariationId(), |
|
133
|
1 |
|
'samples' => $this->getSamples(), |
|
134
|
1 |
|
'variance' => $this->getVariance(), |
|
135
|
|
|
); |
|
136
|
|
|
|
|
137
|
|
|
// Remove options with empty values |
|
138
|
1 |
|
$cleanedOptions = array(); |
|
139
|
1 |
|
foreach ($options as $name=>$value) { |
|
140
|
1 |
|
if ($value!==null) |
|
141
|
1 |
|
$cleanedOptions[$name] = $value; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
1 |
|
return $cleanedOptions; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
1 |
|
public function getExperimentId() |
|
148
|
|
|
{ |
|
149
|
1 |
|
return $this->experimentId; |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
3 |
|
public function setExperimentId($experimentId) |
|
153
|
|
|
{ |
|
154
|
3 |
|
$this->experimentId = $experimentId; |
|
155
|
3 |
|
} |
|
156
|
|
|
|
|
157
|
1 |
|
public function getIsBaseline() |
|
158
|
|
|
{ |
|
159
|
1 |
|
return $this->isBaseline; |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
3 |
|
public function setIsBaseline($isBaseline) |
|
163
|
|
|
{ |
|
164
|
3 |
|
$this->isBaseline = $isBaseline; |
|
165
|
3 |
|
} |
|
166
|
|
|
|
|
167
|
1 |
|
public function getLevel() |
|
168
|
|
|
{ |
|
169
|
1 |
|
return $this->level; |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
public function setLevel($level) |
|
173
|
|
|
{ |
|
174
|
|
|
$this->level = $level; |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
1 |
|
public function getLift() |
|
178
|
|
|
{ |
|
179
|
1 |
|
return $this->lift; |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
3 |
|
public function setLift($lift) |
|
183
|
|
|
{ |
|
184
|
3 |
|
$this->lift = $lift; |
|
185
|
3 |
|
} |
|
186
|
|
|
|
|
187
|
1 |
|
public function getName() |
|
188
|
|
|
{ |
|
189
|
1 |
|
return $this->name; |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
3 |
|
public function setName($name) |
|
193
|
|
|
{ |
|
194
|
3 |
|
$this->name = $name; |
|
195
|
3 |
|
} |
|
196
|
|
|
|
|
197
|
1 |
|
public function getRate() |
|
198
|
|
|
{ |
|
199
|
1 |
|
return $this->rate; |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
3 |
|
public function setRate($rate) |
|
203
|
|
|
{ |
|
204
|
3 |
|
$this->rate = $rate; |
|
205
|
3 |
|
} |
|
206
|
|
|
|
|
207
|
1 |
|
public function getScope() |
|
208
|
|
|
{ |
|
209
|
1 |
|
return $this->scope; |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
3 |
|
public function setScope($scope) |
|
213
|
|
|
{ |
|
214
|
3 |
|
$this->scope = $scope; |
|
215
|
3 |
|
} |
|
216
|
|
|
|
|
217
|
1 |
|
public function getTotalIncrease() |
|
218
|
|
|
{ |
|
219
|
1 |
|
return $this->totalIncrease; |
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
3 |
|
public function setTotalIncrease($totalIncrease) |
|
223
|
|
|
{ |
|
224
|
3 |
|
$this->totalIncrease = $totalIncrease; |
|
225
|
3 |
|
} |
|
226
|
|
|
|
|
227
|
1 |
|
public function getValue() |
|
228
|
|
|
{ |
|
229
|
1 |
|
return $this->value; |
|
230
|
|
|
} |
|
231
|
|
|
|
|
232
|
3 |
|
public function setValue($value) |
|
233
|
|
|
{ |
|
234
|
3 |
|
$this->value = $value; |
|
235
|
3 |
|
} |
|
236
|
|
|
|
|
237
|
1 |
|
public function getVariationId() |
|
238
|
|
|
{ |
|
239
|
1 |
|
return $this->variationId; |
|
240
|
|
|
} |
|
241
|
|
|
|
|
242
|
3 |
|
public function setVariationId($variationId) |
|
243
|
|
|
{ |
|
244
|
3 |
|
$this->variationId = $variationId; |
|
245
|
3 |
|
} |
|
246
|
|
|
|
|
247
|
1 |
|
public function getSamples() |
|
248
|
|
|
{ |
|
249
|
1 |
|
return $this->samples; |
|
250
|
|
|
} |
|
251
|
|
|
|
|
252
|
|
|
public function setSamples($samples) |
|
253
|
|
|
{ |
|
254
|
|
|
$this->samples = $samples; |
|
255
|
|
|
} |
|
256
|
|
|
|
|
257
|
1 |
|
public function getVariance() |
|
258
|
|
|
{ |
|
259
|
1 |
|
return $this->variance; |
|
260
|
|
|
} |
|
261
|
|
|
|
|
262
|
|
|
public function setVariance($variance) |
|
263
|
|
|
{ |
|
264
|
|
|
$this->variance = $variance; |
|
265
|
|
|
} |
|
266
|
|
|
} |
|
267
|
|
|
|
|
268
|
|
|
|
|
269
|
|
|
|
|
270
|
|
|
|
|
271
|
|
|
|
|
272
|
|
|
|
|
273
|
|
|
|
|
274
|
|
|
|
|
275
|
|
|
|
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.