Skip to content
Extraits de code Groupes Projets
Valider 757d47c0 rédigé par diosmosis's avatar diosmosis
Parcourir les fichiers

Allow ProcessedMetrics to declare some metrics as temporary so they will be...

Allow ProcessedMetrics to declare some metrics as temporary so they will be removed if not explicitly requested.
parent 8fafa666
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -248,11 +248,33 @@ class DataTablePostProcessor ...@@ -248,11 +248,33 @@ class DataTablePostProcessor
|| !empty($showColumns) || !empty($showColumns)
) { ) {
$dataTable->filter('ColumnDelete', array($hideColumns, $showColumns)); $dataTable->filter('ColumnDelete', array($hideColumns, $showColumns));
} else {
$this->removeTemporaryMetrics($dataTable);
} }
return $dataTable; return $dataTable;
} }
/**
* @param DataTableInterface $dataTable
*/
public function removeTemporaryMetrics(DataTableInterface $dataTable)
{
$allColumns = !empty($this->report) ? $this->report->getAllMetrics() : array();
$report = $this->report;
$dataTable->filter(function (DataTable $table) use ($report, $allColumns) {
$processedMetrics = Report::getProcessedMetricsForTable($table, $this->report);
$allTemporaryMetrics = array();
foreach ($processedMetrics as $metric) {
$allTemporaryMetrics = array_merge($allTemporaryMetrics, $metric->getTemporaryMetrics());
}
$table->filter('ColumnDelete', array($allTemporaryMetrics));
});
}
/** /**
* @param DataTableInterface $dataTable * @param DataTableInterface $dataTable
* @return DataTableInterface * @return DataTableInterface
......
...@@ -41,6 +41,19 @@ abstract class ProcessedMetric extends Metric ...@@ -41,6 +41,19 @@ abstract class ProcessedMetric extends Metric
*/ */
abstract public function getDependentMetrics(); abstract public function getDependentMetrics();
/**
* Returns the array of metrics that are necessary for computing this metric, but should not
* be displayed to the user unless explicitly requested. These metrics are intermediate
* metrics that are not really valuable to the user. On a request, if showColumns or hideColumns
* is not used, they will be removed automatically.
*
* @return string[]
*/
public function getTemporaryMetrics()
{
return array();
}
/** /**
* Executed before computing all processed metrics for a report. Implementers can return `false` * Executed before computing all processed metrics for a report. Implementers can return `false`
* to skip computing this metric. * to skip computing this metric.
......
...@@ -40,6 +40,11 @@ class AveragePageGenerationTime extends ProcessedMetric ...@@ -40,6 +40,11 @@ class AveragePageGenerationTime extends ProcessedMetric
return array('sum_time_generation', 'nb_hits_with_time_generation'); return array('sum_time_generation', 'nb_hits_with_time_generation');
} }
public function getTemporaryMetrics()
{
return array('nb_hits_with_time_generation');
}
public function compute(Row $row) public function compute(Row $row)
{ {
$sumGenerationTime = $this->getMetric($row, 'sum_time_generation'); $sumGenerationTime = $this->getMetric($row, 'sum_time_generation');
......
...@@ -62,13 +62,7 @@ class TwoVisitorsTwoWebsitesDifferentDaysTest extends SystemTestCase ...@@ -62,13 +62,7 @@ class TwoVisitorsTwoWebsitesDifferentDaysTest extends SystemTestCase
$singlePeriodApi = array('VisitsSummary.get', 'Goals.get'); $singlePeriodApi = array('VisitsSummary.get', 'Goals.get');
$periods = array('day', 'week', 'month', 'year'); $periods = array('day', 'week', 'month', 'year');
return array(
array('Goals.get', array('idSite' => 'all',
'date' => $dateTime,
'periods' => array('day'),
'setDateLastN' => false,
'testSuffix' => '_NotLastNPeriods'))
);
$result = array( $result = array(
// Request data for the last 6 periods and idSite=all // Request data for the last 6 periods and idSite=all
array($apiToCall, array('idSite' => 'all', array($apiToCall, array('idSite' => 'all',
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter