diff --git a/src/Pluf/AB/Funnel.php b/src/Pluf/AB/Funnel.php index 2dad2e5..95ce173 100644 --- a/src/Pluf/AB/Funnel.php +++ b/src/Pluf/AB/Funnel.php @@ -128,15 +128,16 @@ class Pluf_AB_Funnel // will be very easy to adapt. foreach ($db->funnellogs->find($q) as $log) { if (!isset($uids[$log['u'].'##'.$log['s']])) { + if ($prop and !isset($log['p'][$prop])) { + continue; + } $uids[$log['u'].'##'.$log['s']] = true; $step = $log['s']; $steps[$step]['name'] = $log['sn']; + $steps[$step]['id'] = $log['s']; if ($prop and !isset($steps[$step]['props'])) { $steps[$step]['props'] = array(); } - if ($prop and !isset($log['p'][$prop])) { - continue; - } $steps[$step]['total'] = (isset($steps[$step]['total'])) ? $steps[$step]['total'] + 1 : 1; if ($prop) { @@ -146,22 +147,35 @@ class Pluf_AB_Funnel } } // Now, compile the stats for steps 2 to n - if (!isset($steps[1]['total'])) { + // First, we find the "max" for the reference number of + // visitors along this funnel. This is $t1 and $tprops[prop] + $t1 = 0; + foreach ($steps as $step) { + if (isset($step['total']) and $step['total'] > $t1) { + $t1 = $step['total']; + } + if ($prop and isset($step['props'])) { + foreach ($step['props'] as $v => $t) { + if (!isset($tprops[$v])) { + $tprops[$v] = $t; + continue; + } + if ($tprops[$v] < $t) { + $tprops[$v] = $t; + } + } + } + } + if ($t1 == 0) { return array(); } - $t1 = $steps[1]['total']; - $tprops = array(); - if (isset($steps[1]['props'])) { - foreach ($steps[1]['props'] as $v => $t) { - $tprops[$v] = $t; - // some properties are set only in the - // middle of the funnel, we get the - // value in the step. + $prev_step = null; + for ($i=1;$i<=20;$i++) { + if ($prev_step == null) { + } - } - for ($i=2;$i<=20;$i++) { - if ($steps[$i] and $steps[$i-1]) { - $tp = $steps[$i-1]['total']; + if ($steps[$i]) { + $tp = $prev_step['total']; $tn = $steps[$i]['total']; if ($tp) { $steps[$i]['conv'] = sprintf('%01.2f%%', 100.0 - (float)($tp-$tn)/$tp*100.0); @@ -180,7 +194,7 @@ class Pluf_AB_Funnel if (!isset($tprops[$v])) { $tprops[$v] = $t; } - $pv = isset($steps[$i-1]['props'][$v]) ? $steps[$i-1]['props'][$v] : 0; + $pv = isset($prev_step['props'][$v]) ? $prev_step['props'][$v] : 0; $steps[$i]['sprops'][$v] = array($t, $pv); $steps[$i]['sprops1'][$v] = array($t, $tprops[$v]); if ($pv) { @@ -191,8 +205,14 @@ class Pluf_AB_Funnel $steps[$i]['sprops1'][$v][] = round(100*(float)$t/(float)$tprops[$v],2).'%'; } } + $prev_step = $steps[$i]; } } + for ($i=20;$i>=1;$i--) { + if (!$steps[$i]) { + unset($steps[$i]); // We remove the inexisting steps + } + } return $steps; } } diff --git a/src/Pluf/Tests/Log/TestLog.php b/src/Pluf/Tests/Log/TestLog.php index d02229c..7b31574 100644 --- a/src/Pluf/Tests/Log/TestLog.php +++ b/src/Pluf/Tests/Log/TestLog.php @@ -33,6 +33,7 @@ class Pluf_Tests_Log_TestLog extends UnitTestCase function setUp() { $GLOBALS['_PX_config']['log_delayed'] = false; + Pluf_Log::$level = Pluf_Log::ALL; Pluf_Log::$stack = array(); $this->logfile = Pluf::f('pluf_log_file', Pluf::f('tmp_folder', '/tmp').'/pluf.log'); diff --git a/src/Pluf/Tests/Log/TestRemote.php b/src/Pluf/Tests/Log/TestRemote.php index b34fe90..86794d1 100644 --- a/src/Pluf/Tests/Log/TestRemote.php +++ b/src/Pluf/Tests/Log/TestRemote.php @@ -44,6 +44,9 @@ class Pluf_Tests_Log_TestRemote extends UnitTestCase function testSimple() { + if (Pluf::f('test_log_testremote', false) == false) { + return; + } $GLOBALS['_PX_config']['log_delayed'] = true; Pluf_Log::log('hello'); $this->assertEqual(count(Pluf_Log::$stack), 1); @@ -54,6 +57,9 @@ class Pluf_Tests_Log_TestRemote extends UnitTestCase function testAssertLog() { + if (Pluf::f('test_log_testremote', false) == false) { + return; + } Pluf_Log::activeAssert(); $GLOBALS['_PX_config']['log_delayed'] = true; assert('Pluf_Log::alog("hello")'); diff --git a/src/Pluf/conf/pluf.test.php b/src/Pluf/conf/pluf.test.php index 3bcadf8..6ad1a09 100644 --- a/src/Pluf/conf/pluf.test.php +++ b/src/Pluf/conf/pluf.test.php @@ -70,7 +70,8 @@ $cfg['db_table_prefix'] = 'pluf_unit_tests_'; // The reason of the db_version for MySQL is only for that. $cfg['db_version'] = '5.0'; $cfg['db_engine'] = 'SQLite'; - +$cfg['pluf_ab_mongo_db'] = 'pluf_ab_test'; $cfg['simple_test_path'] = '/home/loa/Vendors/simpletest'; +$cfg['cache_engine'] = 'Pluf_Cache_Memcached'; return $cfg; diff --git a/src/Pluf/templates/pluf/ab/funnel.html b/src/Pluf/templates/pluf/ab/funnel.html index de969db..e102aa6 100644 --- a/src/Pluf/templates/pluf/ab/funnel.html +++ b/src/Pluf/templates/pluf/ab/funnel.html @@ -18,13 +18,14 @@ {assign $i=1} -{foreach $stats as $step}{if $step} +{foreach $stats as $n => $step} +{if $step} -{if $i>1} +{if $i>1 and isset($step['conv'])}
{$step['total']} ({$step['conv']})
{/if} -{$stats[$i]['total']} out of {$stats['1']['total']} visitors reached step {$i} of this funnel. -This is a completion rate of {$stats[$i]['conv1']}.
-{if count($props) and isset($stats[$i]['sprops1'])} -{$step['total']} out of {*$stats['1']['total']*} visitors reached step {$step['id']} of this funnel. +This is a completion rate of {$step['conv1']}.
+ +{if count($props) and isset($step['sprops1'])} + +{$k}: {assign $nn = $t[1]}