Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordiosmosis <benaka@piwik.pro>2014-11-06 22:00:10 +0300
committerdiosmosis <benaka@piwik.pro>2014-11-07 04:49:22 +0300
commitc1264ec0476fc2e88c29d052e2018990458f814d (patch)
tree148a599c6c1400df960a72fc1254f14e5f546582 /core/DataTable
parentd4e0c79caef3ca17dbad7890a52af9a000f07ee9 (diff)
Moved processed metrics computation to DataTableGenericFilter, removed new filters & implemented as methods in Report to avoid confusion regarding re-use, allow adding processed metrics as DataTable metadata and use this to rewrite AddProcessedMetrics filter, correct name of Metrics::getMappingFromIdToName function, added placeholder AggregatedMetric class for future, revise Metric/ProcessedMetric hierarchy (add methods for translation/etc.), allow .get API methods to use metadata to automatically figure out which columns to select, get EcommerceOrderWithItemsTest to pass.
Diffstat (limited to 'core/DataTable')
-rw-r--r--core/DataTable/Filter/AddColumnsProcessedMetrics.php29
-rw-r--r--core/DataTable/Filter/ComputeProcessedMetrics.php66
-rw-r--r--core/DataTable/Filter/FormatProcessedMetrics.php65
-rw-r--r--core/DataTable/Filter/PivotByDimension.php2
-rw-r--r--core/DataTable/Filter/Sort.php2
5 files changed, 13 insertions, 151 deletions
diff --git a/core/DataTable/Filter/AddColumnsProcessedMetrics.php b/core/DataTable/Filter/AddColumnsProcessedMetrics.php
index f3d8191b1f..06cdc154ea 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 d463212368..0000000000
--- 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 d612ecaedd..0000000000
--- 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 ce3ac98ec5..61e68423e8 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 9df2250288..6ffe33bced 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];