示例#1
0
 /**
  * Returns A/B-test traffic amounts
  *
  * @param int $id A/B-test ID.
  * @return array
  */
 public static function getTestCapacity($id)
 {
     $cache = new \CPHPCache();
     if ($cache->initCache(time() - strtotime('today'), 'abtest_capacity_' . intval($id), '/abtest')) {
         $capacity = $cache->getVars();
     } else {
         if (Loader::includeModule('conversion')) {
             if ($conversionRates = Conversion\RateManager::getTypes(array('ACTIVE' => true))) {
                 if ($abtest = ABTestTable::getById($id)->fetch()) {
                     $lid = $abtest['SITE_ID'];
                     $baseRate = array_slice($conversionRates, 0, 1, true);
                     $reportContext = new Conversion\ReportContext();
                     $reportContext->setAttribute('conversion_site', $lid);
                     $reportContext->setAttribute('abtest', $id);
                     $reportContext->setAttribute('abtest_section', 'A');
                     $groupAData = reset($reportContext->getRatesDeprecated($baseRate, array(), null));
                     $reportContext->unsetAttribute('abtest_section', 'A');
                     $reportContext->setAttribute('abtest_section', 'B');
                     $groupBData = reset($reportContext->getRatesDeprecated($baseRate, array(), null));
                     $capacity = array('A' => $groupAData['DENOMINATOR'], 'B' => $groupBData['DENOMINATOR']);
                     $cache->startDataCache(strtotime('tomorrow') - time());
                     $cache->endDataCache($capacity);
                 }
             }
         }
     }
     return !empty($capacity) ? $capacity : array('A' => 0, 'B' => 0);
 }
示例#2
0
文件: calc.php 项目: vim84/b-markt
if (!$sites) {
    die('No sites available!');
}
$site = $_GET['site'] ?: $userOptions['site'];
if (!($siteName = $sites[$site])) {
    list($site, $siteName) = each($sites);
}
// FILTER
$filter = array('from' => $from->toString(), 'to' => $to->toString(), 'site' => $site);
CUserOptions::SetOption('conversion', 'filter', array_merge($userOptions, $filter));
$filter['lang'] = LANGUAGE_ID;
// CONTEXT
GeneratorContext::generateInitialData($from);
$context = new ReportContext();
$context->setAttribute('conversion_site', $site);
$rates = $context->getRatesDeprecated($rateTypes, array('>=DAY' => $from, '<=DAY' => $to));
if ($topRate = reset($rates)) {
    $traffic = $topRate['DENOMINATOR'];
    $quantity = $topRate['NUMERATOR'];
    $gross = $topRate['SUM'];
    $conversion = $topRate['RATE'] * 100;
} else {
    $quantity = 0;
    $traffic = 0;
    $gross = 0;
    $conversion = 0;
}
$averageBill = $quantity ? $gross / $quantity : 0;
// with no margin!!!
$clickPrice = 0;
$advertExpense = 0;