1 | <?php |
||
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 | 3 | throw new \Exception('Unknown option: ' . $name); |
|
70 | } |
||
71 | } |
||
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 | ); |
||
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 | } |
||
94 | |||
95 | 1 | return $cleanedOptions; |
|
96 | } |
||
97 | |||
98 | 1 | public function getConfidenceInterval() |
|
102 | |||
103 | 3 | public function setConfidenceInterval($confidenceInterval) |
|
107 | |||
108 | 1 | public function getIsMostConclusive() |
|
112 | |||
113 | 3 | public function setIsMostConclusive($isMostConclusive) |
|
117 | |||
118 | 1 | public function getIsSignificant() |
|
122 | |||
123 | 3 | public function setIsSignificant($isSignificant) |
|
127 | |||
128 | 1 | public function getSignificance() |
|
132 | |||
133 | 3 | public function setSignificance($significance) |
|
137 | |||
138 | 1 | public function getValue() |
|
142 | |||
143 | 3 | public function setValue($value) |
|
147 | |||
148 | 1 | public function getVisitorsRemaining() |
|
152 | |||
153 | 3 | public function setVisitorsRemaining($visitorsRemaining) |
|
157 | } |
||
158 | |||
159 | |||
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.