diff --git a/core/API/DataTableGenericFilter.php b/core/API/DataTableGenericFilter.php index 681c1a12f8e72bcb6c4d972ddacf71584ee4b58f..9cb7599147ee1197d49abe70e34309142464dfca 100644 --- a/core/API/DataTableGenericFilter.php +++ b/core/API/DataTableGenericFilter.php @@ -12,6 +12,8 @@ use Exception; use Piwik\Common; use Piwik\DataTable\Filter\AddColumnsProcessedMetricsGoal; use Piwik\DataTable; +use Piwik\Plugin\ProcessedMetric; +use Piwik\Plugin\Report; class DataTableGenericFilter { @@ -22,14 +24,22 @@ class DataTableGenericFilter */ private $disabledFilters = array(); + /** + * TODO + * + * @var Report|null- + */ + private $report; + /** * Constructor * * @param $request */ - function __construct($request) + function __construct($request, $report = null) { $this->request = $request; + $this->report = $report; } /** @@ -105,7 +115,7 @@ class DataTableGenericFilter 'filter_offset' => array('integer', '0'), 'filter_limit' => array('integer'), 'keep_summary_row' => array('integer', '0'), - )), + )) ); } @@ -126,6 +136,8 @@ class DataTableGenericFilter return; } + $computed = $this->computeProcessedMetricsIfNeeded($datatable); + $genericFilters = self::getGenericFiltersInformation(); $filterApplied = false; @@ -164,6 +176,52 @@ class DataTableGenericFilter $filterApplied = true; } } + + if (!$computed) { + $this->computeProcessedMetrics($datatable); + } + return $filterApplied; } -} + + private function computeProcessedMetricsIfNeeded(DataTable $dataTable) + { + if (!$this->doesColumnQueryParamReferenceProcessedMetric()) { + return false; + } + + $this->computeProcessedMetrics($dataTable); + + return true; + } + + private function computeProcessedMetrics(DataTable $dataTable) + { + if (empty($this->report)) { + return; + } + + $this->report->computeProcessedMetrics($dataTable); + } + + private function doesColumnQueryParamReferenceProcessedMetric() + { + $columnQueryParameters = array( + 'filter_column', + 'filter_column_recursive', + 'filter_excludelowpop', + 'filter_sort_column' + ); + + foreach ($columnQueryParameters as $queryParamName) { + $queryParamValue = Common::getRequestVar($queryParamName, false); + if (!empty($queryParamValue) + && ProcessedMetric::isProcessedMetric($queryParamValue) // TODO + ) { + return true; + } + } + + return false; + } +} \ No newline at end of file diff --git a/core/API/ResponseBuilder.php b/core/API/ResponseBuilder.php index b2e8bd9aea9ab02c1c38ca98dabc86a54dce9da8..49cb4c2f51c78186dbc7bda0db4412e76fe40324 100644 --- a/core/API/ResponseBuilder.php +++ b/core/API/ResponseBuilder.php @@ -169,6 +169,7 @@ class ResponseBuilder private function handleDataTable(DataTableInterface $datatable) { $label = $this->getLabelFromRequest($this->request); + $report = Report::factory($this->apiModule, $this->apiMethod); // handle pivot by dimension filter $pivotBy = Common::getRequestVar('pivotBy', false, 'string', $this->request); @@ -195,14 +196,9 @@ class ResponseBuilder $datatable = $genericFilter->calculate($datatable); } - $report = Report::factory($this->apiModule, $this->apiMethod); - if (!empty($report)) { - $datatable->filter('ComputeProcessedMetrics', array($report)); - } - // 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); + $genericFilter = new DataTableGenericFilter($this->request, $report); if (!empty($label)) { $genericFilter->disableFilters(array('Limit', 'Truncate')); } @@ -243,7 +239,7 @@ class ResponseBuilder if (!($this->apiRenderer instanceof Original) && !empty($report) ) { - $datatable->filter('FormatProcessedMetrics', array($report)); + $datatable->filter(array($report, 'formatProcessedMetrics')); } return $this->apiRenderer->renderDataTable($datatable); diff --git a/core/DataTable.php b/core/DataTable.php index 4d308f7d21c914bfeca5168babd5a933468320c0..089f1a63fa3a3de43292aba70661dc642b183461 100644 --- a/core/DataTable.php +++ b/core/DataTable.php @@ -199,6 +199,11 @@ class DataTable implements DataTableInterface, \IteratorAggregate, \ArrayAccess /** The original label of the Summary Row. */ const LABEL_SUMMARY_ROW = -1; + /** + * TODO + */ + const EXTRA_PROCESSED_METRICS_METADATA_NAME = 'extra_processed_metrics'; + /** * Maximum nesting level. */ diff --git a/core/DataTable/Filter/AddColumnsProcessedMetrics.php b/core/DataTable/Filter/AddColumnsProcessedMetrics.php index f3d8191b1f9d40c149b2320d10eb4e286ea225c3..06cdc154ea11cf927a2c5e2a58e1d51bb4f58022 100644 --- a/core/DataTable/Filter/AddColumnsProcessedMetrics.php +++ b/core/DataTable/Filter/AddColumnsProcessedMetrics.php @@ -12,6 +12,10 @@ use Piwik\DataTable\BaseFilter; use Piwik\DataTable\Row; use Piwik\DataTable; use Piwik\Metrics; +use Piwik\Plugins\CoreHome\Metrics\ActionsPerVisit; +use Piwik\Plugins\CoreHome\Metrics\AverageTimeOnSite; +use Piwik\Plugins\CoreHome\Metrics\BounceRate; +use Piwik\Plugins\CoreHome\Metrics\ConversionRate; /** * Adds processed metrics columns to a {@link DataTable} using metrics that already exist. @@ -65,25 +69,14 @@ class AddColumnsProcessedMetrics extends BaseFilter $this->deleteRowsWithNoVisit($table); } - $metrics = new Metrics\Processed(); - - foreach ($table->getRows() as $row) { - $this->tryToAddColumn($row, 'conversion_rate', array($metrics, 'getConversionRate')); - $this->tryToAddColumn($row, 'nb_actions_per_visit', array($metrics, 'getActionsPerVisit')); - $this->tryToAddColumn($row, 'avg_time_on_site', array($metrics, 'getAvgTimeOnSite')); - $this->tryToAddColumn($row, 'bounce_rate', array($metrics, 'getBounceRate')); + $extraProcessedMetrics = $table->getMetadata(DataTable::EXTRA_PROCESSED_METRICS_METADATA_NAME); - $this->filterSubTable($row); - } - } + $extraProcessedMetrics[] = new ConversionRate(); + $extraProcessedMetrics[] = new ActionsPerVisit(); + $extraProcessedMetrics[] = new AverageTimeOnSite(); + $extraProcessedMetrics[] = new BounceRate(); - private function tryToAddColumn(Row $row, $column, $callable) - { - try { - $row->addColumn($column, $callable); - } catch (\Exception $e) { - - } + $table->setMetadata(DataTable::EXTRA_PROCESSED_METRICS_METADATA_NAME, $extraProcessedMetrics); } private function deleteRowsWithNoVisit(DataTable $table) @@ -102,4 +95,4 @@ class AddColumnsProcessedMetrics extends BaseFilter } } } -} +} \ No newline at end of file diff --git a/core/DataTable/Filter/ComputeProcessedMetrics.php b/core/DataTable/Filter/ComputeProcessedMetrics.php deleted file mode 100644 index d4632123689bc658e4ec80fb34f888766d6376af..0000000000000000000000000000000000000000 --- a/core/DataTable/Filter/ComputeProcessedMetrics.php +++ /dev/null @@ -1,66 +0,0 @@ -<?php -/** - * Piwik - free/libre analytics platform - * - * @link http://piwik.org - * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later - * - */ -namespace Piwik\DataTable\Filter; - -use Exception; -use Piwik\DataTable\BaseFilter; -use Piwik\DataTable; -use Piwik\Plugin\ProcessedMetric; -use Piwik\Plugin\Report; - -/** - * TODO - */ -class ComputeProcessedMetrics extends BaseFilter -{ - /** - * TODO - * - * @var Report - */ - private $report; - - /** - * Constructor. - * - * @param DataTable $table The table that will be filtered. - * @param Report $report The report metadata. - */ - public function __construct($table, Report $report) - { - parent::__construct($table); - - $this->report = $report; - } - - /** - * Executes the filter. See {@link ComputeProcessedMetrics}. - * - * @param DataTable $table - */ - public function filter($table) - { - $processedMetrics = $this->report->processedMetrics; - if (!is_array($processedMetrics)) { - return; - } - - foreach ($table->getRows() as $row) { - /** @var ProcessedMetric $processedMetric */ // TODO: should remove this and if below eventually. - foreach ($processedMetrics as $processedMetric) { - if ($processedMetric instanceof ProcessedMetric) { - $processedMetricName = $processedMetric->getName(); - if ($row->getColumn($processedMetricName) === false) { - $row->addColumn($processedMetricName, $processedMetric->compute($row)); - } - } - } - } - } -} \ No newline at end of file diff --git a/core/DataTable/Filter/FormatProcessedMetrics.php b/core/DataTable/Filter/FormatProcessedMetrics.php deleted file mode 100644 index d612ecaedd4bef3a559c10c2d1422049d91d1959..0000000000000000000000000000000000000000 --- a/core/DataTable/Filter/FormatProcessedMetrics.php +++ /dev/null @@ -1,65 +0,0 @@ -<?php -/** - * Piwik - free/libre analytics platform - * - * @link http://piwik.org - * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later - * - */ -namespace Piwik\DataTable\Filter; - -use Exception; -use Piwik\DataTable\BaseFilter; -use Piwik\DataTable; -use Piwik\Plugin\ProcessedMetric; -use Piwik\Plugin\Report; - -/** - * TODO - */ -class FormatProcessedMetrics extends BaseFilter -{ - /** - * TODO - */ - private $report; - - /** - * Constructor. - *TODO modify - * @param DataTable $table The table that will be filtered. - */ - public function __construct($table, Report $report) - { - parent::__construct($table); - - $this->report = $report; - } - - /** - * Executes the filter. See {@link ComputeProcessedMetrics}. - * - * @param DataTable $table - */ - public function filter($table) - { - $processedMetrics = $this->report->processedMetrics; - if (empty($processedMetrics)) { - return; - } - - foreach ($table->getRows() as $row) { - foreach ($processedMetrics as $processedMetric) { - if (!($processedMetric instanceof ProcessedMetric)) { - continue; - } - - $name = $processedMetric->getName(); - $columnValue = $row->getColumn($name); - if ($columnValue !== false) { - $row->setColumn($name, $processedMetric->format($columnValue)); - } - } - } - } -} \ No newline at end of file diff --git a/core/DataTable/Filter/PivotByDimension.php b/core/DataTable/Filter/PivotByDimension.php index ce3ac98ec57222653a42da3024bc9c5cd7cca7e0..61e68423e8da3b1b8da027e1d3f18cacb704d805 100644 --- a/core/DataTable/Filter/PivotByDimension.php +++ b/core/DataTable/Filter/PivotByDimension.php @@ -161,7 +161,7 @@ class PivotByDimension extends BaseFilter $this->pivotByColumnLimit = $pivotByColumnLimit ?: self::getDefaultColumnLimit(); $this->isFetchingBySegmentEnabled = $isFetchingBySegmentEnabled; - $namesToId = Metrics::getMappingFromIdToName(); + $namesToId = Metrics::getMappingFromNameToId(); $this->metricIndexValue = isset($namesToId[$this->pivotColumn]) ? $namesToId[$this->pivotColumn] : null; $this->setPivotByDimension($pivotByDimension); diff --git a/core/DataTable/Filter/Sort.php b/core/DataTable/Filter/Sort.php index 9df22502887258ba8ed4ab17026a04e9a8b7151f..6ffe33bcedb412bd436a7fd51c86c5487364b533 100644 --- a/core/DataTable/Filter/Sort.php +++ b/core/DataTable/Filter/Sort.php @@ -192,7 +192,7 @@ class Sort extends BaseFilter return $this->columnToSort; } - $columnIdToName = Metrics::getMappingFromIdToName(); + $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]; diff --git a/core/Metrics.php b/core/Metrics.php index 0f8baf5a10f7403eb6aac173cba32d6f530c07c1..01e2e66ca2d306d052a351c40bf746a9a43e2db6 100644 --- a/core/Metrics.php +++ b/core/Metrics.php @@ -183,10 +183,12 @@ class Metrics return $names; } - // TODO: this method is named wrong - public static function getMappingFromIdToName() + public static function getMappingFromNameToId() { - $idToName = array_flip(self::$mappingFromIdToName); + static $idToName = null; + if ($idToName === null) { + $idToName = array_flip(self::$mappingFromIdToName); + } return $idToName; } diff --git a/core/Metrics/Processed.php b/core/Metrics/Processed.php index 0e6b7c969be13bcbed478d8486ff89264906ac15..5fe38e9363aaf6185e7b89249879d5815de53873 100644 --- a/core/Metrics/Processed.php +++ b/core/Metrics/Processed.php @@ -4,7 +4,6 @@ * * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later - * */ namespace Piwik\Metrics; @@ -12,6 +11,7 @@ use Piwik\Metrics; use Piwik\DataTable\Row; use Piwik\DataTable; +// TODO: this class should be removed class Processed extends Base { @@ -60,9 +60,8 @@ class Processed extends Base return $this->invalidDivision; } - $bounceRate = round(100 * $this->getColumn($row, Metrics::INDEX_BOUNCE_COUNT) / $nbVisits, $this->roundPrecision); + $bounceRate = round($this->getColumn($row, Metrics::INDEX_BOUNCE_COUNT) / $nbVisits, $this->roundPrecision); - return $bounceRate . "%"; + return $bounceRate; } - } \ No newline at end of file diff --git a/core/Plugin/AggregatedMetric.php b/core/Plugin/AggregatedMetric.php new file mode 100644 index 0000000000000000000000000000000000000000..5bdf8d4e1e284c0085e4e3885d202af2938ebdba --- /dev/null +++ b/core/Plugin/AggregatedMetric.php @@ -0,0 +1,18 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ +namespace Piwik\Plugin; + +use Piwik\DataTable\Row; + +/** + * TODO + */ +abstract class AggregatedMetric extends Metric +{ + // stub, to be filled out later +} \ No newline at end of file diff --git a/core/Plugin/ComponentFactory.php b/core/Plugin/ComponentFactory.php index 9cb9cd1c1b31ec4027f3bcfd9cb488502777d083..68415e939762840b7231d07bc203f8869f58da33 100644 --- a/core/Plugin/ComponentFactory.php +++ b/core/Plugin/ComponentFactory.php @@ -74,7 +74,7 @@ class ComponentFactory * @param callback $predicate * @return mixed The component that satisfies $predicate or null if not found. */ - public static function getComponentif ($componentTypeClass, $pluginName, $predicate) + public static function getComponentIf($componentTypeClass, $pluginName, $predicate) { $pluginManager = PluginManager::getInstance(); diff --git a/core/Plugin/Metric.php b/core/Plugin/Metric.php index 09c8d2298e7586ad05ca2dcebd0a40f6962c3630..3728dacac5f086c6a9a6998e61e71f904a6a42c3 100644 --- a/core/Plugin/Metric.php +++ b/core/Plugin/Metric.php @@ -8,6 +8,7 @@ namespace Piwik\Plugin; use Piwik\DataTable\Row; +use Piwik\Metrics; /** * TODO @@ -45,4 +46,36 @@ abstract class Metric * TODO */ abstract public function getName(); + + /** + * TODO + */ + abstract public function getTranslatedName(); + + /** + * TODO + */ + public function format($value) + { + return $value; + } + + /** + * TODO + */ + public function getColumn(Row $row, $columnName, $mappingIdToName = null) + { + if (empty($mappingIdToName)) { + $mappingIdToName = Metrics::getMappingFromNameToId(); + } + + $value = $row->getColumn($columnName); + if ($value === false + && isset($mappingIdToName[$columnName]) + ) { + $value = $row->getColumn($mappingIdToName[$columnName]); + } + + return $value; + } } \ No newline at end of file diff --git a/core/Plugin/ProcessedMetric.php b/core/Plugin/ProcessedMetric.php index 9fcf1f5767af7b27abfe5a905297072bec560089..da0fdbea0f25e8c3ca96e2981c179c2d527a7c3a 100644 --- a/core/Plugin/ProcessedMetric.php +++ b/core/Plugin/ProcessedMetric.php @@ -12,7 +12,7 @@ use Piwik\DataTable\Row; /** * TODO */ -abstract class ProcessedMetric +abstract class ProcessedMetric extends Metric { /** * The sub-namespace name in a plugin where Report components are stored. @@ -42,18 +42,10 @@ abstract class ProcessedMetric /** * TODO */ - abstract public function getName(); - - /** - * TODO - */ - public function format($value) - { - return $value; - } + abstract public function compute(Row $row); /** * TODO */ - abstract public function compute(Row $row); + abstract public function getDependenctMetrics(); } \ No newline at end of file diff --git a/core/Plugin/Report.php b/core/Plugin/Report.php index 4f8e357624a1262f83b2503b61c2d3d263da21b8..76e8f66f45970cf814162d1f5d72b8f3e41a4414 100644 --- a/core/Plugin/Report.php +++ b/core/Plugin/Report.php @@ -367,6 +367,33 @@ class Report return $this->getMetricTranslations($this->metrics); } + /** + * TODO + */ + public function getMetricsRequiredForReport($allColumns = null, $restrictToColumns = null) + { + if (empty($allColumns)) { + $allColumns = $this->metrics; + } + + if (empty($restrictToColumns)) { + return $allColumns; + } else { + $processedMetricsById = $this->getProcessedMetricsById(); + $metricsSet = array_flip($allColumns); + + $metrics = array(); + foreach ($restrictToColumns as $column) { + if (isset($processedMetricsById[$column])) { + $metrics = array_merge($metrics, $processedMetricsById[$column]->getDependenctMetrics()); + } else if (isset($metricsSet[$column])) { // TODO: this may cause regression w/ #2531, check? + $metrics[] = $column; + } + } + return array_unique($metrics); + } + } + /** * Returns an array of supported processed metrics and their corresponding translations. Eg * `array('nb_visits' => 'Visits')`. By default the given {@link $processedMetrics} are used and their @@ -655,6 +682,70 @@ class Report return Request::processRequest($module . '.' . $action, $paramOverride); } + /** + * TODO + * TODO: recursion (+ for format) + */ + public function computeProcessedMetrics(DataTable $dataTable) + { + $processedMetrics = $this->getProcessedMetricsFor($dataTable); + if (empty($processedMetrics)) { + return; + } + + foreach ($dataTable->getRows() as $row) { + /** @var ProcessedMetric $processedMetric */ + foreach ($processedMetrics as $name => $processedMetric) { + if ($row->getColumn($name) === false) { // do not compute the metric if it has been computed already + $row->addColumn($name, $processedMetric->compute($row)); + } + } + } + } + + /** + * TODO + * + * @return ProcessedMetric[] + */ + public function getProcessedMetricsFor(DataTable $dataTable) + { + $dataTableProcessedMetrics = $dataTable->getMetadata(DataTable::EXTRA_PROCESSED_METRICS_METADATA_NAME) ?: array(); + + $processedMetrics = $this->processedMetrics ?: array(); + $processedMetrics = array_merge($processedMetrics, $dataTableProcessedMetrics); + + $result = array(); + foreach ($processedMetrics as $metric) { + if (!($metric instanceof ProcessedMetric)) { + continue; + } + + $result[$metric->getName()] = $metric; + } + return $result; + } + + /** + * TODO + */ + public function formatProcessedMetrics(DataTable $dataTable) + { + $processedMetrics = $this->getProcessedMetricsFor($dataTable); + if (empty($processedMetrics)) { + return; + } + + foreach ($dataTable->getRows() as $row) { + foreach ($processedMetrics as $name => $processedMetric) { + $columnValue = $row->getColumn($name); + if ($columnValue !== false) { + $row->setColumn($name, $processedMetric->format($columnValue)); + } + } + } + } + /** * Get an instance of a specific report belonging to the given module and having the given action. * @param string $module @@ -751,10 +842,24 @@ class Report */ public static function getForDimension(Dimension $dimension) { - return ComponentFactory::getComponentif (__CLASS__, $dimension->getModule(), function (Report $report) use ($dimension) { + return ComponentFactory::getComponentIf(__CLASS__, $dimension->getModule(), function (Report $report) use ($dimension) { return !$report->isSubtableReport() && $report->getDimension() && $report->getDimension()->getId() == $dimension->getId(); }); } + + /** + * @return ProcessedMetric[] + */ + private function getProcessedMetricsById() + { + $result = array(); + foreach ($this->processedMetrics as $processedMetric) { + if ($processedMetric instanceof ProcessedMetric) { // instanceof check for backwards compatibility + $result[$processedMetric->getName()] = $processedMetric; + } + } + return $result; + } } diff --git a/plugins/API/API.php b/plugins/API/API.php index 405d5d7b3a53f2f89308ba579397d2bb3cf5432a..9d7d3641871ad037edd16803004e7a66820a2612 100644 --- a/plugins/API/API.php +++ b/plugins/API/API.php @@ -22,7 +22,6 @@ use Piwik\Period; use Piwik\Period\Range; use Piwik\Piwik; use Piwik\Plugin\Dimension\VisitDimension; -use Piwik\Plugin\Report; use Piwik\Plugins\CoreAdminHome\CustomLogo; use Piwik\SegmentExpression; use Piwik\Translate; @@ -363,8 +362,7 @@ class API extends \Piwik\Plugin\API */ public function get($idSite, $period, $date, $segment = false, $columns = false) { - $columnsToShow = Piwik::getArrayFromApiParameter($columns); - $columns = array(); + $columns = Piwik::getArrayFromApiParameter($columns); // build columns map for faster checks later on $columnsMap = array(); @@ -374,7 +372,6 @@ class API extends \Piwik\Plugin\API // find out which columns belong to which plugin $columnsByPlugin = array(); - $allColumns = array(); $meta = \Piwik\Plugins\API\API::getInstance()->getReportMetadata($idSite, $period, $date); foreach ($meta as $reportMeta) { // scan all *.get reports @@ -391,7 +388,6 @@ class API extends \Piwik\Plugin\API || empty($columnsMap) ) { $columnsByPlugin[$plugin][] = $column; - $allColumns[] = $column; } } } @@ -403,10 +399,11 @@ class API extends \Piwik\Plugin\API foreach ($columnsByPlugin as $plugin => $columns) { // load the data $className = Request::getClassNameAPI($plugin); - $params['columns'] = ""; + $params['columns'] = implode(',', $columns); $dataTable = Proxy::getInstance()->call($className, 'get', $params); // make sure the table has all columns + /* TODO: keep removed? $array = ($dataTable instanceof DataTable\Map ? $dataTable->getDataTables() : array($dataTable)); foreach ($array as $table) { // we don't support idSites=all&date=DATE1,DATE2 @@ -422,7 +419,7 @@ class API extends \Piwik\Plugin\API } } } - } + }*/ // merge reports if ($mergedDataTable === false) { @@ -431,11 +428,6 @@ class API extends \Piwik\Plugin\API $this->mergeDataTables($mergedDataTable, $dataTable); } } - - if (!empty($columnsToShow)) { - $mergedDataTable->filter('ColumnDelete', array(array(), $columnsToShow)); - } - return $mergedDataTable; } diff --git a/plugins/API/ProcessedReport.php b/plugins/API/ProcessedReport.php index 040e2b768d57972f81b1414edb8585222fe14be3..f3be5e33596188207ba37a2ec3974ede5132c066 100644 --- a/plugins/API/ProcessedReport.php +++ b/plugins/API/ProcessedReport.php @@ -448,6 +448,8 @@ class ProcessedReport throw new Exception("API returned an error: " . $e->getMessage() . " at " . basename($e->getFile()) . ":" . $e->getLine() . "\n"); } + $dataTable->filter(array(Report::factory($apiModule, $apiAction), 'formatProcessedMetrics')); + list($newReport, $columns, $rowsMetadata, $totals) = $this->handleTableReport($idSite, $dataTable, $reportMetadata, $showRawMetrics); foreach ($columns as &$name) { diff --git a/plugins/CoreHome/Metrics/ActionsPerVisit.php b/plugins/CoreHome/Metrics/ActionsPerVisit.php index cd6e357a2ad515ebeb3cf2c85b750299f166c158..a19fda80de047dde0bb3c5c26cf27e23be3117ae 100644 --- a/plugins/CoreHome/Metrics/ActionsPerVisit.php +++ b/plugins/CoreHome/Metrics/ActionsPerVisit.php @@ -10,6 +10,7 @@ namespace Piwik\Plugins\CoreHome\Metrics; use Piwik\DataTable\Row; use Piwik\Piwik; use Piwik\Plugin\ProcessedMetric; +use Piwik\Translate; /** * TODO @@ -23,6 +24,19 @@ class ActionsPerVisit extends ProcessedMetric public function compute(Row $row) { - return Piwik::getQuotientSafe($row->getColumn('nb_actions'), $row->getColumn('nb_visits'), $precision = 1); + $actions = $this->getColumn($row, 'nb_actions'); + $visits = $this->getColumn($row, 'nb_visits'); + + return Piwik::getQuotientSafe($actions, $visits, $precision = 2); + } + + public function getTranslatedName() + { + return Piwik::translate('General_ColumnActionsPerVisit'); + } + + public function getDependenctMetrics() + { + return array('nb_actions', 'nb_visits'); } } \ No newline at end of file diff --git a/plugins/CoreHome/Metrics/AverageTimeOnSite.php b/plugins/CoreHome/Metrics/AverageTimeOnSite.php index dda436140cc4b49313681cac775812a319d3e8b4..bdeea363ea93195c38dcbd64a921285532a97861 100644 --- a/plugins/CoreHome/Metrics/AverageTimeOnSite.php +++ b/plugins/CoreHome/Metrics/AverageTimeOnSite.php @@ -23,6 +23,19 @@ class AverageTimeOnSite extends ProcessedMetric public function compute(Row $row) { - return Piwik::getQuotientSafe($row->getColumn('sum_visit_length'), $row->getColumn('nb_visits'), $precision = 0); + $sumVisitLength = $this->getColumn($row, 'sum_visit_length'); + $nbVisits = $this->getColumn($row, 'nb_visits'); + + return Piwik::getQuotientSafe($sumVisitLength, $nbVisits, $precision = 0); + } + + public function getTranslatedName() + { + return Piwik::translate('General_ColumnAvgTimeOnSite'); + } + + public function getDependenctMetrics() + { + return array('sum_visit_length', 'nb_visits'); } } \ No newline at end of file diff --git a/plugins/CoreHome/Metrics/BounceRate.php b/plugins/CoreHome/Metrics/BounceRate.php index cd1dfca6711bf029d86fc301a792ecd41eb16bce..4fb79a52c788a9d6f5875bcbd78a8c0cc3eed1af 100644 --- a/plugins/CoreHome/Metrics/BounceRate.php +++ b/plugins/CoreHome/Metrics/BounceRate.php @@ -21,6 +21,16 @@ class BounceRate extends ProcessedMetric return 'bounce_rate'; } + public function getTranslatedName() + { + return Piwik::translate('General_ColumnBounceRate'); + } + + public function getDependenctMetrics() + { + return array('bounce_count', 'nb_visits'); + } + public function format($value) { return ($value * 100) . '%'; @@ -28,6 +38,9 @@ class BounceRate extends ProcessedMetric public function compute(Row $row) { - return Piwik::getQuotientSafe($row->getColumn('bounce_count'), $row->getColumn('nb_visits'), $precision = 2); + $bounceCount = $this->getColumn($row, 'bounce_count'); + $visits = $this->getColumn($row, 'nb_visits'); + + return Piwik::getQuotientSafe($bounceCount, $visits, $precision = 4); } } \ No newline at end of file diff --git a/plugins/CoreHome/Metrics/ConversionRate.php b/plugins/CoreHome/Metrics/ConversionRate.php new file mode 100644 index 0000000000000000000000000000000000000000..c98915a26fcdce94964c029a5e492732ecc26dfa --- /dev/null +++ b/plugins/CoreHome/Metrics/ConversionRate.php @@ -0,0 +1,46 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ +namespace Piwik\Plugins\CoreHome\Metrics; + +use Piwik\DataTable\Row; +use Piwik\Piwik; +use Piwik\Plugin\ProcessedMetric; + +/** + * TODO + */ +class ConversionRate extends ProcessedMetric +{ + public function getName() + { + return 'conversion_rate'; + } + + public function getTranslatedName() + { + return Piwik::translate('General_ColumnConversionRate'); + } + + public function getDependenctMetrics() + { + return array('nb_visits_converted', 'nb_visits'); + } + + public function format($value) + { + return ($value * 100) . '%'; + } + + public function compute(Row $row) + { + $nbVisitsConverted = $this->getColumn($row, 'nb_visits_converted'); + $nbVisits = $this->getColumn($row, 'nb_visits'); + + return Piwik::getQuotientSafe($nbVisitsConverted, $nbVisits, $precision = 4); + } +} \ No newline at end of file diff --git a/plugins/VisitFrequency/Metrics/BounceRateReturning.php b/plugins/VisitFrequency/Metrics/BounceRateReturning.php index 4137a999a5312d2f8790bdbd8b2568ab671ef7f2..d8f572c3a4d02fdbc6d6cb6b3e9d8f7953c68c5b 100644 --- a/plugins/VisitFrequency/Metrics/BounceRateReturning.php +++ b/plugins/VisitFrequency/Metrics/BounceRateReturning.php @@ -9,6 +9,7 @@ namespace Piwik\Plugins\VisitFrequency\Metrics; use Exception; use Piwik\DataTable\Row; +use Piwik\Piwik; use Piwik\Plugin\ProcessedMetric; /** @@ -21,6 +22,11 @@ class BounceRateReturning extends ProcessedMetric return 'bounce_rate_returning'; } + public function getTranslatedName() + { + return Piwik::translate('VisitFrequency_ColumnBounceRateForReturningVisits'); + } + public function format($value) { return ($value * 100) . '%'; @@ -30,4 +36,9 @@ class BounceRateReturning extends ProcessedMetric { // empty (metric is not computed, it is copied from segmented report) } + + public function getDependenctMetrics() + { + return array(); + } } \ No newline at end of file diff --git a/plugins/VisitsSummary/API.php b/plugins/VisitsSummary/API.php index 681b2d05a899d8886b3c0192ae3890484b946768..81fd49f8df7d9b92fb66eebd491dd62e2bf2b16b 100644 --- a/plugins/VisitsSummary/API.php +++ b/plugins/VisitsSummary/API.php @@ -9,8 +9,10 @@ namespace Piwik\Plugins\VisitsSummary; use Piwik\Archive; +use Piwik\Common; use Piwik\MetricsFormatter; use Piwik\Piwik; +use Piwik\Plugin\Report; use Piwik\SettingsPiwik; /** @@ -21,12 +23,16 @@ use Piwik\SettingsPiwik; */ class API extends \Piwik\Plugin\API { - public function get($idSite, $period, $date, $segment = false) + public function get($idSite, $period, $date, $segment = false, $columns = false) { Piwik::checkUserHasViewAccess($idSite); $archive = Archive::build($idSite, $period, $date, $segment); - $columns = $this->getCoreColumns($period); + $columns = Piwik::getArrayFromApiParameter($columns); + + $report = Report::factory("VisitsSummary", "get"); + $columns = $report->getMetricsRequiredForReport($this->getCoreColumns($period), $columns); + $dataTable = $archive->getDataTableFromNumeric($columns); return $dataTable; } diff --git a/tests/PHPUnit/System/expected/test_ImportLogs__VisitFrequency.get_month.xml b/tests/PHPUnit/System/expected/test_ImportLogs__VisitFrequency.get_month.xml index b876004aa6077b763d0f1f8f9ee73987c58cb33f..3633fe591455905c0e862657698625d9b314bc0e 100644 --- a/tests/PHPUnit/System/expected/test_ImportLogs__VisitFrequency.get_month.xml +++ b/tests/PHPUnit/System/expected/test_ImportLogs__VisitFrequency.get_month.xml @@ -8,7 +8,7 @@ <bounce_count_returning>1</bounce_count_returning> <sum_visit_length_returning>0</sum_visit_length_returning> <max_actions_returning>1</max_actions_returning> + <bounce_rate_returning>100%</bounce_rate_returning> <nb_actions_per_visit_returning>1</nb_actions_per_visit_returning> <avg_time_on_site_returning>0</avg_time_on_site_returning> - <bounce_rate_returning>100%</bounce_rate_returning> </result> \ No newline at end of file diff --git a/tests/PHPUnit/System/expected/test_ImportLogs__VisitFrequency.get_range.xml b/tests/PHPUnit/System/expected/test_ImportLogs__VisitFrequency.get_range.xml index 4ae0deec0190debc2f74ea785d7bacdca6457d60..f301254690deda6589c397b03bfdd8e93eb08cdc 100644 --- a/tests/PHPUnit/System/expected/test_ImportLogs__VisitFrequency.get_range.xml +++ b/tests/PHPUnit/System/expected/test_ImportLogs__VisitFrequency.get_range.xml @@ -6,7 +6,7 @@ <bounce_count_returning>8</bounce_count_returning> <sum_visit_length_returning>115</sum_visit_length_returning> <max_actions_returning>2</max_actions_returning> + <bounce_rate_returning>80%</bounce_rate_returning> <nb_actions_per_visit_returning>1.2</nb_actions_per_visit_returning> <avg_time_on_site_returning>12</avg_time_on_site_returning> - <bounce_rate_returning>80%</bounce_rate_returning> </result> \ No newline at end of file diff --git a/tests/PHPUnit/System/expected/test_ImportLogs__VisitsSummary.get_month.xml b/tests/PHPUnit/System/expected/test_ImportLogs__VisitsSummary.get_month.xml index 07e3a2a4440d36520be5277fc529eec18b06f725..327d564f479323b2855bbe76d66030db9b200090 100644 --- a/tests/PHPUnit/System/expected/test_ImportLogs__VisitsSummary.get_month.xml +++ b/tests/PHPUnit/System/expected/test_ImportLogs__VisitsSummary.get_month.xml @@ -8,7 +8,7 @@ <bounce_count>25</bounce_count> <sum_visit_length>305</sum_visit_length> <max_actions>3</max_actions> + <bounce_rate>93%</bounce_rate> <nb_actions_per_visit>1.1</nb_actions_per_visit> <avg_time_on_site>11</avg_time_on_site> - <bounce_rate>93%</bounce_rate> </result> \ No newline at end of file diff --git a/tests/PHPUnit/System/expected/test_ImportLogs_siteIdTwo_TrackedUsingLogReplay__VisitsSummary.get_month.xml b/tests/PHPUnit/System/expected/test_ImportLogs_siteIdTwo_TrackedUsingLogReplay__VisitsSummary.get_month.xml index e58092a648f4ea0f228247d3cbc00b9350284742..b0e66b928090d0ee4382471ea4bf195716dbdc83 100644 --- a/tests/PHPUnit/System/expected/test_ImportLogs_siteIdTwo_TrackedUsingLogReplay__VisitsSummary.get_month.xml +++ b/tests/PHPUnit/System/expected/test_ImportLogs_siteIdTwo_TrackedUsingLogReplay__VisitsSummary.get_month.xml @@ -8,7 +8,7 @@ <bounce_count>1</bounce_count> <sum_visit_length>0</sum_visit_length> <max_actions>1</max_actions> + <bounce_rate>100%</bounce_rate> <nb_actions_per_visit>1</nb_actions_per_visit> <avg_time_on_site>0</avg_time_on_site> - <bounce_rate>100%</bounce_rate> </result> \ No newline at end of file diff --git a/tests/PHPUnit/System/expected/test_MultipleSitesArchivingTest_sitesGroup__VisitsSummary.get_day.xml b/tests/PHPUnit/System/expected/test_MultipleSitesArchivingTest_sitesGroup__VisitsSummary.get_day.xml index fae1924b03f37c026824ce22b26d0efae65cc256..64e9c36af17ce2145e86a522483e54741011a508 100644 --- a/tests/PHPUnit/System/expected/test_MultipleSitesArchivingTest_sitesGroup__VisitsSummary.get_day.xml +++ b/tests/PHPUnit/System/expected/test_MultipleSitesArchivingTest_sitesGroup__VisitsSummary.get_day.xml @@ -8,7 +8,7 @@ <bounce_count>5</bounce_count> <sum_visit_length>0</sum_visit_length> <max_actions>1</max_actions> + <bounce_rate>100%</bounce_rate> <nb_actions_per_visit>1</nb_actions_per_visit> <avg_time_on_site>0</avg_time_on_site> - <bounce_rate>100%</bounce_rate> </result> \ No newline at end of file diff --git a/tests/PHPUnit/System/expected/test_MultipleSitesArchivingTest_sitesGroup__VisitsSummary.get_month.xml b/tests/PHPUnit/System/expected/test_MultipleSitesArchivingTest_sitesGroup__VisitsSummary.get_month.xml index fae1924b03f37c026824ce22b26d0efae65cc256..64e9c36af17ce2145e86a522483e54741011a508 100644 --- a/tests/PHPUnit/System/expected/test_MultipleSitesArchivingTest_sitesGroup__VisitsSummary.get_month.xml +++ b/tests/PHPUnit/System/expected/test_MultipleSitesArchivingTest_sitesGroup__VisitsSummary.get_month.xml @@ -8,7 +8,7 @@ <bounce_count>5</bounce_count> <sum_visit_length>0</sum_visit_length> <max_actions>1</max_actions> + <bounce_rate>100%</bounce_rate> <nb_actions_per_visit>1</nb_actions_per_visit> <avg_time_on_site>0</avg_time_on_site> - <bounce_rate>100%</bounce_rate> </result> \ No newline at end of file diff --git a/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_API_get__API.get_day.xml b/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_API_get__API.get_day.xml index 81ecc67c50c6b4d3205fe983bbffbd130d21db58..ebf215db8ead3c1a9524e21ff43e0df13c33f4ec 100644 --- a/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_API_get__API.get_day.xml +++ b/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_API_get__API.get_day.xml @@ -2,6 +2,6 @@ <result> <nb_visits>3</nb_visits> <nb_visits_converted>2</nb_visits_converted> - <avg_time_on_site>1801</avg_time_on_site> <nb_pageviews>13</nb_pageviews> + <avg_time_on_site>1801</avg_time_on_site> </result> \ No newline at end of file diff --git a/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_API_get__API.get_week.xml b/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_API_get__API.get_week.xml index 00706ea24a2c82115923f2834396f669b5813202..3194b95fa147c8a67148b934224eacc0665d90d8 100644 --- a/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_API_get__API.get_week.xml +++ b/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_API_get__API.get_week.xml @@ -2,6 +2,6 @@ <result> <nb_visits>5</nb_visits> <nb_visits_converted>4</nb_visits_converted> - <avg_time_on_site>1369</avg_time_on_site> <nb_pageviews>16</nb_pageviews> + <avg_time_on_site>1369</avg_time_on_site> </result> \ No newline at end of file diff --git a/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentAbandonedCart__VisitsSummary.get_day.xml b/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentAbandonedCart__VisitsSummary.get_day.xml index c909a67f093a335e2b3260c8f92f87c7bd8e6a61..2ecf6934746b019c8b7a6c903d049561a1d4c7fe 100644 --- a/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentAbandonedCart__VisitsSummary.get_day.xml +++ b/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentAbandonedCart__VisitsSummary.get_day.xml @@ -8,7 +8,7 @@ <bounce_count>0</bounce_count> <sum_visit_length>4682</sum_visit_length> <max_actions>6</max_actions> + <bounce_rate>0%</bounce_rate> <nb_actions_per_visit>4.5</nb_actions_per_visit> <avg_time_on_site>2341</avg_time_on_site> - <bounce_rate>0%</bounce_rate> </result> \ No newline at end of file diff --git a/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentConvertedGoalId1__VisitsSummary.get_day.xml b/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentConvertedGoalId1__VisitsSummary.get_day.xml index c48c13a998464f0f94f68742182074dda51bc344..a9d2095dfb93bff2e01487c01c02f3793441d206 100644 --- a/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentConvertedGoalId1__VisitsSummary.get_day.xml +++ b/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentConvertedGoalId1__VisitsSummary.get_day.xml @@ -8,7 +8,7 @@ <bounce_count>0</bounce_count> <sum_visit_length>721</sum_visit_length> <max_actions>4</max_actions> + <bounce_rate>0%</bounce_rate> <nb_actions_per_visit>4</nb_actions_per_visit> <avg_time_on_site>721</avg_time_on_site> - <bounce_rate>0%</bounce_rate> </result> \ No newline at end of file diff --git a/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentConvertedGoalId1__VisitsSummary.get_week.xml b/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentConvertedGoalId1__VisitsSummary.get_week.xml index c48c13a998464f0f94f68742182074dda51bc344..a9d2095dfb93bff2e01487c01c02f3793441d206 100644 --- a/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentConvertedGoalId1__VisitsSummary.get_week.xml +++ b/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentConvertedGoalId1__VisitsSummary.get_week.xml @@ -8,7 +8,7 @@ <bounce_count>0</bounce_count> <sum_visit_length>721</sum_visit_length> <max_actions>4</max_actions> + <bounce_rate>0%</bounce_rate> <nb_actions_per_visit>4</nb_actions_per_visit> <avg_time_on_site>721</avg_time_on_site> - <bounce_rate>0%</bounce_rate> </result> \ No newline at end of file diff --git a/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentDidNotConvertGoalId1__VisitsSummary.get_day.xml b/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentDidNotConvertGoalId1__VisitsSummary.get_day.xml index c909a67f093a335e2b3260c8f92f87c7bd8e6a61..2ecf6934746b019c8b7a6c903d049561a1d4c7fe 100644 --- a/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentDidNotConvertGoalId1__VisitsSummary.get_day.xml +++ b/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentDidNotConvertGoalId1__VisitsSummary.get_day.xml @@ -8,7 +8,7 @@ <bounce_count>0</bounce_count> <sum_visit_length>4682</sum_visit_length> <max_actions>6</max_actions> + <bounce_rate>0%</bounce_rate> <nb_actions_per_visit>4.5</nb_actions_per_visit> <avg_time_on_site>2341</avg_time_on_site> - <bounce_rate>0%</bounce_rate> </result> \ No newline at end of file diff --git a/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentNewVisitors__VisitsSummary.get_week.xml b/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentNewVisitors__VisitsSummary.get_week.xml index c48c13a998464f0f94f68742182074dda51bc344..a9d2095dfb93bff2e01487c01c02f3793441d206 100644 --- a/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentNewVisitors__VisitsSummary.get_week.xml +++ b/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentNewVisitors__VisitsSummary.get_week.xml @@ -8,7 +8,7 @@ <bounce_count>0</bounce_count> <sum_visit_length>721</sum_visit_length> <max_actions>4</max_actions> + <bounce_rate>0%</bounce_rate> <nb_actions_per_visit>4</nb_actions_per_visit> <avg_time_on_site>721</avg_time_on_site> - <bounce_rate>0%</bounce_rate> </result> \ No newline at end of file diff --git a/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentNoEcommerce__VisitsSummary.get_day.xml b/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentNoEcommerce__VisitsSummary.get_day.xml index c48c13a998464f0f94f68742182074dda51bc344..a9d2095dfb93bff2e01487c01c02f3793441d206 100644 --- a/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentNoEcommerce__VisitsSummary.get_day.xml +++ b/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentNoEcommerce__VisitsSummary.get_day.xml @@ -8,7 +8,7 @@ <bounce_count>0</bounce_count> <sum_visit_length>721</sum_visit_length> <max_actions>4</max_actions> + <bounce_rate>0%</bounce_rate> <nb_actions_per_visit>4</nb_actions_per_visit> <avg_time_on_site>721</avg_time_on_site> - <bounce_rate>0%</bounce_rate> </result> \ No newline at end of file diff --git a/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentNoVisit_HaveConvertedNonExistingGoal__VisitsSummary.get_week.xml b/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentNoVisit_HaveConvertedNonExistingGoal__VisitsSummary.get_week.xml index f8181af56dbe52a7012c4e42dc1f5a0fa28ba6a4..32b66284bedbe458384d8a08a7b9a61b9d01f775 100644 --- a/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentNoVisit_HaveConvertedNonExistingGoal__VisitsSummary.get_week.xml +++ b/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentNoVisit_HaveConvertedNonExistingGoal__VisitsSummary.get_week.xml @@ -8,7 +8,7 @@ <bounce_count>0</bounce_count> <sum_visit_length>0</sum_visit_length> <max_actions>0</max_actions> + <bounce_rate>0%</bounce_rate> <nb_actions_per_visit>0</nb_actions_per_visit> <avg_time_on_site>0</avg_time_on_site> - <bounce_rate>0%</bounce_rate> </result> \ No newline at end of file diff --git a/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentOrderedSomething__VisitsSummary.get_day.xml b/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentOrderedSomething__VisitsSummary.get_day.xml index 6b178d1ed507170523bda6be580307c1d0527a59..44b18e613c2372108d964340f7ec8a0b8c9c9718 100644 --- a/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentOrderedSomething__VisitsSummary.get_day.xml +++ b/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentOrderedSomething__VisitsSummary.get_day.xml @@ -8,7 +8,7 @@ <bounce_count>0</bounce_count> <sum_visit_length>3961</sum_visit_length> <max_actions>6</max_actions> + <bounce_rate>0%</bounce_rate> <nb_actions_per_visit>6</nb_actions_per_visit> <avg_time_on_site>3961</avg_time_on_site> - <bounce_rate>0%</bounce_rate> </result> \ No newline at end of file diff --git a/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentPageTitleMatch__VisitsSummary.get_day.xml b/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentPageTitleMatch__VisitsSummary.get_day.xml index c48c13a998464f0f94f68742182074dda51bc344..a9d2095dfb93bff2e01487c01c02f3793441d206 100644 --- a/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentPageTitleMatch__VisitsSummary.get_day.xml +++ b/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentPageTitleMatch__VisitsSummary.get_day.xml @@ -8,7 +8,7 @@ <bounce_count>0</bounce_count> <sum_visit_length>721</sum_visit_length> <max_actions>4</max_actions> + <bounce_rate>0%</bounce_rate> <nb_actions_per_visit>4</nb_actions_per_visit> <avg_time_on_site>721</avg_time_on_site> - <bounce_rate>0%</bounce_rate> </result> \ No newline at end of file diff --git a/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentReturningCustomers__VisitsSummary.get_week.xml b/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentReturningCustomers__VisitsSummary.get_week.xml index 4a69adcaa0ab9269dd9011bc90811505bc74d187..fc0095a9b656f1a2d2bacaa6ca0aaf28822dae6b 100644 --- a/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentReturningCustomers__VisitsSummary.get_week.xml +++ b/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentReturningCustomers__VisitsSummary.get_week.xml @@ -8,7 +8,7 @@ <bounce_count>1</bounce_count> <sum_visit_length>2165</sum_visit_length> <max_actions>3</max_actions> + <bounce_rate>33.33%</bounce_rate> <nb_actions_per_visit>2</nb_actions_per_visit> <avg_time_on_site>722</avg_time_on_site> - <bounce_rate>33%</bounce_rate> </result> \ No newline at end of file diff --git a/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentReturningVisitors__VisitsSummary.get_week.xml b/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentReturningVisitors__VisitsSummary.get_week.xml index 6b178d1ed507170523bda6be580307c1d0527a59..44b18e613c2372108d964340f7ec8a0b8c9c9718 100644 --- a/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentReturningVisitors__VisitsSummary.get_week.xml +++ b/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentReturningVisitors__VisitsSummary.get_week.xml @@ -8,7 +8,7 @@ <bounce_count>0</bounce_count> <sum_visit_length>3961</sum_visit_length> <max_actions>6</max_actions> + <bounce_rate>0%</bounce_rate> <nb_actions_per_visit>6</nb_actions_per_visit> <avg_time_on_site>3961</avg_time_on_site> - <bounce_rate>0%</bounce_rate> </result> \ No newline at end of file diff --git a/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentVisitHasConvertedGoal__VisitsSummary.get_week.xml b/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentVisitHasConvertedGoal__VisitsSummary.get_week.xml index c48c13a998464f0f94f68742182074dda51bc344..a9d2095dfb93bff2e01487c01c02f3793441d206 100644 --- a/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentVisitHasConvertedGoal__VisitsSummary.get_week.xml +++ b/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentVisitHasConvertedGoal__VisitsSummary.get_week.xml @@ -8,7 +8,7 @@ <bounce_count>0</bounce_count> <sum_visit_length>721</sum_visit_length> <max_actions>4</max_actions> + <bounce_rate>0%</bounce_rate> <nb_actions_per_visit>4</nb_actions_per_visit> <avg_time_on_site>721</avg_time_on_site> - <bounce_rate>0%</bounce_rate> </result> \ No newline at end of file diff --git a/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentVisitHasNotOrderedAndConvertedGoal__VisitsSummary.get_week.xml b/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentVisitHasNotOrderedAndConvertedGoal__VisitsSummary.get_week.xml index c48c13a998464f0f94f68742182074dda51bc344..a9d2095dfb93bff2e01487c01c02f3793441d206 100644 --- a/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentVisitHasNotOrderedAndConvertedGoal__VisitsSummary.get_week.xml +++ b/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_SegmentVisitHasNotOrderedAndConvertedGoal__VisitsSummary.get_week.xml @@ -8,7 +8,7 @@ <bounce_count>0</bounce_count> <sum_visit_length>721</sum_visit_length> <max_actions>4</max_actions> + <bounce_rate>0%</bounce_rate> <nb_actions_per_visit>4</nb_actions_per_visit> <avg_time_on_site>721</avg_time_on_site> - <bounce_rate>0%</bounce_rate> </result> \ No newline at end of file diff --git a/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems__VisitsSummary.get_day.xml b/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems__VisitsSummary.get_day.xml index 0902118d1aa07befd67ad8478b5fdb7de6ed4f29..bd9117bce7a1f1a73d271657cbc6e4d9d8b9dfaa 100644 --- a/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems__VisitsSummary.get_day.xml +++ b/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems__VisitsSummary.get_day.xml @@ -8,7 +8,7 @@ <bounce_count>0</bounce_count> <sum_visit_length>5403</sum_visit_length> <max_actions>6</max_actions> - <nb_actions_per_visit>4.3</nb_actions_per_visit> - <avg_time_on_site>1801</avg_time_on_site> <bounce_rate>0%</bounce_rate> + <nb_actions_per_visit>4.33</nb_actions_per_visit> + <avg_time_on_site>1801</avg_time_on_site> </result> \ No newline at end of file diff --git a/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_scheduled_report_in_csv__ScheduledReports.generateReport_week.original.csv b/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_scheduled_report_in_csv__ScheduledReports.generateReport_week.original.csv index 09391812789d2433b28a1ee41a2808d92200b77e..ad3cd2810904c13b75d309e0cef0d6de2bf36fef 100644 --- a/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_scheduled_report_in_csv__ScheduledReports.generateReport_week.original.csv +++ b/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_scheduled_report_in_csv__ScheduledReports.generateReport_week.original.csv @@ -4,8 +4,8 @@ Piwik test,5,16,16,$ 13361.11,5,4,$ 13351.11,100%,100%,100%,100%,100%,100%,100% Piwik test,2,1,1,$ 250,1,0,$ 0,100%,100%,100%,100%,100%,0,0 Visits Summary -nb_uniq_visitors,nb_users,nb_visits,nb_actions,max_actions,nb_actions_per_visit,avg_time_on_site,bounce_rate -1,0,5,16,6,3.2,00:22:49,0.2% +nb_uniq_visitors,nb_users,nb_visits,nb_actions,max_actions,bounce_rate,nb_actions_per_visit,avg_time_on_site +1,0,5,16,6,20%,3.2,00:22:49 Visits by Server Time label,nb_visits,nb_actions,revenue,nb_actions_per_visit,avg_time_on_site,bounce_rate @@ -484,8 +484,8 @@ New visits,1 365+ days,0 Returning Visits -nb_uniq_visitors_returning,nb_users_returning,nb_visits_returning,nb_actions_returning,nb_visits_converted_returning,sum_visit_length_returning,max_actions_returning,nb_actions_per_visit_returning,avg_time_on_site_returning,bounce_rate_returning -1,0,4,12,3,6126,6,3,00:25:32,0.25% +nb_uniq_visitors_returning,nb_users_returning,nb_visits_returning,nb_actions_returning,nb_visits_converted_returning,sum_visit_length_returning,max_actions_returning,bounce_rate_returning,nb_actions_per_visit_returning,avg_time_on_site_returning +1,0,4,12,3,6126,6,25%,3,00:25:32 Provider label,nb_visits,nb_actions,conversion_rate,nb_actions_per_visit,avg_time_on_site,bounce_rate diff --git a/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_scheduled_report_in_html_tables_only__ScheduledReports.generateReport_week.original.html b/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_scheduled_report_in_html_tables_only__ScheduledReports.generateReport_week.original.html index f0a2507dcfc31737687720a80eee401e8479d956..dbe23a2221f164d33ccd50656ce418ea2c6d56d7 100644 --- a/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_scheduled_report_in_html_tables_only__ScheduledReports.generateReport_week.original.html +++ b/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_scheduled_report_in_html_tables_only__ScheduledReports.generateReport_week.original.html @@ -551,25 +551,25 @@ <tr style="background-color: rgb(249,250,250)"> <td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;"> - Actions per Visit </td> + Bounce Rate </td> <td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;"> - 3.2 + 20% </td> </tr> <tr style=""> <td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;"> - Avg. Visit Duration (in seconds) </td> + Actions per Visit </td> <td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;"> - 00:22:49 + 3.2 </td> </tr> <tr style="background-color: rgb(249,250,250)"> <td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;"> - Bounce Rate </td> + Avg. Time on Website </td> <td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;"> - 0.2% + 00:22:49 </td> </tr> </tbody> @@ -6482,25 +6482,25 @@ <tr style="background-color: rgb(249,250,250)"> <td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;"> - Avg. Actions per Returning Visit </td> + Bounce Rate for Returning Visits </td> <td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;"> - 3 + 25% </td> </tr> <tr style=""> <td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;"> - Avg. Duration of a Returning Visit (in sec) </td> + Avg. Actions per Returning Visit </td> <td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;"> - 00:25:32 + 3 </td> </tr> <tr style="background-color: rgb(249,250,250)"> <td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;"> - Bounce Rate for Returning Visits </td> + Avg. Duration of a Returning Visit (in sec) </td> <td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;"> - 0.25% + 00:25:32 </td> </tr> </tbody> diff --git a/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_scheduled_report_in_pdf_tables_only__ScheduledReports.generateReport_week.original.pdf b/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_scheduled_report_in_pdf_tables_only__ScheduledReports.generateReport_week.original.pdf index 3db8e7ed770c4ed225c87091b08c556f0397bc20..fbfae51937bd72976b27399f655d34a16b2e0b5c 100644 Binary files a/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_scheduled_report_in_pdf_tables_only__ScheduledReports.generateReport_week.original.pdf and b/tests/PHPUnit/System/expected/test_ecommerceOrderWithItems_scheduled_report_in_pdf_tables_only__ScheduledReports.generateReport_week.original.pdf differ diff --git a/tests/PHPUnit/System/expected/test_noVisit__VisitFrequency.get_day.xml b/tests/PHPUnit/System/expected/test_noVisit__VisitFrequency.get_day.xml index 937fbcb5589dc91d6db5acc252c6af1ca0fc3735..c41509991615003d5680fd59886951e524fc2d53 100644 --- a/tests/PHPUnit/System/expected/test_noVisit__VisitFrequency.get_day.xml +++ b/tests/PHPUnit/System/expected/test_noVisit__VisitFrequency.get_day.xml @@ -8,7 +8,7 @@ <bounce_count_returning>0</bounce_count_returning> <sum_visit_length_returning>0</sum_visit_length_returning> <max_actions_returning>0</max_actions_returning> + <bounce_rate_returning>0%</bounce_rate_returning> <nb_actions_per_visit_returning>0</nb_actions_per_visit_returning> <avg_time_on_site_returning>0</avg_time_on_site_returning> - <bounce_rate_returning>0%</bounce_rate_returning> </result> \ No newline at end of file diff --git a/tests/PHPUnit/Unit/MetricsTest.php b/tests/PHPUnit/Unit/MetricsTest.php index 610e1cf45924ecb698b51356633e168d70534af4..20202232ef2f6b97feed606d317ba286703a4dda 100644 --- a/tests/PHPUnit/Unit/MetricsTest.php +++ b/tests/PHPUnit/Unit/MetricsTest.php @@ -39,7 +39,7 @@ class Core_MetricsTest extends \PHPUnit_Framework_TestCase */ public function testGetMappingFromIdToName() { - $mapping = Metrics::getMappingFromIdToName(); + $mapping = Metrics::getMappingFromNameToId(); $expectedMapping = array( 'nb_uniq_visitors' => 1, 'nb_visits' => 2,