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