81 lines
1.9 KiB
PHP
81 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace Toalett\Redis\Timeseries\Model;
|
|
|
|
use Toalett\Redis\Timeseries\Exception\InvalidArgumentException;
|
|
|
|
final class Aggregation
|
|
{
|
|
public string $type;
|
|
public int $timeBucket;
|
|
|
|
private function __construct(string $type, int $timeBucket)
|
|
{
|
|
if ($timeBucket < 0) {
|
|
throw new InvalidArgumentException("Argument 'bucket' must be >= 0");
|
|
}
|
|
$this->type = $type;
|
|
$this->timeBucket = $timeBucket;
|
|
}
|
|
|
|
public static function average(int $timeBucket): self
|
|
{
|
|
return new Aggregation('avg', $timeBucket);
|
|
}
|
|
|
|
public static function sum(int $timeBucket): self
|
|
{
|
|
return new Aggregation('sum', $timeBucket);
|
|
}
|
|
|
|
public static function min(int $timeBucket): self
|
|
{
|
|
return new Aggregation('min', $timeBucket);
|
|
}
|
|
|
|
public static function max(int $timeBucket): self
|
|
{
|
|
return new Aggregation('max', $timeBucket);
|
|
}
|
|
|
|
public static function range(int $timeBucket): self
|
|
{
|
|
return new Aggregation('range', $timeBucket);
|
|
}
|
|
|
|
public static function count(int $timeBucket): self
|
|
{
|
|
return new Aggregation('count', $timeBucket);
|
|
}
|
|
|
|
public static function first(int $timeBucket): self
|
|
{
|
|
return new Aggregation('first', $timeBucket);
|
|
}
|
|
|
|
public static function last(int $timeBucket): self
|
|
{
|
|
return new Aggregation('last', $timeBucket);
|
|
}
|
|
|
|
public static function populationStdDev(int $timeBucket): self
|
|
{
|
|
return new Aggregation('std.p', $timeBucket);
|
|
}
|
|
|
|
public static function sampleStdDev(int $timeBucket): self
|
|
{
|
|
return new Aggregation('std.s', $timeBucket);
|
|
}
|
|
|
|
public static function populationVariance(int $timeBucket): self
|
|
{
|
|
return new Aggregation('var.p', $timeBucket);
|
|
}
|
|
|
|
public static function sampleVariance(int $timeBucket): self
|
|
{
|
|
return new Aggregation('var.s', $timeBucket);
|
|
}
|
|
}
|