Piwik\DataTable\Filter\
A DataTable filter that calculates the evolution of a metric and adds it to each row as a percentage.
This filter cannot be used as an argument to DataTable::filter() since it requires corresponding data from another DataTable. Instead, you must manually perform a binary filter (see the MultiSites API for an example).
The evolution metric is calculated as:
((currentValue - pastValue) / pastValue) * 100
The class defines the following methods:
__construct()
— Constructor.filter()
ash; See ColumnCallbackAddColumnQuotient. Inherited from ColumnCallbackAddColumnQuotient
enableRecursive()
ash; Enables/Disables recursive filtering. Inherited from BaseFilter
filterSubTable()
ash; Filters a row's subtable, if one exists and is loaded in memory. Inherited from BaseFilter
calculate()
— Calculates the evolution percentage for two arbitrary values.appendPercentSign()
prependPlusSignToNumber()
__construct()
Constructor.
It accepts the following parameter(s):
$table
(DataTable
) —
$pastDataTable
(DataTable
) —
The DataTable containing data for the period in the past.
$columnToAdd
(string
) —
The column to add evolution data to, eg, 'visits_evolution'
.$columnToRead
(string
) —
The column to use to calculate evolution data, eg, 'nb_visits'
.$quotientPrecision
(int
) —
The precision to use when rounding the quotient.filter()
See ColumnCallbackAddColumnQuotient.
It accepts the following parameter(s):
$table
(DataTable
) —It does not return anything or a mixed result.
enableRecursive()
Enables/Disables recursive filtering. Whether this property is actually used is up to the derived BaseFilter class.
It accepts the following parameter(s):
$enable
(bool
) —It does not return anything or a mixed result.
filterSubTable()
Filters a row's subtable, if one exists and is loaded in memory.
$row
(Row
) —
The row whose subtable should be filter.calculate()
Calculates the evolution percentage for two arbitrary values.
It accepts the following parameter(s):
$currentValue
(float
|int
) —
The current metric value.$pastValue
(float
|int
) —
The value of the metric in the past. We measure the % change from this value to $currentValue.$quotientPrecision
(float
|int
) —
The quotient precision to round to.$appendPercentSign
(bool
) —
Whether to append a '%' sign to the end of the number or not.$prependPlusSignWhenPositive
(bool
) —
Whether to prepend a '+' sign before the number if it's not negative.Returns: string
—
The evolution percent, eg '15%'
.
appendPercentSign()
It accepts the following parameter(s):
$number
It does not return anything or a mixed result.
prependPlusSignToNumber()
It accepts the following parameter(s):
$number
It does not return anything or a mixed result.