Example #1
0
 /**
  * Determines the winner of A/B test based on dwell time rates
  *
  * @param MauticFactory $factory
  * @param Page          $parent
  * @param               $children
  *
  * @return array
  */
 public static function determineDwellTimeTestWinner($factory, $parent, $children)
 {
     //find the hits that did not go any further
     $repo = $factory->getEntityManager()->getRepository('MauticPageBundle:Hit');
     $pageIds = array($parent->getId());
     foreach ($children as $c) {
         $pageIds[] = $c->getId();
     }
     $startDate = $parent->getVariantStartDate();
     if ($startDate != null && !empty($pageIds)) {
         //get their bounce rates
         $counts = $repo->getDwellTimes(array('pageIds' => $pageIds, 'startDate' => $startDate));
         $translator = $factory->getTranslator();
         $support = array();
         if ($counts) {
             //in order to get a fair grade, we have to compare the averages here since a page that is only shown
             //25% of the time will have a significantly lower sum than a page shown 75% of the time
             $avgs = array();
             $support['data'] = array();
             $support['labels'] = array();
             foreach ($counts as $pid => $stats) {
                 $avgs[$pid] = $stats['average'];
                 $support['data'][$translator->trans('mautic.page.abtest.label.dewlltime.average')][] = $stats['average'];
                 $support['labels'][] = $pid . ':' . $stats['title'];
             }
             //set max for scales
             $max = max($avgs);
             $support['step_width'] = ceil($max / 10) * 10;
             //get the page ids with the greatest average dwell time
             $winners = $max > 0 ? array_keys($avgs, $max) : array();
             return array('winners' => $winners, 'support' => $support, 'basedOn' => 'page.dwelltime', 'supportTemplate' => 'MauticPageBundle:SubscribedEvents\\AbTest:bargraph.html.php');
         }
     }
     return array('winners' => array(), 'support' => array(), 'basedOn' => 'page.dwelltime');
 }
Example #2
0
 /**
  * Determines the winner of A/B test based on number of asset downloads
  *
  * @param MauticFactory $factory
  * @param Page          $parent
  * @param               $children
  *
  * @return array
  */
 public static function determineDownloadWinner($factory, $parent, $children)
 {
     $repo = $factory->getEntityManager()->getRepository('MauticAssetBundle:Download');
     //if this is an email A/B test, then link email to page to form submission
     //if it is a page A/B test, then link form submission to page
     $type = $parent instanceof Email ? 'email' : 'page';
     $ids = array($parent->getId());
     foreach ($children as $c) {
         if ($c->isPublished()) {
             $id = $c->getId();
             $ids[] = $id;
         }
     }
     $startDate = $parent->getVariantStartDate();
     if ($startDate != null && !empty($ids)) {
         $counts = $type == 'page' ? $repo->getDownloadCountsByPage($ids, $startDate) : $repo->getDownloadCountsByEmail($ids, $startDate);
         $translator = $factory->getTranslator();
         if ($counts) {
             $downloads = $support = $data = array();
             $hasResults = array();
             $downloadsLabel = $translator->trans('mautic.asset.abtest.label.downloads');
             $hitsLabel = $type == 'page' ? $translator->trans('mautic.asset.abtest.label.hits') : $translator->trans('mautic.asset.abtest.label.sentemils');
             foreach ($counts as $stats) {
                 $rate = $stats['total'] ? round($stats['count'] / $stats['total'] * 100, 2) : 0;
                 $downloads[$stats['id']] = $rate;
                 $data[$downloadsLabel][] = $stats['count'];
                 $data[$hitsLabel][] = $stats['total'];
                 $support['labels'][] = $stats['id'] . ':' . $stats['name'] . ' (' . $rate . '%)';
                 $hasResults[] = $stats['id'];
             }
             //make sure that parent and published children are included
             if (!in_array($parent->getId(), $hasResults)) {
                 $data[$downloadsLabel][] = 0;
                 $data[$hitsLabel][] = 0;
                 $support['labels'][] = $parent->getId() . ':' . ($type == 'page' ? $parent->getTitle() : $parent->getName()) . ' (0%)';
             }
             foreach ($children as $c) {
                 if ($c->isPublished()) {
                     if (!in_array($c->getId(), $hasResults)) {
                         $data[$downloadsLabel][] = 0;
                         $data[$hitsLabel][] = 0;
                         $support['labels'][] = $c->getId() . ':' . ($type == 'page' ? $c->getTitle() : $c->getName()) . ' (0%)';
                     }
                 }
             }
             $support['data'] = $data;
             //set max for scales
             $maxes = array();
             foreach ($support['data'] as $label => $data) {
                 $maxes[] = max($data);
             }
             $top = max($maxes);
             $support['step_width'] = ceil($top / 10) * 10;
             //put in order from least to greatest just because
             asort($downloads);
             //who's the winner?
             $max = max($downloads);
             //get the page ids with the most number of downloads
             $winners = $max > 0 ? array_keys($downloads, $max) : array();
             return array('winners' => $winners, 'support' => $support, 'basedOn' => 'asset.downloads', 'supportTemplate' => 'MauticPageBundle:SubscribedEvents\\AbTest:bargraph.html.php');
         }
     }
     return array('winners' => array(), 'support' => array(), 'basedOn' => 'asset.downloads');
 }
 /**
  * {@inheritDoc}
  */
 public function getVariantStartDate()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getVariantStartDate', array());
     return parent::getVariantStartDate();
 }