MediaWiki master
MetricSpec.php
Go to the documentation of this file.
1<?php
2
3namespace Wikimedia\WRStats;
4
12 public const DEFAULT_RESOLUTION = 1;
13
15 public $type;
19 public $sequences;
20
21 public function __construct( array $spec ) {
22 $this->type = $spec['type'] ?? 'counter';
23 $this->resolution = $spec['resolution'] ?? self::DEFAULT_RESOLUTION;
24 foreach ( [ 'timeStep', 'expiry' ] as $var ) {
25 if ( isset( $spec[$var] ) ) {
26 throw new WRStatsError( "$var must be in the sequences array" );
27 }
28 }
29 $seqArrays = $spec['sequences'] ?? [];
30 if ( !$seqArrays ) {
31 $seqArrays = [ [] ];
32 }
33 $sequences = [];
34 foreach ( $seqArrays as $i => $seqArray ) {
35 if ( !is_array( $seqArray ) ) {
36 throw new WRStatsError( 'sequences must be an array of arrays' );
37 }
38 $seqSpec = new SequenceSpec( $seqArray );
39 while ( isset( $sequences[$seqSpec->name] ) ) {
40 $seqSpec->name .= "s$i";
41 }
42 $sequences[$seqSpec->name] = $seqSpec;
43 }
44 uasort( $sequences, static function ( SequenceSpec $a, SequenceSpec $b ) {
45 return $a->hardExpiry <=> $b->hardExpiry;
46 } );
47 $this->sequences = $sequences;
48 }
49}
Class representation of normalized metric specifications.
array< string, SequenceSpec > $sequences
Sequences in ascending order of expiry.
const DEFAULT_RESOLUTION
The default (value axis) resolution.
Class representation of normalized sequence specifications.
Exception class for errors thrown by the WRStats library.