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:
authormattab <matthieu.aubry@gmail.com>2013-03-06 04:48:37 +0400
committermattab <matthieu.aubry@gmail.com>2013-03-06 04:48:37 +0400
commitccadd8ee1fe62a880d44f499fa9fb7930bb4eede (patch)
tree032fcd80b267a89c4e77c6daba18a24b0b09a4be /core/DataTable/Filter/CalculateEvolutionFilter.php
parent9c26191d0f5986fcf940dc21529d475b2862192b (diff)
small refactor
Diffstat (limited to 'core/DataTable/Filter/CalculateEvolutionFilter.php')
-rwxr-xr-xcore/DataTable/Filter/CalculateEvolutionFilter.php82
1 files changed, 46 insertions, 36 deletions
diff --git a/core/DataTable/Filter/CalculateEvolutionFilter.php b/core/DataTable/Filter/CalculateEvolutionFilter.php
index 3393952829..675a3cf8ef 100755
--- a/core/DataTable/Filter/CalculateEvolutionFilter.php
+++ b/core/DataTable/Filter/CalculateEvolutionFilter.php
@@ -112,7 +112,9 @@ class Piwik_DataTable_Filter_CalculateEvolutionFilter extends Piwik_DataTable_Fi
*/
protected function formatValue($value, $divisor)
{
- return self::makePercent($value, $divisor, $this->quotientPrecision);
+ $value = self::getPercentageValue($value, $divisor, $this->quotientPrecision);
+ $value = self::appendPercentSign($value);
+ return $value;
}
/**
@@ -131,41 +133,49 @@ class Piwik_DataTable_Filter_CalculateEvolutionFilter extends Piwik_DataTable_Fi
* @param numeric $currentValue The current metric value.
* @param numeric $pastValue The value of the metric in the past. We measure the % change
* from this value to $currentValue.
- * @param numeric $quotientPrecision The quotient precision to round to.
- * @param bool $addPlusSign Whether to add plus sign or not to positive values.
- * @return string The evolution percent. TODO: addPlusSign should be used elsewhere?
- */
- public static function calculate($currentValue, $pastValue, $quotientPrecision = 0, $addPlusSign = false)
+ * @param numeric $quotientPrecision The quotient precision to round to.
+ * @return string The evolution percent 15%
+ */
+ public static function calculate($currentValue, $pastValue, $quotientPrecision = 0)
{
- return self::makePercent($currentValue - $pastValue, $pastValue, $quotientPrecision, $addPlusSign);
- }
-
- /**
- * Returns an evolution percent based on a value & divisor.
- */
- private static function makePercent($value, $divisor, $quotientPrecision, $addPlusSign = false)
+ $number = self::getPercentageValue($currentValue - $pastValue, $pastValue, $quotientPrecision);
+ $number = self::appendPercentSign($number);
+ return $number;
+ }
+
+ public static function appendPercentSign($number)
+ {
+ $number = $number . '%';
+ return $number;
+ }
+
+ public static function prependPlusSignToNumber($number)
+ {
+ if ($number > 0) {
+ $number = '+'.$number;
+ }
+ return $number;
+ }
+
+ /**
+ * Returns an evolution percent based on a value & divisor.
+ */
+ private static function getPercentageValue($value, $divisor, $quotientPrecision)
{
- if($value == 0)
- {
- $evolution = 0;
- }
- elseif($divisor == 0)
- {
- $evolution = 100;
- }
- else
- {
- $evolution = ($value / $divisor) * 100;
- }
-
- $evolution = round($evolution, $quotientPrecision);
-
- $result = $evolution.'%';
- if ($addPlusSign
- && $evolution > 0)
- {
- $result = '+'.$result;
- }
- return $result;
- }
+ if($value == 0)
+ {
+ $evolution = 0;
+ }
+ elseif($divisor == 0)
+ {
+ $evolution = 100;
+ }
+ else
+ {
+ $evolution = ($value / $divisor) * 100;
+ }
+
+ $evolution = round($evolution, $quotientPrecision);
+ return $evolution;
+ }
}