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:
authorStefan Giehl <stefan@matomo.org>2019-03-05 00:10:06 +0300
committerdiosmosis <diosmosis@users.noreply.github.com>2019-03-05 00:10:06 +0300
commit3ba0e38ffe5d45561d5dff541652a95c25a88dec (patch)
tree8f73353c1c82e49506e195b15e3baf43fb07ef98 /plugins/API
parent283ec8d650d25d6f7577c13108a69d98367fc486 (diff)
Improve total report values calculation (#14158)
* Ensure summed up values are numeric to prevent a `A non well formed numeric value encountered` on PHP 7.x * Do not calculate total values for average, rate or nested metrics * Fix calculation for minimal or maximal metrics * updates expected test files * Also skip evolution metrics * skip all non numeric values * update test file * calculate totals for nested metrics recursivly * update test files
Diffstat (limited to 'plugins/API')
-rw-r--r--plugins/API/ProcessedReport.php27
1 files changed, 26 insertions, 1 deletions
diff --git a/plugins/API/ProcessedReport.php b/plugins/API/ProcessedReport.php
index bcd81c08ee..e0b85f3ccc 100644
--- a/plugins/API/ProcessedReport.php
+++ b/plugins/API/ProcessedReport.php
@@ -714,10 +714,35 @@ class ProcessedReport
$simpleTotals = $this->hideShowMetrics($metadataTotals);
+ return $this->calculateTotals($simpleTotals, $totals);
+ }
+
+ private function calculateTotals($simpleTotals, $totals)
+ {
foreach ($simpleTotals as $metric => $value) {
+ if (0 === strpos($metric, 'avg_') || '_rate' === substr($metric, -5) || '_evolution' === substr($metric, -10)) {
+ continue; // skip average, rate and evolution metrics
+ }
+
+ if (!is_numeric($value) && !is_array($value)) {
+ continue;
+ }
+
+ if (is_array($value)) {
+ $currentValue = array_key_exists($metric, $totals) ? $totals[$metric] : [];
+ $newValue = $this->calculateTotals($value, $currentValue);
+ if (!empty($newValue)) {
+ $totals[$metric] = $newValue;
+ }
+ }
+
if (!array_key_exists($metric, $totals)) {
$totals[$metric] = $value;
- } else {
+ } else if(0 === strpos($metric, 'min_')) {
+ $totals[$metric] = min($totals[$metric], $value);
+ } else if(0 === strpos($metric, 'max_')) {
+ $totals[$metric] = max($totals[$metric], $value);
+ } else if($value) {
$totals[$metric] += $value;
}
}