From 4ada86876033fa171e2896d7e3d3c5645d8062db Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 14:46:47 +0200 Subject: Adding upstream version 0.10.0. Signed-off-by: Daniel Baumann --- library/Reporting/ReportData.php | 71 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 library/Reporting/ReportData.php (limited to 'library/Reporting/ReportData.php') 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 @@ +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()); + } +} -- cgit v1.2.3