summaryrefslogtreecommitdiffstats
path: root/library/Reporting/ReportData.php
diff options
context:
space:
mode:
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());
+ }
+}