summaryrefslogtreecommitdiffstats
path: root/library/Reporting/ReportData.php
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 13:28:59 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 13:28:59 +0000
commit978a1651bac3faf5e91ddba327bf39aeb6a4cb63 (patch)
treef0d1fee61877df200ccfb1c0af58a39cd551fb46 /library/Reporting/ReportData.php
parentInitial commit. (diff)
downloadicingaweb2-module-reporting-978a1651bac3faf5e91ddba327bf39aeb6a4cb63.tar.xz
icingaweb2-module-reporting-978a1651bac3faf5e91ddba327bf39aeb6a4cb63.zip
Adding upstream version 0.10.0.upstream/0.10.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/Reporting/ReportData.php')
-rw-r--r--library/Reporting/ReportData.php71
1 files changed, 71 insertions, 0 deletions
diff --git a/library/Reporting/ReportData.php b/library/Reporting/ReportData.php
new file mode 100644
index 0000000..787f4db
--- /dev/null
+++ b/library/Reporting/ReportData.php
@@ -0,0 +1,71 @@
+<?php
+// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2
+
+namespace Icinga\Module\Reporting;
+
+class ReportData implements \Countable
+{
+ use Dimensions;
+ use Values;
+
+ /** @var ReportRow[]|null */
+ protected $rows;
+
+ public function getRows()
+ {
+ return $this->rows;
+ }
+
+ public function setRows(array $rows)
+ {
+ $this->rows = $rows;
+
+ return $this;
+ }
+
+ public function getAverages()
+ {
+ $totals = $this->getTotals();
+ $averages = [];
+ $count = \count($this);
+
+ foreach ($totals as $total) {
+ $averages[] = $total / $count;
+ }
+
+ return $averages;
+ }
+
+// public function getMaximums()
+// {
+// }
+
+// public function getMinimums()
+// {
+// }
+
+ public function getTotals()
+ {
+ $totals = [];
+
+ foreach ((array) $this->getRows() as $row) {
+ $i = 0;
+ foreach ((array) $row->getValues() as $value) {
+ if (! isset($totals[$i])) {
+ $totals[$i] = $value;
+ } else {
+ $totals[$i] += $value;
+ }
+
+ ++$i;
+ }
+ }
+
+ return $totals;
+ }
+
+ public function count(): int
+ {
+ return count((array) $this->getRows());
+ }
+}