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>2020-12-10 04:16:13 +0300
committerGitHub <noreply@github.com>2020-12-10 04:16:13 +0300
commit848d1a258b085cad5b7725e630b1303f4c8e3a21 (patch)
treee805e324677a9d0686124bcf4100ab7ece6f3534
parent5706eabad6d1a6495ef12937f02cde0c8cda80cc (diff)
Improvements on prepending a plus sign to evolutions (#16923)
* fix prepending a plus sign to evolutions * updates expected test files
-rw-r--r--core/DataTable/Filter/CalculateEvolutionFilter.php18
-rw-r--r--plugins/API/Filter/DataComparisonFilter.php7
-rw-r--r--plugins/API/RowEvolution.php4
-rw-r--r--tests/PHPUnit/System/expected/test_RowEvolution_LabelReservedCharactersHierarchical__API.getRowEvolution_day.xml2
-rw-r--r--tests/PHPUnit/System/expected/test_RowEvolution_goals_visitsUntilConversion_WithoutLabels__API.getRowEvolution_day.xml2
-rw-r--r--tests/PHPUnit/System/expected/test_RowEvolution_goals_visitsUntilConversion__API.getRowEvolution_day.xml2
-rw-r--r--tests/PHPUnit/System/expected/test_RowEvolution_multiWithFilterLimit__API.getRowEvolution_day.xml2
-rw-r--r--tests/PHPUnit/System/expected/test_RowEvolution_pageTitlesMulti__API.getRowEvolution_week.xml2
-rw-r--r--tests/PHPUnit/System/expected/test_RowEvolution_pageTitles__API.getRowEvolution_week.xml8
9 files changed, 25 insertions, 22 deletions
diff --git a/core/DataTable/Filter/CalculateEvolutionFilter.php b/core/DataTable/Filter/CalculateEvolutionFilter.php
index 0ebe19b53c..5906e1bb8f 100644
--- a/core/DataTable/Filter/CalculateEvolutionFilter.php
+++ b/core/DataTable/Filter/CalculateEvolutionFilter.php
@@ -12,6 +12,7 @@ use Piwik\Common;
use Piwik\DataTable;
use Piwik\DataTable\Row;
use Piwik\NumberFormatter;
+use Piwik\Piwik;
use Piwik\Site;
/**
@@ -151,17 +152,24 @@ class CalculateEvolutionFilter extends ColumnCallbackAddColumnPercentage
* from this value to $currentValue.
* @param float|int $quotientPrecision The quotient precision to round to.
* @param bool $appendPercentSign Whether to append a '%' sign to the end of the number or not.
+ * @param bool $prependPlusSignWhenPositive Whether to prepend a '+' sign before the number if it's not negative.
*
* @return string The evolution percent, eg `'15%'`.
*/
- public static function calculate($currentValue, $pastValue, $quotientPrecision = 0, $appendPercentSign = true)
+ public static function calculate($currentValue, $pastValue, $quotientPrecision = 0, $appendPercentSign = true, $prependPlusSignWhenPositive = false)
{
$number = self::getPercentageValue($currentValue - $pastValue, $pastValue, $quotientPrecision);
if ($appendPercentSign) {
- return NumberFormatter::getInstance()->formatPercent($number, $quotientPrecision);
+ $formatted = NumberFormatter::getInstance()->formatPercent($number, $quotientPrecision);
+ } else {
+ $formatted = NumberFormatter::getInstance()->format($number, $quotientPrecision);
+ }
+
+ if ($prependPlusSignWhenPositive && $number >= 0) {
+ $formatted = Piwik::translate('Intl_NumberSymbolPlus') . $formatted;
}
- return NumberFormatter::getInstance()->format($number, $quotientPrecision);
+ return $formatted;
}
public static function appendPercentSign($number)
@@ -171,8 +179,8 @@ class CalculateEvolutionFilter extends ColumnCallbackAddColumnPercentage
public static function prependPlusSignToNumber($number)
{
- if ($number > 0) {
- $number = '+' . $number;
+ if ((float) $number > 0) {
+ return '+' . $number;
}
return $number;
diff --git a/plugins/API/Filter/DataComparisonFilter.php b/plugins/API/Filter/DataComparisonFilter.php
index 03bc5e6b1b..17bec4430d 100644
--- a/plugins/API/Filter/DataComparisonFilter.php
+++ b/plugins/API/Filter/DataComparisonFilter.php
@@ -521,12 +521,7 @@ class DataComparisonFilter
$valueToCompare = $fromRow ? $fromRow->getColumn($columnName) : 0;
$valueToCompare = $valueToCompare ?: 0;
- $change = DataTable\Filter\CalculateEvolutionFilter::calculate($value, $valueToCompare, $precision = 1, $appendPercent = false);
-
- if ($change >= 0) {
- $change = '+' . $change;
- }
- $change .= '%';
+ $change = DataTable\Filter\CalculateEvolutionFilter::calculate($value, $valueToCompare, $precision = 1, true, true);
return $change;
}
diff --git a/plugins/API/RowEvolution.php b/plugins/API/RowEvolution.php
index da44b19f6b..fe046e9ffb 100644
--- a/plugins/API/RowEvolution.php
+++ b/plugins/API/RowEvolution.php
@@ -411,8 +411,8 @@ class RowEvolution
continue;
}
- $change = CalculateEvolutionFilter::calculate($last, $first, $quotientPrecision = 0);
- $change = CalculateEvolutionFilter::prependPlusSignToNumber($change);
+ $change = CalculateEvolutionFilter::calculate($last, $first, $quotientPrecision = 0, true, true);
+
$metricsResult[$metric]['change'] = $change;
}
diff --git a/tests/PHPUnit/System/expected/test_RowEvolution_LabelReservedCharactersHierarchical__API.getRowEvolution_day.xml b/tests/PHPUnit/System/expected/test_RowEvolution_LabelReservedCharactersHierarchical__API.getRowEvolution_day.xml
index 579575d2a0..85c18cf8a9 100644
--- a/tests/PHPUnit/System/expected/test_RowEvolution_LabelReservedCharactersHierarchical__API.getRowEvolution_day.xml
+++ b/tests/PHPUnit/System/expected/test_RowEvolution_LabelReservedCharactersHierarchical__API.getRowEvolution_day.xml
@@ -258,7 +258,7 @@
<logo>plugins/Morpheus/icons/dist/searchEngines/google.com.png</logo>
<min>1</min>
<max>1</max>
- <change>0%</change>
+ <change>+0%</change>
</nb_visits_3>
</metrics>
<dimension>Search Engine</dimension>
diff --git a/tests/PHPUnit/System/expected/test_RowEvolution_goals_visitsUntilConversion_WithoutLabels__API.getRowEvolution_day.xml b/tests/PHPUnit/System/expected/test_RowEvolution_goals_visitsUntilConversion_WithoutLabels__API.getRowEvolution_day.xml
index bed5b4c44e..1033a88c65 100644
--- a/tests/PHPUnit/System/expected/test_RowEvolution_goals_visitsUntilConversion_WithoutLabels__API.getRowEvolution_day.xml
+++ b/tests/PHPUnit/System/expected/test_RowEvolution_goals_visitsUntilConversion_WithoutLabels__API.getRowEvolution_day.xml
@@ -183,7 +183,7 @@
<name>1 visit (Conversions)</name>
<min>2</min>
<max>2</max>
- <change>0%</change>
+ <change>+0%</change>
</nb_conversions_0>
<nb_conversions_1>
<name>2 visits (Conversions)</name>
diff --git a/tests/PHPUnit/System/expected/test_RowEvolution_goals_visitsUntilConversion__API.getRowEvolution_day.xml b/tests/PHPUnit/System/expected/test_RowEvolution_goals_visitsUntilConversion__API.getRowEvolution_day.xml
index 6b29ea0e98..14841663a2 100644
--- a/tests/PHPUnit/System/expected/test_RowEvolution_goals_visitsUntilConversion__API.getRowEvolution_day.xml
+++ b/tests/PHPUnit/System/expected/test_RowEvolution_goals_visitsUntilConversion__API.getRowEvolution_day.xml
@@ -183,7 +183,7 @@
<name>1 visit (Conversions)</name>
<min>2</min>
<max>2</max>
- <change>0%</change>
+ <change>+0%</change>
</nb_conversions_0>
<nb_conversions_1>
<name> 2 visits (Conversions)</name>
diff --git a/tests/PHPUnit/System/expected/test_RowEvolution_multiWithFilterLimit__API.getRowEvolution_day.xml b/tests/PHPUnit/System/expected/test_RowEvolution_multiWithFilterLimit__API.getRowEvolution_day.xml
index 29f0426935..0c4bf9629b 100644
--- a/tests/PHPUnit/System/expected/test_RowEvolution_multiWithFilterLimit__API.getRowEvolution_day.xml
+++ b/tests/PHPUnit/System/expected/test_RowEvolution_multiWithFilterLimit__API.getRowEvolution_day.xml
@@ -51,7 +51,7 @@
<name>www.referrer0.com (Visits)</name>
<min>0</min>
<max>1</max>
- <change>0%</change>
+ <change>+0%</change>
</nb_visits_0>
<nb_visits_1>
<name>www.referrer4.com (Visits)</name>
diff --git a/tests/PHPUnit/System/expected/test_RowEvolution_pageTitlesMulti__API.getRowEvolution_week.xml b/tests/PHPUnit/System/expected/test_RowEvolution_pageTitlesMulti__API.getRowEvolution_week.xml
index 1da0cd6ff6..cdab643c32 100644
--- a/tests/PHPUnit/System/expected/test_RowEvolution_pageTitlesMulti__API.getRowEvolution_week.xml
+++ b/tests/PHPUnit/System/expected/test_RowEvolution_pageTitlesMulti__API.getRowEvolution_week.xml
@@ -39,7 +39,7 @@
<name>incredible title 0 (Pageviews)</name>
<min>2</min>
<max>3</max>
- <change>0%</change>
+ <change>+0%</change>
</nb_hits_0>
<nb_hits_1>
<name>incredible title 2 (Pageviews)</name>
diff --git a/tests/PHPUnit/System/expected/test_RowEvolution_pageTitles__API.getRowEvolution_week.xml b/tests/PHPUnit/System/expected/test_RowEvolution_pageTitles__API.getRowEvolution_week.xml
index 6437157efb..f6fea5de4d 100644
--- a/tests/PHPUnit/System/expected/test_RowEvolution_pageTitles__API.getRowEvolution_week.xml
+++ b/tests/PHPUnit/System/expected/test_RowEvolution_pageTitles__API.getRowEvolution_week.xml
@@ -54,13 +54,13 @@
<name>Pageviews</name>
<min>2</min>
<max>3</max>
- <change>0%</change>
+ <change>+0%</change>
</nb_hits>
<nb_visits>
<name>Unique Pageviews</name>
<min>2</min>
<max>3</max>
- <change>0%</change>
+ <change>+0%</change>
</nb_visits>
<avg_time_on_page>
<name>Avg. time on page</name>
@@ -69,13 +69,13 @@
<name>Bounce Rate</name>
<min>100</min>
<max>100</max>
- <change>0%</change>
+ <change>+0%</change>
</bounce_rate>
<exit_rate>
<name>Exit rate</name>
<min>100</min>
<max>100</max>
- <change>0%</change>
+ <change>+0%</change>
</exit_rate>
<avg_time_generation>
<name>Avg. generation time</name>