-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Description
Matomo stores values that are displayed as percent values as rates.
So a value like 12.345% would be stored as 0.12345 in the database.
To receive the percent value out of the rate all percent metric classes are currently using the format method. e.g.
matomo/plugins/Actions/Columns/Metrics/ExitRate.php
Lines 43 to 46 in eeb6e3b
public function format($value, Formatter $formatter) | |
{ | |
return $formatter->getPrettyPercentFromQuotient($value); | |
} |
matomo/core/Metrics/Formatter.php
Lines 159 to 162 in 3b00013
public function getPrettyPercentFromQuotient($value) | |
{ | |
return NumberFormatter::getInstance()->formatPercent($value * 100, 4, 0); | |
} |
This works perfectly when formatting results for the API. But in our UI there are several places where we actually can't directly work with formatted numbers, as we need to apply mathematical operations. This currently produces problems as when fetching unformatted values from the API the rate value would be returned. But as the UI doesn't know that the value would need to be calculated before formatting, we can't use it unformatted. In the past we have implemented various workarounds.
The biggest example would be the API parameter format_metrics=bc
, which actually does not format anything except of percent values and is used as default for formatting. That way the percent values are correctly calculated but also formatted. If those numbers then need to be used for calculation this can result in a problem for certain languages. While the English presentation like 14.55%
can be easily converted to float, this doesn't apply for e.g. the German one 14,55%
or the Turkish %14,55
. Both might end up in invalid/incorrect numbers.
There might be various ways to fix this. We might need to discuss the possible solutions to find a proper way, that doesn't end up in another workaround that we might need to refactor at some point.
My ideas for a possible solution would be:
-
Change all rate/percent metric classes so they do the calculation (multiply with 100) within the compute method (or similar), so the formatting method only applies the formatting.
This might actually be some sort of breaking change, as the API would no longer return rate values when data is fetched unformatted. But we would be able to get rid of the bc formatting, and UI would be able to calculate with all values.
-
Let the UI know which values are returned as rates, so the UI can calculate the percent value when unformatted values are fetched
This would be a quite big change, as currently the UI does not know which types the metrics are of. But if it's on purpose to return rate values and we can't change that, this might be an alternative solution.
refs #19940