From 912f4e3e21b5150dfd6cdf979baaa0acdff96b61 Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Thu, 30 May 2019 08:33:16 +0200 Subject: [PATCH 1/2] Some documentation and bugfixes --- src/Models/Player.php | 4 ++-- src/Readers/Pairtwo6.php | 2 -- src/Tournament.php | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Models/Player.php b/src/Models/Player.php index 216b56b..18e8ebd 100644 --- a/src/Models/Player.php +++ b/src/Models/Player.php @@ -70,7 +70,7 @@ abstract class Player /** * @return string[] */ - public function getIds(): array + public function getIds(): ?array { return $this->Ids; } @@ -88,7 +88,7 @@ abstract class Player /** * @return int[] */ - public function getElos(): array + public function getElos(): ?array { return $this->Elos; } diff --git a/src/Readers/Pairtwo6.php b/src/Readers/Pairtwo6.php index 4f3b88d..208e017 100644 --- a/src/Readers/Pairtwo6.php +++ b/src/Readers/Pairtwo6.php @@ -458,8 +458,6 @@ class Pairtwo6 extends Pairtwo6Model implements ReaderInterface $player->setBinaryData("TieMatch", $this->readData('Int', substr($swscontents, $offset, $length))); $offset += $length; - $player->setElos($elos); - $player->setIds($ids); $this->getTournament()->addPlayer($player); } // PlayerNames diff --git a/src/Tournament.php b/src/Tournament.php index 333c36a..cd08fa7 100644 --- a/src/Tournament.php +++ b/src/Tournament.php @@ -264,7 +264,7 @@ class Tournament extends Tiebreaks /** - * @return float|bool + * @return float|null */ private function calculateTiebreak(Tiebreak $tiebreak, Player $player, int $tbkey = 0): ?float { From 5bac5e746fb7e389f028932b7a2d6823af20f0a3 Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Thu, 30 May 2019 08:33:52 +0200 Subject: [PATCH 2/2] Implemented Aro Cut 1 --- src/Tiebreaks.php | 10 ++++++---- src/Tournament.php | 3 +++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Tiebreaks.php b/src/Tiebreaks.php index 1670315..424ce83 100644 --- a/src/Tiebreaks.php +++ b/src/Tiebreaks.php @@ -141,20 +141,22 @@ abstract class Tiebreaks extends Tournament * @param Player $player * @return float */ - protected function calculateAverageRating(Player $player) + protected function calculateAverageRating(Player $player, int $cut = 0) { $pairings = $player->getPairings(); $totalrating = 0; $totalopponents = 0; + $allratings = []; foreach ($pairings as $pairing) { if (array_search($pairing->getResult(), self::NotPlayed) === false) { $toadd = $pairing->getOpponent()->getElos()['home']; if ($toadd != 0) { - $totalrating += $toadd; - $totalopponents++; + $allratings[] = $toadd; } } } - return round($totalrating / $totalopponents); + sort($allratings); + $allratings = array_slice($allratings, $cut); + return round(array_sum($allratings) / count($allratings)); } } diff --git a/src/Tournament.php b/src/Tournament.php index cd08fa7..09e1107 100644 --- a/src/Tournament.php +++ b/src/Tournament.php @@ -293,6 +293,9 @@ class Tournament extends Tiebreaks case Tiebreak::Aro: return $this->calculateAverageRating($player); break; + case Tiebreak::AroCut: + return $this->calculateAverageRating($player, 1); + break; default: return null; }