1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\Module\statistics; |
6
|
|
|
|
7
|
|
|
use SimpleSAML\Configuration; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @package SimpleSAMLphp |
11
|
|
|
*/ |
12
|
|
|
class RatioDataset extends StatDataset |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* Constructor |
16
|
|
|
* |
17
|
|
|
* @param \SimpleSAML\Configuration $statconfig |
18
|
|
|
* @param \SimpleSAML\Configuration $ruleconfig |
19
|
|
|
* @param array $ruleid |
20
|
|
|
* @param string $timeres |
21
|
|
|
* @param string $fileslot |
22
|
|
|
*/ |
23
|
|
|
public function __construct( |
24
|
|
|
Configuration $statconfig, |
25
|
|
|
Configuration $ruleconfig, |
26
|
|
|
array $ruleid, |
27
|
|
|
string $timeres, |
28
|
|
|
string $fileslot, |
29
|
|
|
) { |
30
|
|
|
parent::__construct($statconfig, $ruleconfig, $ruleid, $timeres, $fileslot); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
*/ |
36
|
|
|
public function aggregateSummary(): void |
37
|
|
|
{ |
38
|
|
|
/** |
39
|
|
|
* Aggregate summary table from dataset. To be used in the table view. |
40
|
|
|
*/ |
41
|
|
|
$this->summary = []; |
42
|
|
|
$noofvalues = []; |
43
|
|
|
foreach ($this->results as $slot => $res) { |
44
|
|
|
foreach ($res as $key => $value) { |
45
|
|
|
if (array_key_exists($key, $this->summary)) { |
46
|
|
|
$this->summary[$key] += $value; |
47
|
|
|
if ($value > 0) { |
48
|
|
|
$noofvalues[$key]++; |
49
|
|
|
} |
50
|
|
|
} else { |
51
|
|
|
$this->summary[$key] = $value; |
52
|
|
|
if ($value > 0) { |
53
|
|
|
$noofvalues[$key] = 1; |
54
|
|
|
} else { |
55
|
|
|
$noofvalues[$key] = 0; |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
foreach ($this->summary as $key => $val) { |
62
|
|
|
$this->summary[$key] = $this->divide($this->summary[$key], $noofvalues[$key]); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
asort($this->summary); |
66
|
|
|
$this->summary = array_reverse($this->summary, true); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param string $k |
72
|
|
|
* @param array $a |
73
|
|
|
* @return int |
74
|
|
|
*/ |
75
|
|
|
private function ag(string $k, array $a): int |
76
|
|
|
{ |
77
|
|
|
if (array_key_exists($k, $a)) { |
78
|
|
|
return $a[$k]; |
79
|
|
|
} |
80
|
|
|
return 0; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @param int $v1 |
86
|
|
|
* @param int $v2 |
87
|
|
|
* @return int|float |
88
|
|
|
*/ |
89
|
|
|
private function divide(int $v1, int $v2) |
90
|
|
|
{ |
91
|
|
|
if ($v2 == 0) { |
92
|
|
|
return 0; |
93
|
|
|
} |
94
|
|
|
return ($v1 / $v2); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @param array $result1 |
100
|
|
|
* @param array $result2 |
101
|
|
|
* @return array |
102
|
|
|
*/ |
103
|
|
|
public function combine(array $result1, array $result2): array |
104
|
|
|
{ |
105
|
|
|
$combined = []; |
106
|
|
|
|
107
|
|
|
foreach ($result2 as $tick => $val) { |
108
|
|
|
$combined[$tick] = []; |
109
|
|
|
foreach ($val as $index => $num) { |
110
|
|
|
$combined[$tick][$index] = $this->divide( |
111
|
|
|
$this->ag($index, $result1[$tick]), |
112
|
|
|
$this->ag($index, $result2[$tick]), |
113
|
|
|
); |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
return $combined; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @return array |
122
|
|
|
*/ |
123
|
|
|
public function getPieData(): array |
124
|
|
|
{ |
125
|
|
|
return []; |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|