| 1 |
<?php |
| 2 |
|
| 3 |
namespace Wikimedia\WRStats; |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
class RatePromise { |
| 13 |
|
| 14 |
private $reader; |
| 15 |
|
| 16 |
private $name; |
| 17 |
|
| 18 |
private $entity; |
| 19 |
|
| 20 |
private $metricSpec; |
| 21 |
|
| 22 |
private $seqSpec; |
| 23 |
|
| 24 |
private $range; |
| 25 |
|
| 26 |
private $total; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
public function __construct( |
| 38 |
WRStatsReader $reader, |
| 39 |
string $name, |
| 40 |
EntityKey $entity, |
| 41 |
MetricSpec $metricSpec, |
| 42 |
SequenceSpec $seqSpec, |
| 43 |
TimeRange $range |
| 44 |
) { |
| 45 |
$this->reader = $reader; |
| 46 |
$this->name = $name; |
| 47 |
$this->entity = $entity; |
| 48 |
$this->metricSpec = $metricSpec; |
| 49 |
$this->seqSpec = $seqSpec; |
| 50 |
$this->range = $range; |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
public function total() { |
| 59 |
if ( $this->total === null ) { |
| 60 |
$this->total = $this->reader->internalGetCount( |
| 61 |
$this->name, |
| 62 |
$this->entity, |
| 63 |
$this->metricSpec, |
| 64 |
$this->seqSpec, |
| 65 |
$this->range |
| 66 |
); |
| 67 |
} |
| 68 |
return $this->total; |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
public function perSecond() { |
| 77 |
return $this->total() / $this->range->getDuration(); |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
public function perMinute() { |
| 86 |
return $this->perSecond() * 60; |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
public function perHour() { |
| 95 |
return $this->perSecond() * 3600; |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
public function perDay() { |
| 104 |
return $this->perSecond() * 86400; |
| 105 |
} |
| 106 |
} |