From d9aebfd90cf79f620a905e5cc183acd5f41a75d2 Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Wed, 29 May 2019 17:57:42 +0200 Subject: [PATCH] Added average rating calculation --- src/Tournament.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Tournament.php b/src/Tournament.php index 6968a6c..333c36a 100644 --- a/src/Tournament.php +++ b/src/Tournament.php @@ -297,4 +297,25 @@ class Tournament extends Tiebreaks return null; } } + + /** + * Return the average rating for tournament + * + * @return int + */ + public function getAverageElo(): int + { + $totalrating = 0; + $players = 0; + foreach ($this->getPlayers() as $player) { + $toadd = $player->getElos()['home']; + if ($toadd == 0) { + $toadd = $this->getNonRatedElo(); + } + + $totalrating += $toadd; + $players++; + } + return intdiv($totalrating, $players); + } }