From 0d83e86edb7a8c9fbe8cdb3892fd6b7941b5e7d2 Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Fri, 31 May 2019 22:45:26 +0200 Subject: [PATCH] Added priorityElo to getPerformance and tiebreaks --- src/Player.php | 4 ++-- src/Tiebreaks.php | 10 ++++------ src/Tournament.php | 6 +++--- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/Player.php b/src/Player.php index 73998f9..01a7034 100644 --- a/src/Player.php +++ b/src/Player.php @@ -131,13 +131,13 @@ class Player extends PlayerModel /** * @return int */ - public function getPerformance(): int + public function getPerformance(string $type) : int { $total = 0; $opponents = 0; foreach ($this->getPairings() as $pairing) { if (array_search($pairing->getResult(), Constants::Notplayed)) { - $opponentElo = $pairing->getOpponent()->getElo('Nation'); + $opponentElo = $pairing->getOpponent()->getElo($type); $opponentElo = $opponentElo != 0 ? $opponentElo : $this->getUnratedElo(); if (array_search(self::Won, $pairing->getResult())) { $total += $opponentElo + 400; diff --git a/src/Tiebreaks.php b/src/Tiebreaks.php index e4a6b01..1008a08 100644 --- a/src/Tiebreaks.php +++ b/src/Tiebreaks.php @@ -128,15 +128,13 @@ abstract class Tiebreaks extends Tournament * @param int $cut * @return float */ - protected function calculateAverageRating(Player $player, int $cut = 0): ?float + protected function calculateAverageRating(Player $player, string $type, int $cut = 0): ?float { $pairings = $player->getPairings(); - $totalrating = 0; - $totalopponents = 0; $allratings = []; foreach ($pairings as $pairing) { if (array_search($pairing->getResult(), Constants::NotPlayed) === false) { - $toadd = $pairing->getOpponent()->getElo('Nation'); + $toadd = $pairing->getOpponent()->getElo($type); if ($toadd != 0) { $allratings[] = $toadd; } @@ -153,13 +151,13 @@ abstract class Tiebreaks extends Tournament * @param int $cut * @return float|null */ - protected function calculateAveragePerformance(Player $player, int $cut = 0): ?float + protected function calculateAveragePerformance(Player $player, string $type, int $cut = 0): ?float { $pairings = $player->getPairings(); $allratings = []; foreach ($pairings as $pairing) { if (array_search($pairing->getResult(), Constants::NotPlayed) === false) { - $toadd = $pairing->getOpponent()->getPerformance('Nation'); + $toadd = $pairing->getOpponent()->getPerformance($type); if ($toadd != 0) { $allratings[] = $toadd; } diff --git a/src/Tournament.php b/src/Tournament.php index 6d7d9bf..f6ab62f 100644 --- a/src/Tournament.php +++ b/src/Tournament.php @@ -291,10 +291,10 @@ class Tournament extends Tiebreaks return $this->calculateMutualResult($player, $this->getPlayers(), $tbkey); break; case Tiebreak::Aro: - return $this->calculateAverageRating($player); + return $this->calculateAverageRating($player, $this->getPriorityElo()); break; case Tiebreak::AroCut: - return $this->calculateAverageRating($player, 1); + return $this->calculateAverageRating($player, $this->getPriorityElo(), 1); break; case Tiebreak::Koya: return $this->calculateKoya($player); @@ -318,7 +318,7 @@ class Tournament extends Tiebreaks return $this->calculateCumulative($player); break; case Tiebreak::Performance: - return $this->calculateAveragePerformance($player); + return $this->calculateAveragePerformance($player, $this->getPriorityElo()); break; default: return null;