wrapped = $wrapped; $this->pastData = $pastData; if (empty($evolutionMetricName)) { $wrappedName = $this->getWrappedName(); $evolutionMetricName = $wrappedName . '_evolution'; } $this->evolutionMetricName = $evolutionMetricName; $this->quotientPrecision = $quotientPrecision; } public function getName() { return $this->evolutionMetricName; } public function getTranslatedName() { return $this->wrapped instanceof Metric ? $this->wrapped->getTranslatedName() : $this->getName(); } public function compute(Row $row) { $columnName = $this->getWrappedName(); $pastRow = $this->getPastRowFromCurrent($row); $currentValue = $this->getMetric($row, $columnName); $pastValue = $pastRow ? $this->getMetric($pastRow, $columnName) : 0; $dividend = $currentValue - $pastValue; $divisor = $pastValue; if ($dividend == 0) { return 0; } else if ($divisor == 0) { return 1; } else { return Piwik::getQuotientSafe($dividend, $divisor, $this->quotientPrecision + 2); } } public function format($value, Formatter $formatter) { return $formatter->getPrettyPercentFromQuotient($value); } public function getDependentMetrics() { return array($this->getWrappedName()); } protected function getWrappedName() { return $this->wrapped instanceof Metric ? $this->wrapped->getName() : $this->wrapped; } /** * public for Insights use. */ public function getPastRowFromCurrent(Row $row) { return $this->pastData->getRowFromLabel($row->getColumn('label')); } }