pluf2

pluf2 Commit Details


Date:2010-03-21 04:11:44 (14 years 9 months ago)
Author:Loic d'Anterroches
Branch:master
Commit:8345dbaaab7d4ac54fa4d83a9b01af2d38cb2a2b
Parents: 819b375e5c6b7dcf6eaca3141791340661482272
Message:Added an A/B testing library to easily improve a webapplication.

Changes:

File differences

src/Pluf/AB.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
<?php
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
# ***** BEGIN LICENSE BLOCK *****
# This file is part of Plume Framework, a simple PHP Application Framework.
# Copyright (C) 2001-2010 Loic d'Anterroches and contributors.
#
# Plume Framework is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Plume Framework is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# ***** END LICENSE BLOCK ***** */
/**
* Core A/B testing component.
*
* The two importants methods are `test` and `convert`.
*
* For performance reasons, the A/B testing component requires you to
* setup a cache (APC or Memcached) and use the MongoDB database. The
* amount of data in the MongoDB should not be that big for most of
* the websites and as such it is fine if you are using the 32bit
* version of MongoDB.
*
* For the moment the storage is not abstracted to use another database.
*
* All the configuration variables for the component start with
* `pluf_ab_`. You need to add 'Pluf_AB' to your list of middleware.
*
*/
class Pluf_AB
{
/**
* MongoDB database handler.
*/
public static $db = null;
/**
* Returns an alternative for a given test.
*
* The middleware is already storing the uid of the user and makes
* it available as $request->pabuid.
*
* @param $test string Unique name of the test
* @param $request Pluf_HTTP_Request
* @param $alts array Alternatives to pick from (array(true,false))
* @param $weights array Weights for the alternatives (null)
* @param $desc string Optional description of the test ('')
* @return mixed One value from $alts
*/
public static function test($test, &$request, $alts=array(true,false),
$weights=null, $desc='')
{
if (Pluf::f('pluf_ab_allow_force', false) and
isset($request->GET[$test])) {
return $alts[$request->GET[$test]];
}
$db = self::getDb();
// Get or set test
$dtest = $db->tests->findOne(array('_id' => $test),
array('_id', 'active', 'winner'));
if ($dtest == null) {
$dtest = array('_id' => $test,
'creation_dtime' => gmdate('Y-m-d H:i:s',
$request->time),
'desc' => $desc,
'alts' => $alts,
'exp' => 0,
'conv' => 0,
'active' => true);
for ($i=0;$i<count($alts);$i++) {
$dtest['expalt_'.$i] = 0;
$dtest['convalt_'.$i] = 0;
}
$db->tests->update(array('_id'=>$test), $dtest,
array('upsert' => true));
} elseif (!$dtest['active']) {
// If test closed with given alternative, returns alternative
return (isset($dtest['winner'])) ? $alts[$dtest['winner']] : $alts[0];
}
if (!isset($request->pabuid)) {
$request->pabuid = self::getUid($request);
}
if ($request->pabuid == 'bot') {
return $alts[0];
}
// If $request->pabuid in test, returns corresponding alternative
$intest = $db->intest->findOne(array('_id' => $test.'##'.$request->pabuid),
array('_id', 'alt'));
if ($intest) {
return $alts[$intest['alt']];
}
// Else find alternative, store and return it
if ($weights == null) {
$weights = array_fill(0, count($alts), 1.0/count($alts));
}
$alt = self::weightedRand($weights);
$intest = array('_id' => $test.'##'.$request->pabuid,
'test' => $test,
'pabuid' => $request->pabuid,
'first_dtime' => gmdate('Y-m-d H:i:s',
$request->time),
'alt' => $alt);
$db->intest->update(array('_id' => $test.'##'.$request->pabuid),
$intest, array('upsert' => true));
// Update the counts of the test
$db->tests->update(array('_id' => $test),
array('$inc' => array('exp' => 1,
'expalt_'.$alt => 1)));
return $alts[$alt];
}
/**
* Mark a test as converted.
*
* A user which was not exposed to the test or a bot is not marked
* as converted as it is not significant.
*
* @param $test string Test
* @param $request Pluf_HTTP_Request
*/
public static function convert($test, $request)
{
if (!isset($request->pabuid) or $request->pabuid == 'bot') {
return;
}
$db = self::getDb();
$id = $test.'##'.$request->pabuid;
$intest = $db->intest->findOne(array('_id' => $id),
array('_id', 'alt'));
if (!$intest) {
// Not tested
return;
}
$conv = $db->convert->findOne(array('_id' => $id));
if ($conv) {
// Already converted
return;
}
$dtest = $db->tests->findOne(array('_id' => $test));
if (!$dtest or !$dtest['active']) {
return;
}
$conv = array(
'_id' => $id,
'test' => $test,
);
$db->convert->update(array('_id' => $id), $conv,
array('upsert' => true));
// increment the test counters
$db->tests->update(array('_id' => $test),
array('$inc' => array('conv' => 1,
'convalt_'.$intest['alt'] => 1)));
}
/**
* Process the response of a view.
*
* If the request has no cookie and the request has a pabuid, set
* the cookie in the response.
*
* @param Pluf_HTTP_Request The request
* @param Pluf_HTTP_Response The response
* @return Pluf_HTTP_Response The response
*/
function process_response($request, $response)
{
if (!isset($request->COOKIE['pabuid']) and isset($request->pabuid)
and $request->pabuid != 'bot') {
$response->cookies['pabuid'] = $request->pabuid;
}
return $response;
}
/**
* Process the request.
*
* If the request has the A/B test cookie, set $request->pabuid.
*
* @param Pluf_HTTP_Request The request
* @return bool False
*/
function process_request($request)
{
if (isset($request->COOKIE['pabuid']) and
self::check_uid($request->COOKIE['pabuid'])) {
$request->pabuid = $request->COOKIE['pabuid'];
}
return false;
}
/**
* Get a MongoDB database handle.
*
* It opens only one connection per request and tries to keep a
* persistent connection between the requests.
*
* The configuration keys used are:
*
* `pluf_ab_mongo_server`: 'mongodb://localhost:27017'
* `pluf_ab_mongo_options`: array('connect' => true,
* 'persist' => 'pluf_ab_mongo')
* `pluf_ab_mongo_db`: 'pluf_ab'
*
* If you have a default installation of MongoDB, it should work
* out of the box.
*
*/
public static function getDb()
{
if (self::$db !== null) {
return self::$db;
}
$server = Pluf::f('pluf_ab_mongo_server', 'mongodb://localhost:27017');
$options = Pluf::f('pluf_ab_mongo_options',
array('connect' => true, 'persist' => 'pluf_ab_mongo'));
$conn = new Mongo($server, $options);
self::$db = $conn->selectDB(Pluf::f('pluf_ab_mongo_db', 'pluf_ab'));
return self::$db;
}
/**
* Get the uid of a given request.
*
* @param $request Pluf_HTTP_Request
*/
public static function getUid($request)
{
if (isset($request->COOKIE['pabuid']) and
self::check_uid($request->COOKIE['pabuid'])) {
return $request->COOKIE['pabuid'];
}
if (!isset($request->SERVER['HTTP_USER_AGENT']) or
self::isBot($request->SERVER['HTTP_USER_AGENT'])) {
return 'bot';
}
// Here we need to make an uid, first check if a user with
// same ip/agent exists and was last seen within the last 1h.
// We get that from MemcacheDB
$cache = Pluf_Cache::factory();
$key = 'pluf_ab_'.crc32($request->remote_addr.'#'.$request->SERVER['HTTP_USER_AGENT']);
if ($uid=$cache->get($key, null)) {
$cache->set($key, $uid, 3600);
return $uid;
}
$uid = self::make_uid($request);
$cache->set($key, $uid, 3600);
return $uid;
}
/**
* Check if a given user agent is a bot.
*
* @param $user_agent string User agent string
* @return bool True if the user agent is a bot
*/
public static function isBot($user_agent)
{
static $bots = array('robot', 'checker', 'crawl', 'discovery',
'hunter', 'scanner', 'spider', 'sucker', 'larbin',
'slurp', 'libwww', 'lwp', 'yandex', 'netcraft',
'wget', 'twiceler');
static $pbots = array('/bot[\s_+:,\.\;\/\\\-]/i',
'/[\s_+:,\.\;\/\\\-]bot/i');
foreach ($bots as $r) {
if (false !== stristr($user_agent, $r)) {
return true;
}
}
foreach ($pbots as $p) {
if (preg_match($p, $user_agent)) {
return true;
}
}
if (false === strpos($user_agent, '(')) {
return true;
}
return false;
}
/**
* Returns a random weighted alternative.
*
* Given a series of weighted alternative in the format:
*
* <pre>
* array('alt1' => 0.2,
* 'alt2' => 0.3,
* 'alt3' => 0.5);
* </pre>
*
* Returns the key of the selected alternative. In the following
* example, the alternative 3 (alt3) has a 50% chance to be
* selected, if the selected the results would be 'alt3'.
* @link: http://20bits.com/downloads/w_rand.phps
*
* @param $weights array Weighted alternatives
* @return mixed Key of the selected $weights array
*/
public static function weightedRand($weights)
{
$r = mt_rand(1,10000);
$offset = 0;
foreach ($weights as $k => $w) {
$offset += $w*10000;
if ($r <= $offset) {
return $k;
}
}
}
/**
* Given a request, make a corresponding A/B test UID.
*
* The UID is based on the time, the remote address, a random
* component and is hashed to ensure the integrity and avoid the
* need of a database hit when controlled.
*
* @param $request Pluf_HTTP_Request
* @return string UID
*/
public static function make_uid($request)
{
$base = sprintf('%08X%08X%08X', $request->time,
sprintf('%u', crc32($request->remote_addr)),
rand());
return sprintf('%s%08X', $base, sprintf('%u', crc32($base.md5(Pluf::f('secret_key')))));
}
/**
* Validate the uid in the cookie.
*
* @see self::make_uid
*
* @param $uid string The UID
* @return bool True if the UID is valid
*/
public static function check_uid($uid)
{
if (strlen($uid) != 32) {
return false;
}
$check = sprintf('%08X', sprintf('%u', crc32(substr($uid, 0, 24).md5(Pluf::f('secret_key')))));
return ($check == substr($uid, -8));
}
/* ------------------------------------------------------------
*
* Statistics Functions
*
* Note: I am not a statistician, use at your own risk!
*
* ------------------------------------------------------------ */
/**
* Given a conversion rate calculate the recommended sample sizes.
*
* The sample sizes is calculated to be significant at 95% in the
* case of a variation of conversion with respect to the other
* alternative of 25%, 15% and 5%.
*
* @param $conv Conversion rate ]0.0;1.0]
* @return array The 3 sample sizes for 25%, 15% and 5%
*/
public static function ssize($conv)
{
$a = 3.84145882689; // $a = pow(inverse_ncdf(1-(1-0.95)/2),2)
$res = array();
$bs = array(0.0625, 0.0225, 0.0025);
foreach ($bs as $b) {
$res[] = (int) ((1-$conv)*$a/($b*$conv));
}
return $res;
}
/**
* Given a test, returns the corresponding stats.
*
* @param $test array Test definition and results
* @return array Statistics for the test
*/
public static function getTestStats($test)
{
$stats = array(); // Will store the stats
$n = count($test['alts']);
$aconvr = array(); // All the conversion rates to sort the alternatives
for ($i=0;$i<$n;$i++) {
$conv = (isset($test['convalt_'.$i])) ? $test['convalt_'.$i] : 0;
$exp = (isset($test['expalt_'.$i])) ? $test['expalt_'.$i] : 0;
$convr = self::cr(array($exp, $conv));
$nconvr = ($convr !== null) ?
sprintf('%01.2f%%', $convr*100.0) : 'N/A';
$ssize = ($convr !== null and $convr > 0) ?
self::ssize($convr) : array();
$stats[] = array('alt' => $i,
'convr' => $convr,
'conv' => $conv,
'exp' => $exp,
'nconvr' => $nconvr,
'ssize' => $ssize);
$aconvr[] = ($convr === null) ? 0 : $convr;
}
array_multisort($aconvr, SORT_DESC, $stats);
// We want the best to be significantly better than the second best.
for ($i=0;$i<$n;$i++) {
$convr = $stats[$i]['convr'];
$exp = $stats[$i]['exp'];
$conv = $stats[$i]['conv'];
$comp = false;
$zscore = false;
$conf = false;
$better = false;
if ($i != 1 and $stats[1]['convr'] > 0) {
// Compare with base case and get confidence/Z-score
$comp = 100.0 * (float) ($convr - $stats[1]['convr'])/ (float) ($stats[1]['convr']);
if ($comp > 0) $better = true;
$comp = sprintf('%01.2f%%', $comp);
$zscore = self::zscore(array($stats[1]['exp'], $stats[1]['conv']),
array($exp, $conv));
$conf = sprintf('%01.2f%%', self::cumnormdist($zscore)*100.0);
$zscore = sprintf('%01.2f', $zscore);
}
$stats[$i]['comp'] = $comp;
$stats[$i]['zscore'] = $zscore;
$stats[$i]['conf'] = $conf;
$stats[$i]['better'] = $better;
}
return $stats;
}
public static function cr($t)
{
if ($t[1] < 0) return null;
if ($t[0] <= 0) return null;
return $t[1]/$t[0];
}
public static function zscore($c, $t)
{
$z = self::cr($t)-self::cr($c);
$s = (self::cr($t)*(1-self::cr($t)))/$t[0]
+ (self::cr($c)*(1-self::cr($c)))/$c[0];
return $z/sqrt($s);
}
/**
* Approximation of the cumulative normal distribution.
*/
public static function cumnormdist($x)
{
$b1 = 0.319381530;
$b2 = -0.356563782;
$b3 = 1.781477937;
$b4 = -1.821255978;
$b5 = 1.330274429;
$p = 0.2316419;
$c = 0.39894228;
if($x >= 0.0) {
$t = 1.0 / ( 1.0 + $p * $x );
return (1.0 - $c * exp( -$x * $x / 2.0 ) * $t *
( $t *( $t * ( $t * ( $t * $b5 + $b4 ) + $b3 ) + $b2 ) + $b1 ));
} else {
$t = 1.0 / ( 1.0 - $p * $x );
return ( $c * exp( -$x * $x / 2.0 ) * $t *
( $t *( $t * ( $t * ( $t * $b5 + $b4 ) + $b3 ) + $b2 ) + $b1 ));
}
}
}
src/Pluf/AB/Form/MarkWinner.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
# ***** BEGIN LICENSE BLOCK *****
# This file is part of Plume Framework, a simple PHP Application Framework.
# Copyright (C) 2001-2010 Loic d'Anterroches and contributors.
#
# Plume Framework is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Plume Framework is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# ***** END LICENSE BLOCK ***** */
/**
* Mark the winner of a test.
*
* This form is not used to display the form, only to validate and
* process it.
*
*/
class Pluf_AB_Form_MarkWinner extends Pluf_Form
{
protected $test = null; /**< Store the test retrieved during validation. */
public function initFields($extra=array())
{
$this->fields['test'] = new Pluf_Form_Field_Varchar(
array('required' => true)
);
$this->fields['alt'] = new Pluf_Form_Field_Integer(
array('required' => true,
'min' => 0,
));
}
/**
* Validate that the test exists, is active and the corresponding
* alternative exists too.
*
* The validation is at the global level to prevent the need of a
* form per test and simplify the dashboard design.
*/
public function clean()
{
$db = Pluf_AB::getDb();
$test = $db->tests->findOne(array('_id' => $this->cleaned_data['test']));
if ($test == null) {
throw new Pluf_Form_Invalid(__('The test has not been found.'));
}
if (!$test['active']) {
throw new Pluf_Form_Invalid(__('The test is already inactive.'));
}
if (!isset($test['alts'][$this->cleaned_data['alt']])) {
throw new Pluf_Form_Invalid(__('This alternative is not available.'));
}
// Good we have the test and the right alternative
$this->test = $test;
return $this->cleaned_data;
}
/**
* Save the test.
*
* @return array Test.
*/
function save($commit=true)
{
$this->test['winner'] = $this->cleaned_data['alt'];
$this->test['active'] = false;
$this->test['stop_dtime'] = gmdate('Y-m-d H:i:s');
$db = Pluf_AB::getDb();
$db->tests->update(array('_id'=> $this->cleaned_data['test']),
$this->test);
return $this->test;
}
}
src/Pluf/AB/Views.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
# ***** BEGIN LICENSE BLOCK *****
# This file is part of Plume Framework, a simple PHP Application Framework.
# Copyright (C) 2001-2010 Loic d'Anterroches and contributors.
#
# Plume Framework is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Plume Framework is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# ***** END LICENSE BLOCK ***** */
Pluf::loadFunction('Pluf_Shortcuts_RenderToResponse');
Pluf::loadFunction('Pluf_HTTP_URL_urlForView');
/**
* Manage and visualize the tests.
*
* It is possible to mark a test as inactive by picking a
* winner.
*
* Check the urls.php file for the URL definition to integrate the
* dashboard in your application/project.
*
* The permission used are:
*
* Pluf_AB.view-dashboard: The user can view the dasboard.
* Pluf_AB.edit-test: The user can edit a test.
*
*/
class Pluf_AB_Views
{
/**
* Display the currently running tests.
*
* The name of the view in the urls must be 'pluf_ab_dashboard'.
*/
public $dasboard_precond = array(array('Pluf_Precondition::hasPerm',
'Pluf_AB.view-dashboard'));
public function dashboard($request, $match)
{
$url = Pluf_HTTP_URL_urlForView('pluf_ab_dashboard');
$can_edit = $request->user->hasPerm('Pluf_AB.edit-test');
if ($can_edit && $request->method == 'POST') {
// We mark the winner.
$form = new Pluf_AB_Form_MarkWinner($request->POST);
if ($form->isValid()) {
$form->save();
$request->user->setMessage(__('The test has been updated.'));
return new Pluf_HTTP_Response_Redirect($url);
}
} else {
// To have it available for the control of the errors in
// the template.
$form = new Pluf_AB_Form_MarkWinner();
}
// Get the list of tests
$db = Pluf_AB::getDb();
$active = array();
$stopped = array();
foreach ($db->tests->find() as $test) {
$test['stats'] = Pluf_AB::getTestStats($test);
if ($test['active']) {
$active[] = $test;
} else {
$stopped[] = $test;
}
}
return Pluf_Shortcuts_RenderToResponse('pluf/ab/dashboard.html',
array('active' => $active,
'stopped' => $stopped,
'form' => $form,
'can_edit' => $can_edit,
),
$request);
}
/**
* A simple view to redirect a user and convert it.
*
* To convert the user for the test 'my_test' and redirect it to
* the URL 'http://www.example.com' add the following view in your
* urls.php:
*
* <pre>
* array('regex' => '#^/goto/example/$#',
* 'base' => $base,
* 'model' => 'Pluf_AB_Views',
* 'method' => 'convRedirect',
* 'name' => 'go_to_example',
* 'params' => array('url' => 'http://www.example.com',
* 'test' => 'my_test')
* );
* </pre>
*
* Try to put a url which reflects the final url after redirection
* to minimize the confusion for the user. In this example, in
* your code or template you use the named url 'go_to_example'.
*
*/
public function convRedirect($request, $match, $p)
{
Pluf_AB::convert($p['test'], $request);
return new Pluf_HTTP_Response_Redirect($p['url']);
}
}
src/Pluf/templates/pluf/ab/base.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<!DOCTYPE html>
{*
Simple base for the A/B dashboard.
It contains the standard header and footer.
*}<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>{trans 'A/B Testing Dashboard'}</title>
<style type="text/css">
{literal}
body {
background: #fff;
font-family: Lucida Grande, Verdana, sans-serif;
padding: 1em 2em;
margin-left: 100px;
width: 600px;
}
h1, h2 {
font-weight: normal;
}
hr {
border: 1px solid #d3d7cf;
border-collapse: collapse;
height: 1px;
margin-top: 2em;
}
table {
margin: 0;
padding: 0;
border-spacing: 0;
border-collapse: collapse;
}
tr {
margin: 0;
padding: 0;
}
tr.winner {
background-color: #729fcf;
}
td {
border-top: 1px solid #d3d7cf;
border-bottom: 1px solid #d3d7cf;
padding: 10px;
vertical-align: top;
}
td.details {
background: #eeeeef;
margin: 0;
padding: 5px 10px;
}
pre {
margin: 0;
padding: 0;
}
.note, .details {
font-size: 0.8em;
}
p.note {
margin-top: 2em;
}
{/literal}
</style>
</head>
<body>
{block body}{/block}
</body>
</html>
src/Pluf/templates/pluf/ab/dashboard.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
{extends "pluf/ab/base.html"}
{block body}
<h1>A/B Testing Dashboard</h1>
{foreach $active as $test}
<h2>Test {$test['_id']}</h2>
<table summary=" ">{assign $alts=$test['stats']}
{foreach $alts as $alt}
<tr>
<td>Option {$alt['alt']}</td>
<td>{$test['alts'][$alt['alt']]|dump}</td>
<td>{$alt['nconvr']}{if $alt['better']} ({$alt['comp']} change){/if}</td>
{if $can_edit}
<td>
<form action="{url 'pluf_ab_dashboard'}" method="post">
<input type="hidden" name="test" value="{$test['_id']}" />
<input type="hidden" name="alt" value="{$alt['alt']}" />
<input type="submit" name="s" value="{trans 'Use as winner'}" />
</form>
</td>
{/if}
</tr>
<tr>
<td colspan="{if $can_edit}4{else}3{/if}" class="details">
Conv: {$alt['conv']}/{$alt['exp']}{if $alt['conf']} - Conf: {$alt['conf']}{/if}
</td>
</tr>
{/foreach}
</table>
{/foreach}
{if count($active) == 0}
<p>No running tests at the moment.</p>
{/if}
<p class="note">
The confidence is calculated with respect to the second best
alternative to evaluate if the best alternative is significantly
better than the second best.
</p>
<hr />
{foreach $stopped as $test}
<h2>Stopped Test {$test['_id']}</h2>
<table summary=" ">{assign $alts=$test['stats']}
{foreach $alts as $alt}
<tr{if $test['winner'] == $alt['alt']} class="winner"{/if}>
<td>{if $test['winner'] == $alt['alt']}<strong>!</strong>{/if} Option {$alt['alt']}</td>
<td>{$test['alts'][$alt['alt']]|dump}</td>
<td>{$alt['nconvr']}{if $alt['better']} ({$alt['comp']} change){/if}</td>
</tr>
<tr>
<td colspan="3" class="details">
Conv: {$alt['conv']}/{$alt['exp']}{if $alt['conf']} - Conf: {$alt['conf']}{/if}
</td>
</tr>
{/foreach}
</table>
{/foreach}
{/block}

Archive Download the corresponding diff file

Branches

Number of commits:
Page rendered in 0.08560s using 13 queries.