/**
  * Constructor.
  *
  * @param DataTable $table The table to pivot.
  * @param string $report The ID of the report being pivoted, eg, `'Referrers.getKeywords'`.
  * @param string $pivotByDimension The ID of the dimension to pivot by, eg, `'Referrers.Keyword'`.
  * @param string|false $pivotColumn The metric that should be displayed in the pivot table, eg, `'nb_visits'`.
  *                                  If `false`, the first non-label column is used.
  * @param false|int $pivotByColumnLimit The number of columns to limit the pivot table to.
  * @param bool $isFetchingBySegmentEnabled Whether to allow fetching by segment.
  * @throws Exception if pivoting the report by a dimension is unsupported.
  */
 public function __construct($table, $report, $pivotByDimension, $pivotColumn, $pivotByColumnLimit = false, $isFetchingBySegmentEnabled = true)
 {
     parent::__construct($table);
     Log::debug("PivotByDimension::%s: creating with [report = %s, pivotByDimension = %s, pivotColumn = %s, " . "pivotByColumnLimit = %s, isFetchingBySegmentEnabled = %s]", __FUNCTION__, $report, $pivotByDimension, $pivotColumn, $pivotByColumnLimit, $isFetchingBySegmentEnabled);
     $this->pivotColumn = $pivotColumn;
     $this->pivotByColumnLimit = $pivotByColumnLimit ?: self::getDefaultColumnLimit();
     $this->isFetchingBySegmentEnabled = $isFetchingBySegmentEnabled;
     $namesToId = Metrics::getMappingFromNameToId();
     $this->metricIndexValue = isset($namesToId[$this->pivotColumn]) ? $namesToId[$this->pivotColumn] : null;
     $this->setPivotByDimension($pivotByDimension);
     $this->setThisReportMetadata($report);
     $this->checkSupportedPivot();
 }
Exemple #2
0
 /**
  * @group Core
  */
 public function testGetMappingFromIdToName()
 {
     $mapping = Metrics::getMappingFromNameToId();
     $expectedMapping = array('nb_uniq_visitors' => 1, 'nb_visits' => 2, 'nb_actions' => 3, 'max_actions' => 4, 'sum_visit_length' => 5, 'bounce_count' => 6, 'nb_users' => 39, 'nb_visits_converted' => 7, 'nb_conversions' => 8, 'revenue' => 23, 'goals' => 10, 'sum_daily_nb_uniq_visitors' => 11, 'sum_daily_nb_users' => 40, 'nb_hits' => 12, 'sum_time_spent' => 13, 'sum_time_generation' => 30, 'nb_hits_with_time_generation' => 31, 'min_time_generation' => 32, 'max_time_generation' => 33, 'exit_nb_uniq_visitors' => 14, 'exit_nb_visits' => 15, 'sum_daily_exit_nb_uniq_visitors' => 16, 'entry_nb_uniq_visitors' => 17, 'sum_daily_entry_nb_uniq_visitors' => 18, 'entry_nb_visits' => 19, 'entry_nb_actions' => 20, 'entry_sum_visit_length' => 21, 'entry_bounce_count' => 22, 'nb_hits_following_search' => 29, 'quantity' => 24, 'price' => 25, 'price_viewed' => 27, 'orders' => 26, 'nb_events' => 34, 'sum_event_value' => 35, 'min_event_value' => 36, 'max_event_value' => 37, 'nb_events_with_value' => 38, 'nb_impressions' => 41, 'nb_interactions' => 42, 'nb_uniq_fingerprints' => 43);
     $this->assertEquals($expectedMapping, $mapping);
 }
Exemple #3
0
 /**
  * Helper method that determines the actual column for a metric in a {@link Piwik\DataTable}.
  *
  * @param DataTable $table
  * @param string $columnName
  * @param int[]|null $mappingNameToId A custom mapping of metric names to special index values. By
  *                                    default {@link Metrics::getMappingFromNameToId()} is used.
  * @return string
  */
 public static function getActualMetricColumn(DataTable $table, $columnName, $mappingNameToId = null)
 {
     if (empty($mappingIdToName)) {
         $mappingNameToId = Metrics::getMappingFromNameToId();
     }
     $firstRow = $table->getFirstRow();
     if (!empty($firstRow) && $firstRow->getColumn($columnName) === false) {
         $columnName = $mappingNameToId[$columnName];
     }
     return $columnName;
 }
 /**
  * Sets the column to be used for Excluding low population
  *
  * @param DataTable\Row $row
  * @return int
  */
 private function selectColumnToExclude($columnToFilter, $row)
 {
     if ($row->hasColumn($columnToFilter)) {
         return $columnToFilter;
     }
     // filter_excludelowpop=nb_visits but the column name is still Metrics::INDEX_NB_VISITS in the table
     $columnIdToName = Metrics::getMappingFromNameToId();
     if (isset($columnIdToName[$columnToFilter])) {
         $column = $columnIdToName[$columnToFilter];
         if ($row->hasColumn($column)) {
             return $column;
         }
     }
     return $columnToFilter;
 }
Exemple #5
0
 /**
  * Sets the column to be used for sorting
  *
  * @param Row $row
  * @return int
  */
 protected function selectColumnToSort($row)
 {
     $value = $row->hasColumn($this->columnToSort);
     if ($value) {
         return $this->columnToSort;
     }
     $columnIdToName = Metrics::getMappingFromNameToId();
     // sorting by "nb_visits" but the index is Metrics::INDEX_NB_VISITS in the table
     if (isset($columnIdToName[$this->columnToSort])) {
         $column = $columnIdToName[$this->columnToSort];
         $value = $row->hasColumn($column);
         if ($value) {
             return $column;
         }
     }
     // eg. was previously sorted by revenue_per_visit, but this table
     // doesn't have this column; defaults with nb_visits
     $column = Metrics::INDEX_NB_VISITS;
     $value = $row->hasColumn($column);
     if ($value) {
         return $column;
     }
     // even though this column is not set properly in the table,
     // we select it for the sort, so that the table's internal state is set properly
     return $this->columnToSort;
 }