Beispiel #1
0
 /**
  * Sums the given `$rowToSum` columns values to the existing row column values.
  * Only the int or float values will be summed. Label columns will be ignored
  * even if they have a numeric value.
  *
  * Columns in `$rowToSum` that don't exist in `$this` are added to `$this`.
  *
  * @param \Piwik\DataTable\Row $rowToSum The row to sum to this row.
  * @param bool $enableCopyMetadata Whether metadata should be copied or not.
  * @param array $aggregationOperations for columns that should not be summed, determine which
  *                                     aggregation should be used (min, max). format:
  *                                     `array('column name' => 'function name')`
  */
 public function sumRow(Row $rowToSum, $enableCopyMetadata = true, $aggregationOperations = false)
 {
     foreach ($rowToSum->getColumnsRaw() as $columnToSumName => $columnToSumValue) {
         if (!$this->isSummableColumn($columnToSumName)) {
             continue;
         }
         if ($this->isColumnValueCallable($columnToSumValue)) {
             $this->setColumn($columnToSumName, $columnToSumValue);
             continue;
         }
         $thisColumnValue = $this->getColumn($columnToSumName);
         $operation = 'sum';
         if (is_array($aggregationOperations) && isset($aggregationOperations[$columnToSumName])) {
             $operation = strtolower($aggregationOperations[$columnToSumName]);
         }
         // max_actions is a core metric that is generated in ArchiveProcess_Day. Therefore, it can be
         // present in any data table and is not part of the $aggregationOperations mechanism.
         if ($columnToSumName == Metrics::INDEX_MAX_ACTIONS) {
             $operation = 'max';
         }
         if (empty($operation)) {
             throw new Exception("Unknown aggregation operation for column {$columnToSumName}.");
         }
         $newValue = $this->getColumnValuesMerged($operation, $thisColumnValue, $columnToSumValue);
         $this->setColumn($columnToSumName, $newValue);
     }
     if ($enableCopyMetadata) {
         $this->sumRowMetadata($rowToSum);
     }
 }