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
24 public function __construct( array $spec ) {
25 $this->type = $spec['type'] ?? 'counter';
26 $this->resolution = $spec['resolution'] ?? self::DEFAULT_RESOLUTION;
27 foreach ( [ 'timeStep', 'expiry' ] as $var ) {
28 if ( isset( $spec[$var] ) ) {
29 throw new WRStatsError( "$var must be in the sequences array" );
30 }
31 }
32 $seqArrays = $spec['sequences'] ?? [];
33 if ( !$seqArrays ) {
34 $seqArrays = [ [] ];
35 }
36 $sequences = [];
37 foreach ( $seqArrays as $i => $seqArray ) {
38 if ( !is_array( $seqArray ) ) {
39 throw new WRStatsError( 'sequences must be an array of arrays' );
40 }
41 $seqSpec = new SequenceSpec( $seqArray );
42 while ( isset( $sequences[$seqSpec->name] ) ) {
43 $seqSpec->name .= "s$i";
44 }
45 $sequences[$seqSpec->name] = $seqSpec;
46 }
47 uasort( $sequences, static function ( SequenceSpec $a, SequenceSpec $b ) {
48 return $a->hardExpiry <=> $b->hardExpiry;
49 } );
50 $this->sequences = $sequences;
51 }
52}
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.