예제 #1
0
파일: API.php 프로젝트: a4tunado/piwik
 /**
  * Common filters for Page URLs and Page Titles
  *
  * @param DataTable|DataTable\Simple|DataTable\Map $dataTable
  */
 protected function filterPageDatatable($dataTable)
 {
     $columnsToRemove = array('bounce_rate');
     $dataTable->queueFilter('ColumnDelete', array($columnsToRemove));
     // Average time on page = total time on page / number visits on that page
     $dataTable->queueFilter('ColumnCallbackAddColumnQuotient', array('avg_time_on_page', 'sum_time_spent', 'nb_visits', 0));
     // Bounce rate = single page visits on this page / visits started on this page
     $dataTable->queueFilter('ColumnCallbackAddColumnPercentage', array('bounce_rate', 'entry_bounce_count', 'entry_nb_visits', 0));
     // % Exit = Number of visits that finished on this page / visits on this page
     $dataTable->queueFilter('ColumnCallbackAddColumnPercentage', array('exit_rate', 'exit_nb_visits', 'nb_visits', 0));
     // Handle performance analytics
     $hasTimeGeneration = array_sum($dataTable->getColumn(Metrics::INDEX_PAGE_SUM_TIME_GENERATION)) > 0;
     if ($hasTimeGeneration) {
         // Average generation time = total generation time / number of pageviews
         $precisionAvgTimeGeneration = 3;
         $dataTable->queueFilter('ColumnCallbackAddColumnQuotient', array('avg_time_generation', 'sum_time_generation', 'nb_hits_with_time_generation', $precisionAvgTimeGeneration));
         $dataTable->queueFilter('ColumnDelete', array(array('sum_time_generation')));
     } else {
         // No generation time: remove it from the API output and add it to empty_columns metadata, so that
         // the columns can also be removed from the view
         $dataTable->filter('ColumnDelete', array(array(Metrics::INDEX_PAGE_SUM_TIME_GENERATION, Metrics::INDEX_PAGE_NB_HITS_WITH_TIME_GENERATION, Metrics::INDEX_PAGE_MIN_TIME_GENERATION, Metrics::INDEX_PAGE_MAX_TIME_GENERATION)));
         if ($dataTable instanceof DataTable) {
             $emptyColumns = $dataTable->getMetadata(DataTable::EMPTY_COLUMNS_METADATA_NAME);
             if (!is_array($emptyColumns)) {
                 $emptyColumns = array();
             }
             $emptyColumns[] = 'sum_time_generation';
             $emptyColumns[] = 'avg_time_generation';
             $emptyColumns[] = 'min_time_generation';
             $emptyColumns[] = 'max_time_generation';
             $dataTable->setMetadata(DataTable::EMPTY_COLUMNS_METADATA_NAME, $emptyColumns);
         }
     }
 }
예제 #2
0
 /**
  * Sets the total evolution metadata for a datatable returned by $this->buildDataTable
  * given data for the last period.
  *
  * @param DataTable|DataTable\Map $dataTable
  * @param DataTable|DataTable\Map $pastData
  * @param array $apiMetrics Metrics info.
  */
 private function setPastDataMetadata($dataTable, $pastData, $apiMetrics)
 {
     if ($dataTable instanceof DataTable\Map) {
         $pastArray = $pastData->getDataTables();
         foreach ($dataTable->getDataTables() as $subTable) {
             $this->setPastDataMetadata($subTable, current($pastArray), $apiMetrics);
             next($pastArray);
         }
     } else {
         // calculate total visits/actions/revenue for past data
         $this->setMetricsTotalsMetadata($pastData, $apiMetrics);
         foreach ($apiMetrics as $label => $metricInfo) {
             // get the names of metadata to set
             $totalMetadataName = self::getTotalMetadataName($label);
             $lastPeriodTotalMetadataName = self::getLastPeriodMetadataName($totalMetadataName);
             $totalEvolutionMetadataName = self::getTotalMetadataName($metricInfo[self::METRIC_EVOLUTION_COL_NAME_KEY]);
             // set last period total
             $pastTotal = $pastData->getMetadata($totalMetadataName);
             $dataTable->setMetadata($lastPeriodTotalMetadataName, $pastTotal);
             // calculate & set evolution
             $currentTotal = $dataTable->getMetadata($totalMetadataName);
             $evolution = CalculateEvolutionFilter::calculate($currentTotal, $pastTotal);
             $dataTable->setMetadata($totalEvolutionMetadataName, $evolution);
         }
     }
 }