From aef6b688e9a0c6b76a99190170b53d295c70ba21 Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Thu, 30 May 2019 21:10:31 +0200 Subject: [PATCH] Implemented Player::getPerformance() --- src/Player.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/Player.php b/src/Player.php index d750870..2bc5b45 100644 --- a/src/Player.php +++ b/src/Player.php @@ -127,4 +127,27 @@ class Player extends PlayerModel } return $points; } + + + /** + * @return float + */ + public function getPerformance() + { + $total = 0; + $opponents = 0; + foreach ($this->getPairings() as $pairing) { + if (array_search($pairing->getResult(), Constants::Notplayed)) { + if (array_search(self::Won, $pairing->getResult())) { + $total += $pairing->getOpponent()->getElo('home') + 400; + } elseif (array_search(self::Lost, $pairing->getResult())) { + $total += $pairing->getOpponent()->getElo('home') - 400; + } elseif (array_search(self::Draw, $pairing->getResult())) { + $total += $pairing->getOpponent()->getElo('home'); + } + $opponents++; + } + return round($total / $opponents); + } + } }