MediaWiki REL1_39
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( __METHOD__ .
30 ": $var must be specified in the sequences array" );
31 }
32 }
33 $seqArrays = $spec['sequences'] ?? [];
34 if ( !count( $seqArrays ) ) {
35 $seqArrays = [ [] ];
36 }
37 $sequences = [];
38 foreach ( $seqArrays as $i => $seqArray ) {
39 if ( !is_array( $seqArray ) ) {
40 throw new WRStatsError( __METHOD__ .
41 ': sequences is supposed to be an array of arrays' );
42 }
43 $seqSpec = new SequenceSpec( $seqArray );
44 while ( isset( $sequences[$seqSpec->name] ) ) {
45 $seqSpec->name .= "s$i";
46 }
47 $sequences[$seqSpec->name] = $seqSpec;
48 }
49 uasort( $sequences, static function ( SequenceSpec $a, SequenceSpec $b ) {
50 return $a->hardExpiry <=> $b->hardExpiry;
51 } );
52 $this->sequences = $sequences;
53 }
54}
Class representation of normalized metric specifications.
const DEFAULT_RESOLUTION
The default (value axis) resolution.
SequenceSpec[] $sequences
Sequences in ascending order of expiry.
Class representation of normalized sequence specifications.
Exception class for errors thrown by the WRStats library.