Esempio n. 1
0
 public function hasDataTableUsers(DataTable\DataTableInterface $result)
 {
     if ($result instanceof Map) {
         foreach ($result->getDataTables() as $table) {
             if ($this->hasDataTableUsers($table)) {
                 return true;
             }
         }
     }
     if (!$result->getRowsCount()) {
         return false;
     }
     $numUsers = $result->getColumn('nb_users');
     $numUsers = array_sum($numUsers);
     return !empty($numUsers);
 }
Esempio n. 2
0
 /**
  * That methods handles the fallback to version datatables to calculate those without versions.
  *
  * Unlike DevicesDetection plugin now, the UserSettings plugin did not store archives holding the os and browser data without
  * their version number. The "version-less" reports were always generated out of the "version-containing" archives .
  * For big archives (month/year) that ment that some of the data was truncated, due to the datatable entry limit.
  * To avoid that data loss / inaccuracy in the future, DevicesDetection plugin will also store archives without the version.
  * For data archived before DevicesDetection plugin was enabled, those archives do not exist, so we try to calculate
  * them here from the "version-containing" reports if possible.
  *
  * @param DataTable\DataTableInterface $dataTable
  * @param DataTable\DataTableInterface $dataTable2
  * @return DataTable\DataTableInterface
  */
 protected function mergeDataTables(DataTable\DataTableInterface $dataTable, DataTable\DataTableInterface $dataTable2)
 {
     if ($dataTable instanceof DataTable\Map) {
         $dataTables = $dataTable->getDataTables();
         foreach ($dataTables as $label => $table) {
             $versionDataTables = $dataTable2->getDataTables();
             if (!array_key_exists($label, $versionDataTables)) {
                 continue;
             }
             $newDataTable = $this->mergeDataTables($table, $versionDataTables[$label]);
             $dataTable->addTable($newDataTable, $label);
         }
     } else {
         if (!$dataTable->getRowsCount() && $dataTable2->getRowsCount()) {
             $dataTable2->filter('GroupBy', array('label', function ($label) {
                 if (preg_match("/(.+) [0-9]+(?:\\.[0-9]+)?\$/", $label, $matches)) {
                     return $matches[1];
                     // should match for browsers
                 }
                 if (strpos($label, ';')) {
                     return substr($label, 0, 3);
                     // should match for os
                 }
                 return $label;
             }));
             return $dataTable2;
         }
     }
     return $dataTable;
 }
Esempio n. 3
0
 private function applyFilters(DataTable\DataTableInterface $table)
 {
     foreach ($this->config->getPriorityFilters() as $filter) {
         $table->filter($filter[0], $filter[1]);
     }
     // queue other filters so they can be applied later if queued filters are disabled
     foreach ($this->config->getPresentationFilters() as $filter) {
         $table->queueFilter($filter[0], $filter[1]);
     }
     $table->applyQueuedFilters();
 }
Esempio n. 4
0
 private function handleDataTable(DataTableInterface $datatable)
 {
     $label = $this->getLabelFromRequest($this->request);
     // handle pivot by dimension filter
     $pivotBy = Common::getRequestVar('pivotBy', false, 'string', $this->request);
     if (!empty($pivotBy)) {
         $reportId = $this->apiModule . '.' . $this->apiMethod;
         $pivotByColumn = Common::getRequestVar('pivotByColumn', false, 'string', $this->request);
         $pivotByColumnLimit = Common::getRequestVar('pivotByColumnLimit', false, 'int', $this->request);
         $datatable->filter('PivotByDimension', array($reportId, $pivotBy, $pivotByColumn, $pivotByColumnLimit, PivotByDimension::isSegmentFetchingEnabledInConfig()));
     }
     // if requested, flatten nested tables
     if (Common::getRequestVar('flat', '0', 'string', $this->request) == '1') {
         $flattener = new Flattener($this->apiModule, $this->apiMethod, $this->request);
         if (Common::getRequestVar('include_aggregate_rows', '0', 'string', $this->request) == '1') {
             $flattener->includeAggregateRows();
         }
         $datatable = $flattener->flatten($datatable);
     }
     if (1 == Common::getRequestVar('totals', '1', 'integer', $this->request)) {
         $genericFilter = new ReportTotalsCalculator($this->apiModule, $this->apiMethod, $this->request);
         $datatable = $genericFilter->calculate($datatable);
     }
     // if the flag disable_generic_filters is defined we skip the generic filters
     if (0 == Common::getRequestVar('disable_generic_filters', '0', 'string', $this->request)) {
         $genericFilter = new DataTableGenericFilter($this->request);
         if (!empty($label)) {
             $genericFilter->disableFilters(array('Limit', 'Truncate'));
         }
         $genericFilter->filter($datatable);
     }
     // we automatically safe decode all datatable labels (against xss)
     $datatable->queueFilter('SafeDecodeLabel');
     // if the flag disable_queued_filters is defined we skip the filters that were queued
     if (Common::getRequestVar('disable_queued_filters', 0, 'int', $this->request) == 0) {
         $datatable->applyQueuedFilters();
     }
     // use the ColumnDelete filter if hideColumns/showColumns is provided (must be done
     // after queued filters are run so processed metrics can be removed, too)
     $hideColumns = Common::getRequestVar('hideColumns', '', 'string', $this->request);
     $showColumns = Common::getRequestVar('showColumns', '', 'string', $this->request);
     if ($hideColumns !== '' || $showColumns !== '') {
         $datatable->filter('ColumnDelete', array($hideColumns, $showColumns));
     }
     // apply label filter: only return rows matching the label parameter (more than one if more than one label)
     if (!empty($label)) {
         $addLabelIndex = Common::getRequestVar('labelFilterAddLabelIndex', 0, 'int', $this->request) == 1;
         $filter = new LabelFilter($this->apiModule, $this->apiMethod, $this->request);
         $datatable = $filter->filter($label, $datatable, $addLabelIndex);
     }
     return $this->apiRenderer->renderDataTable($datatable);
 }
 public function applyComputeProcessedMetrics(DataTableInterface $dataTable)
 {
     $dataTable->filter(array($this, 'computeProcessedMetrics'));
 }
Esempio n. 6
0
 public function hasDataTableUsers(DataTable\DataTableInterface $result)
 {
     if ($result instanceof Map) {
         foreach ($result->getDataTables() as $table) {
             if ($this->hasDataTableUsers($table)) {
                 return true;
             }
         }
     }
     if (!$result->getRowsCount()) {
         return false;
     }
     $firstRow = $result->getFirstRow();
     if ($firstRow instanceof DataTable\Row && $firstRow->hasColumn(Metrics::INDEX_NB_USERS)) {
         $metric = Metrics::INDEX_NB_USERS;
     } else {
         $metric = 'nb_users';
     }
     $numUsers = $result->getColumn($metric);
     $numUsers = array_sum($numUsers);
     return !empty($numUsers);
 }
Esempio n. 7
0
 private function addPageProcessedMetrics(DataTable\DataTableInterface $dataTable)
 {
     $dataTable->filter(function (DataTable $table) {
         $extraProcessedMetrics = $table->getMetadata(DataTable::EXTRA_PROCESSED_METRICS_METADATA_NAME);
         $extraProcessedMetrics[] = new AverageTimeOnPage();
         $extraProcessedMetrics[] = new BounceRate();
         $extraProcessedMetrics[] = new ExitRate();
         $extraProcessedMetrics[] = new AveragePageGenerationTime();
         $table->setMetadata(DataTable::EXTRA_PROCESSED_METRICS_METADATA_NAME, $extraProcessedMetrics);
     });
 }