1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\Module\statistics\Statistics\Rulesets; |
6
|
|
|
|
7
|
|
|
use SimpleSAML\Configuration; |
8
|
|
|
use SimpleSAML\Error; |
9
|
|
|
use SimpleSAML\Module\statistics\RatioDataset; |
10
|
|
|
use SimpleSAML\Module\statistics\StatDataset; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @package SimpleSAMLphp |
14
|
|
|
*/ |
15
|
|
|
class Ratio extends BaseRule |
16
|
|
|
{ |
17
|
|
|
/** @var \SimpleSAML\Module\statistics\Statistics\Rulesets\BaseRule $refrule1 */ |
18
|
|
|
protected BaseRule $refrule1; |
19
|
|
|
|
20
|
|
|
/** @var \SimpleSAML\Module\statistics\Statistics\Rulesets\BaseRule $refrule2 */ |
21
|
|
|
protected BaseRule $refrule2; |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Constructor |
26
|
|
|
* |
27
|
|
|
* @param \SimpleSAML\Configuration $statconfig |
28
|
|
|
* @param \SimpleSAML\Configuration $ruleconfig |
29
|
|
|
* @param string $ruleid |
30
|
|
|
* @param array $available |
31
|
|
|
*/ |
32
|
|
|
public function __construct(Configuration $statconfig, Configuration $ruleconfig, string $ruleid, array $available) |
33
|
|
|
{ |
34
|
|
|
parent::__construct($statconfig, $ruleconfig, $ruleid, $available); |
35
|
|
|
|
36
|
|
|
$refNames = $this->ruleconfig->getArray('ref'); |
37
|
|
|
|
38
|
|
|
$statrulesConfig = $this->statconfig->getOptionalConfigItem('statrules', null); |
39
|
|
|
if ($statrulesConfig === null) { |
40
|
|
|
throw new Error\ConfigurationError('Missing \'statrules\' in module configuration.'); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
$statruleConfig1 = $statrulesConfig->getOptionalConfigItem($refNames[0], null); |
44
|
|
|
$statruleConfig2 = $statrulesConfig->getOptionalConfigItem($refNames[1], null); |
45
|
|
|
|
46
|
|
|
if ($statruleConfig1 === null || $statruleConfig2 === null) { |
47
|
|
|
throw new Error\ConfigurationError(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
$this->refrule1 = new BaseRule($this->statconfig, $statruleConfig1, $refNames[0], $available); |
51
|
|
|
$this->refrule2 = new BaseRule($this->statconfig, $statruleConfig2, $refNames[1], $available); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @return array |
57
|
|
|
*/ |
58
|
|
|
public function availableTimeRes(): array |
59
|
|
|
{ |
60
|
|
|
return $this->refrule1->availableTimeRes(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param string $timeres |
66
|
|
|
* @return array |
67
|
|
|
*/ |
68
|
|
|
public function availableFileSlots(string $timeres): array |
69
|
|
|
{ |
70
|
|
|
return $this->refrule1->availableFileSlots($timeres); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @param string $preferTimeRes |
76
|
|
|
* @return string |
77
|
|
|
*/ |
78
|
|
|
protected function resolveTimeRes(string $preferTimeRes): string |
79
|
|
|
{ |
80
|
|
|
return $this->refrule1->resolveTimeRes($preferTimeRes); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @param string $timeres |
86
|
|
|
* @param string $preferTime |
87
|
|
|
* @return string |
88
|
|
|
*/ |
89
|
|
|
protected function resolveFileSlot($timeres, $preferTime): string |
90
|
|
|
{ |
91
|
|
|
return $this->refrule1->resolveFileSlot($timeres, $preferTime); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @param string $timeres |
97
|
|
|
* @param string $preferTime |
98
|
|
|
* @return array |
99
|
|
|
*/ |
100
|
|
|
public function getTimeNavigation(string $timeres, string $preferTime): array |
101
|
|
|
{ |
102
|
|
|
return $this->refrule1->getTimeNavigation($timeres, $preferTime); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @param string $preferTimeRes |
108
|
|
|
* @param string $preferTime |
109
|
|
|
* @return \SimpleSAML\Module\statistics\RatioDataset |
110
|
|
|
*/ |
111
|
|
|
public function getDataSet(string $preferTimeRes, string $preferTime): StatDataset |
112
|
|
|
{ |
113
|
|
|
$timeres = $this->resolveTimeRes($preferTimeRes); |
114
|
|
|
$fileslot = $this->resolveFileSlot($timeres, $preferTime); |
115
|
|
|
|
116
|
|
|
$refNames = $this->ruleconfig->getArray('ref'); |
117
|
|
|
|
118
|
|
|
$dataset = new RatioDataset( |
119
|
|
|
$this->statconfig, |
120
|
|
|
$this->ruleconfig, |
121
|
|
|
$refNames, |
122
|
|
|
$timeres, |
123
|
|
|
$fileslot, |
124
|
|
|
); |
125
|
|
|
return $dataset; |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|