Lizmap Web Client 3.11.0

TraceAggregator
in package

FinalYes

Online (one pass) aggregation of the values of a trace per group.

Only the state required by the configured function is kept, so the memory used is proportional to the number of groups, except for the median which needs to keep every numeric value. When the features are sorted by group, reset() allows to keep only the state of the current group.

Except for count, first and last, non numeric values are ignored.

Table of Contents

Properties

$colors  : array<int, mixed>
First non empty color per group.
$counts  : array<int, int>
Number of numeric values per group (avg, stddev).
$function  : string
$m2  : array<int, float>
Sum of squares of differences from the mean per group (stddev).
$means  : array<int, float>
Running mean per group (stddev, Welford algorithm).
$samples  : array<int, array<int, float|int>>
Numeric values per group (median only).
$values  : array<int, mixed>
Main state per group: sum, count, min, max, first or last value.

Methods

__construct()  : mixed
Create an aggregator for the given function.
add()  : void
Add a feature value to a group.
color()  : mixed
Get the first non empty color of a group.
colors()  : null|array<int, mixed>
Get the color of each group.
getFunction()  : string
Get the aggregate function.
reset()  : void
Forget the state of all the groups.
result()  : mixed
Get the aggregated value of a group.
results()  : array<int, mixed>
Get the aggregated value of each group.
median()  : null|float|int
Compute the median of the values.
toNumber()  : null|float|int
Convert a value to a number, if possible.

Properties

$colors

First non empty color per group.

private array<int, mixed> $colors = array()

$counts

Number of numeric values per group (avg, stddev).

private array<int, int> $counts = array()

$m2

Sum of squares of differences from the mean per group (stddev).

private array<int, float> $m2 = array()

$means

Running mean per group (stddev, Welford algorithm).

private array<int, float> $means = array()

$samples

Numeric values per group (median only).

private array<int, array<int, float|int>> $samples = array()

$values

Main state per group: sum, count, min, max, first or last value.

private array<int, mixed> $values = array()

Methods

__construct()

Create an aggregator for the given function.

public __construct(string $function) : mixed
Parameters
$function : string

one of the AggregateFunction constants

Tags
throws
InvalidArgumentException

if the function is not supported

add()

Add a feature value to a group.

public add(int $group, mixed $value[, mixed $color = null ]) : void

Only the state needed by the aggregate function is updated.

Parameters
$group : int

the group position given by the GroupIndex

$value : mixed

the feature value (Y)

$color : mixed = null

the feature color, if any

color()

Get the first non empty color of a group.

public color(int $group) : mixed
Parameters
$group : int

the group position

Return values
mixed —

the color, null if the group has no color

colors()

Get the color of each group.

public colors(int $groupCount) : null|array<int, mixed>
Parameters
$groupCount : int

the total number of groups

Return values
null|array<int, mixed> —

the colors aligned on the group positions (null for a group without color), or null if no group has a color

getFunction()

Get the aggregate function.

public getFunction() : string
Return values
string —

one of the AggregateFunction constants

reset()

Forget the state of all the groups.

public reset() : void

Used when the features are sorted by group: once the value of a group is read, its state is no longer needed and the next group starts again at position 0, so the memory does not depend on the number of groups.

result()

Get the aggregated value of a group.

public result(int $group) : mixed
Parameters
$group : int

the group position

Return values
mixed —

the aggregated value: 0 for an empty count or sum, null for the other functions if the group has no value

results()

Get the aggregated value of each group.

public results(int $groupCount) : array<int, mixed>
Parameters
$groupCount : int

the total number of groups

Return values
array<int, mixed> —

the values, aligned on the group positions

median()

Compute the median of the values.

private static median(array<int, float|int> $values) : null|float|int
Parameters
$values : array<int, float|int>

the numeric values

Return values
null|float|int —

the median, null if there is no value

toNumber()

Convert a value to a number, if possible.

private static toNumber(mixed $value) : null|float|int
Parameters
$value : mixed

the value

Return values
null|float|int —

the number, null if the value is not numeric

On this page

Search results