diff --git a/dist/boilerplate.php b/dist/boilerplate.php index 276391a..ed288ff 100644 --- a/dist/boilerplate.php +++ b/dist/boilerplate.php @@ -10,8 +10,8 @@ require_once 'vendor/autoload.php'; $pairingfile = 'your pairing-file.sws'; -if(!file_exists($pairingfile)) { - trigger_error('Your file is not set or doesn\'t exist! Edit the file: ' . __FILE__ . ' and try again', E_USER_ERROR); +if (!file_exists($pairingfile)) { + trigger_error('Your file is not set or doesn\'t exist! Edit the file: ' . __FILE__ . ' and try again', E_USER_ERROR); } $reader = IOFactory::createReader('Pairtwo-6'); diff --git a/src/Constants.php b/src/Constants.php index ab8be63..8950dd2 100644 --- a/src/Constants.php +++ b/src/Constants.php @@ -1,11 +1,30 @@ + * @category Main + * @package Libpairtwo + * @copyright Copyright (c) 2018-2019 Jeroen De Meerleer + */ namespace JeroenED\Libpairtwo; use JeroenED\Libpairtwo\Enums\Color; use JeroenED\Libpairtwo\Enums\Result; +/** + * Class Constants + * + * Static class for constants + * + * @author Jeroen De Meerleer + * @category Main + * @package Libpairtwo + * @copyright Copyright (c) 2018-2019 Jeroen De Meerleer + */ class Constants { const Won = [ Result::won, Result::wonforfait, Result::wonbye, Result::wonadjourned ]; diff --git a/src/Enums/Color.php b/src/Enums/Color.php index 67fae9d..9f35580 100644 --- a/src/Enums/Color.php +++ b/src/Enums/Color.php @@ -1,15 +1,29 @@ + * @category Main + * @package Libpairtwo + * @copyright Copyright (c) 2018-2019 Jeroen De Meerleer */ namespace JeroenED\Libpairtwo\Enums; use MyCLabs\Enum\Enum; +/** + * Enum Color + * + * List of all compatible colors + * + * @author Jeroen De Meerleer + * @category Main + * @package Libpairtwo + * @copyright Copyright (c) 2018-2019 Jeroen De Meerleer + */ class Color extends Enum { const black = 'B'; diff --git a/src/Enums/Gameresult.php b/src/Enums/Gameresult.php index 2b55a39..bf0b6f9 100644 --- a/src/Enums/Gameresult.php +++ b/src/Enums/Gameresult.php @@ -1,15 +1,29 @@ + * @category Main + * @package Libpairtwo + * @copyright Copyright (c) 2018-2019 Jeroen De Meerleer */ namespace JeroenED\Libpairtwo\Enums; use MyCLabs\Enum\Enum; +/** + * Enum Gameresult + * + * List of all compatible gameresults + * + * @author Jeroen De Meerleer + * @category Main + * @package Libpairtwo + * @copyright Copyright (c) 2018-2019 Jeroen De Meerleer + */ class Gameresult extends Enum { const None = '-'; diff --git a/src/Enums/Gender.php b/src/Enums/Gender.php index be6ac45..bcb2d9c 100644 --- a/src/Enums/Gender.php +++ b/src/Enums/Gender.php @@ -1,15 +1,30 @@ + * @category Main + * @package Libpairtwo + * @copyright Copyright (c) 2018-2019 Jeroen De Meerleer */ namespace JeroenED\Libpairtwo\Enums; use MyCLabs\Enum\Enum; + +/** + * Enum Gender + * + * List of all compatible genders + * + * @author Jeroen De Meerleer + * @category Main + * @package Libpairtwo + * @copyright Copyright (c) 2018-2019 Jeroen De Meerleer + */ class Gender extends Enum { const Neutral = 'X'; // Unforturnately, Incompatible with Pairtwo (Dinos) diff --git a/src/Enums/Result.php b/src/Enums/Result.php index 6d026fc..a064612 100644 --- a/src/Enums/Result.php +++ b/src/Enums/Result.php @@ -1,15 +1,29 @@ + * @category Main + * @package Libpairtwo + * @copyright Copyright (c) 2018-2019 Jeroen De Meerleer */ namespace JeroenED\Libpairtwo\Enums; use MyCLabs\Enum\Enum; +/** + * Enum Result + * + * List of all compatible results + * + * @author Jeroen De Meerleer + * @category Main + * @package Libpairtwo + * @copyright Copyright (c) 2018-2019 Jeroen De Meerleer + */ class Result extends Enum { const none = '*'; diff --git a/src/Enums/Tiebreak.php b/src/Enums/Tiebreak.php index 765702d..82fab3e 100644 --- a/src/Enums/Tiebreak.php +++ b/src/Enums/Tiebreak.php @@ -1,10 +1,29 @@ + * @category Main + * @package Libpairtwo + * @copyright Copyright (c) 2018-2019 Jeroen De Meerleer + */ namespace JeroenED\Libpairtwo\Enums; use MyCLabs\Enum\Enum; +/** + * Enum Tiebreak + * + * List of all compatible tiebreaks + * + * @author Jeroen De Meerleer + * @category Main + * @package Libpairtwo + * @copyright Copyright (c) 2018-2019 Jeroen De Meerleer + */ class Tiebreak extends Enum { const None = ""; diff --git a/src/Enums/Title.php b/src/Enums/Title.php index 1533a42..e27cf94 100644 --- a/src/Enums/Title.php +++ b/src/Enums/Title.php @@ -1,15 +1,29 @@ + * @category Main + * @package Libpairtwo + * @copyright Copyright (c) 2018-2019 Jeroen De Meerleer */ namespace JeroenED\Libpairtwo\Enums; use MyCLabs\Enum\Enum; +/** + * Enum Title + * + * List of all compatible titles + * + * @author Jeroen De Meerleer + * @category Main + * @package Libpairtwo + * @copyright Copyright (c) 2018-2019 Jeroen De Meerleer + */ class Title extends Enum { const NONE = '*'; diff --git a/src/Enums/TournamentSystem.php b/src/Enums/TournamentSystem.php index 03305ce..2109555 100644 --- a/src/Enums/TournamentSystem.php +++ b/src/Enums/TournamentSystem.php @@ -1,15 +1,29 @@ + * @category Main + * @package Libpairtwo + * @copyright Copyright (c) 2018-2019 Jeroen De Meerleer */ namespace JeroenED\Libpairtwo\Enums; use MyCLabs\Enum\Enum; +/** + * Enum TournamentSystem + * + * List of all compatible tournament systems + * + * @author Jeroen De Meerleer + * @category Main + * @package Libpairtwo + * @copyright Copyright (c) 2018-2019 Jeroen De Meerleer + */ class TournamentSystem extends Enum { const Swiss = 'Swiss'; diff --git a/src/Exceptions/IncompatibleReaderException.php b/src/Exceptions/IncompatibleReaderException.php index 8785357..5a4cd41 100644 --- a/src/Exceptions/IncompatibleReaderException.php +++ b/src/Exceptions/IncompatibleReaderException.php @@ -1,8 +1,27 @@ + * @category Main + * @package Libpairtwo + * @copyright Copyright (c) 2018-2019 Jeroen De Meerleer + */ namespace JeroenED\Libpairtwo\Exceptions; +/** + * Exception IncompatibleReaderException + * + * Exception to be raised when a reader is used that is incompatible + * + * @author Jeroen De Meerleer + * @category Main + * @package Libpairtwo + * @copyright Copyright (c) 2018-2019 Jeroen De Meerleer + */ class IncompatibleReaderException extends LibpairtwoException { } diff --git a/src/Exceptions/LibpairtwoException.php b/src/Exceptions/LibpairtwoException.php index 7a9f580..147b783 100644 --- a/src/Exceptions/LibpairtwoException.php +++ b/src/Exceptions/LibpairtwoException.php @@ -1,8 +1,27 @@ + * @category Main + * @package Libpairtwo + * @copyright Copyright (c) 2018-2019 Jeroen De Meerleer + */ namespace JeroenED\Libpairtwo\Exceptions; +/** + * Exception LibpairtwoException + * + * General exception when something goes wrong with libpairtwo + * + * @author Jeroen De Meerleer + * @category Main + * @package Libpairtwo + * @copyright Copyright (c) 2018-2019 Jeroen De Meerleer + */ class LibpairtwoException extends \Exception { } diff --git a/src/Game.php b/src/Game.php index 7b3fe8b..f14a1c0 100644 --- a/src/Game.php +++ b/src/Game.php @@ -1,20 +1,47 @@ + * @category Main + * @package Libpairtwo + * @copyright Copyright (c) 2018-2019 Jeroen De Meerleer */ namespace JeroenED\Libpairtwo; +use DateTime; use JeroenED\Libpairtwo\Enums\Gameresult; -use JeroenED\Libpairtwo\Models\Game as GameModel; +use JeroenED\Libpairtwo\Models\Round; +use JeroenED\Libpairtwo\Pairing; -class Game extends GameModel +/** + * Class Games + * + * Class for a game of the tournament + * + * @author Jeroen De Meerleer + * @category Main + * @package Libpairtwo + * @copyright Copyright (c) 2018-2019 Jeroen De Meerleer + */ +class Game { + /** @var Pairing|null */ + private $white; + + /** @var Pairing|null */ + private $black; + + /** @var GameResult|null */ + private $result; + /** * This function gets the result from the game + * + * @return Gameresult */ public function getResult(): Gameresult { @@ -46,4 +73,132 @@ class Game extends GameModel return $result; } + + /** + * Gets pairing for white player + * + * @return Pairing|null + */ + public function getWhite(): ?Pairing + { + return $this->white; + } + + /** + * Sets pairing for white player + * + * @param Pairing|null $white + * @return Game + */ + public function setWhite(?Pairing $white): Game + { + $this->white = $white; + return $this; + } + + /** + * Gets pairing for black player + * + * @return Pairing|null + */ + public function getBlack(): ?Pairing + { + return $this->black; + } + + /** + * Sets pairing for black player + * + * @param Pairing|null $black + * @return Game + */ + public function setBlack(?Pairing $black): Game + { + $this->black = $black; + return $this; + } + + /** + * Sets result for game + * + * @param Gameresult|null $result + * @return Game + */ + public function setResult(?Gameresult $result): Game + { + $this->result = $result; + return $this; + } + + /** + * @return DateTime + */ + public function getDate(): DateTime + { + return $this->date; + } + + /** + * @param DateTime $date + * @return Round + */ + public function setDate(DateTime $date): Round + { + $this->date = $date; + return $this; + } + + /** + * @return Game[] + */ + public function getGames(): array + { + return $this->games; + } + + /** + * @param Game[] $games + * @return Round + */ + public function setGames(array $games): Round + { + $this->games = $games; + return $this; + } + + /** + * @return int + */ + public function getRoundNo(): int + { + return $this->roundNo; + } + + /** + * @param int $roundNo + * @return Round + */ + public function setRoundNo(int $roundNo): Round + { + $this->roundNo = $roundNo; + return $this; + } + + /** + * @return Pairing[] + */ + public function getPairings(): array + { + return $this->pairings; + } + + /** + * @param Pairing[] $pairings + * @return Round + */ + public function setPairings(array $pairings): Round + { + $this->pairings = $pairings; + return $this; + } } diff --git a/src/IOFactory.php b/src/IOFactory.php index 9b55d9f..f732d87 100644 --- a/src/IOFactory.php +++ b/src/IOFactory.php @@ -1,5 +1,14 @@ + * @category Main + * @package Libpairtwo + * @copyright Copyright (c) 2018-2019 Jeroen De Meerleer + */ namespace JeroenED\Libpairtwo; @@ -7,8 +16,23 @@ use JeroenED\LibPairtwo\Exceptions\LibpairtwoException; use JeroenED\Libpairtwo\Interfaces\ReaderInterface; use JeroenED\Libpairtwo\Readers\Pairtwo6; +/** + * Class IOFactory + * + * Class for creating readers for pairing files + * + * @author Jeroen De Meerleer + * @category Main + * @package Libpairtwo + * @copyright Copyright (c) 2018-2019 Jeroen De Meerleer + */ abstract class IOFactory { + /** + * Compatible readers + * + * @var array + */ private static $readers = [ 'Pairtwo-6' => Readers\Pairtwo6::class, 'Pairtwo-5' => Readers\Pairtwo6::class // File structure identical diff --git a/src/Interfaces/ReaderInterface.php b/src/Interfaces/ReaderInterface.php index 68f7f90..428fcb4 100644 --- a/src/Interfaces/ReaderInterface.php +++ b/src/Interfaces/ReaderInterface.php @@ -1,12 +1,43 @@ + * @category Main + * @package Libpairtwo + * @copyright Copyright (c) 2018-2019 Jeroen De Meerleer + */ namespace JeroenED\Libpairtwo\Interfaces; use JeroenED\Libpairtwo\Tournament; +/** + * Interface ReaderInterface + * + * Sets the methods a reader needs to implement + * + * @author Jeroen De Meerleer + * @category Main + * @package Libpairtwo + * @copyright Copyright (c) 2018-2019 Jeroen De Meerleer + */ interface ReaderInterface { - public function read($filename): ReaderInterface; + /** + * Reads out $filename + * + * @param $filename + * @return ReaderInterface + */ + public function read(string $filename): ReaderInterface; + + /** + * Gets the tournament out of $filename + * + * @return Tournament + */ public function getTournament(): Tournament; } diff --git a/src/Models/Game.php b/src/Models/Game.php deleted file mode 100644 index cc63b69..0000000 --- a/src/Models/Game.php +++ /dev/null @@ -1,78 +0,0 @@ -white; - } - - /** - * @param Pairing|null $white - * @return Game - */ - public function setWhite(?Pairing $white): Game - { - $this->white = $white; - return $this; - } - - /** - * @return Pairing|null - */ - public function getBlack(): ?Pairing - { - return $this->black; - } - - /** - * @param Pairing|null $black - * @return Game - */ - public function setBlack(?Pairing $black): Game - { - $this->black = $black; - return $this; - } - - /** - * @return Gameresult|null - */ - public function getResult(): ?Gameresult - { - return $this->result; - } - - /** - * @param Gameresult|null $result - * @return Game - */ - public function setResult(?Gameresult $result): Game - { - $this->result = $result; - return $this; - } -} diff --git a/src/Models/Pairing.php b/src/Models/Pairing.php deleted file mode 100644 index 594fb28..0000000 --- a/src/Models/Pairing.php +++ /dev/null @@ -1,121 +0,0 @@ -Player; - } - - /** - * @param Player|null $Player - * @return Pairing - */ - public function setPlayer(?Player $Player): Pairing - { - $this->Player = $Player; - return $this; - } - - /** - * @return Player|null - */ - public function getOpponent(): ?Player - { - return $this->Opponent; - } - - /** - * @param Player|null $Opponent - * @return Pairing - */ - public function setOpponent(?Player $Opponent): Pairing - { - $this->Opponent = $Opponent; - return $this; - } - - /** - * @return Color - */ - public function getColor(): Color - { - return $this->Color; - } - - /** - * @param Color $Color - * @return Pairing - */ - public function setColor(Color $Color): Pairing - { - $this->Color = $Color; - return $this; - } - - /** - * @return Result - */ - public function getResult(): Result - { - return $this->Result; - } - - /** - * @param Result $Result - * @return Pairing - */ - public function setResult(Result $Result): Pairing - { - $this->Result = $Result; - return $this; - } - - /** - * @return int - */ - public function getRound(): int - { - return $this->Round; - } - - /** - * @param int $Round - * @return Pairing - */ - public function setRound(int $Round): Pairing - { - $this->Round = $Round; - return $this; - } -} diff --git a/src/Models/Player.php b/src/Models/Player.php deleted file mode 100644 index 18e8ebd..0000000 --- a/src/Models/Player.php +++ /dev/null @@ -1,255 +0,0 @@ -Name; - } - - /** - * @param string $Name - * @return Player - */ - public function setName(string $Name): Player - { - $this->Name = $Name; - return $this; - } - - /** - * @return string[] - */ - public function getIds(): ?array - { - return $this->Ids; - } - - /** - * @param string[] $Ids - * @return Player - */ - public function setIds(array $Ids): Player - { - $this->Ids = $Ids; - return $this; - } - - /** - * @return int[] - */ - public function getElos(): ?array - { - return $this->Elos; - } - - /** - * @param int[] $Elos - * @return Player - */ - public function setElos(array $Elos): Player - { - $this->Elos = $Elos; - return $this; - } - - /** - * @return \DateTime - */ - public function getDateOfBirth(): \DateTime - { - return $this->DateOfBirth; - } - - /** - * @param \DateTime $DateOfBirth - * @return Player - */ - public function setDateOfBirth(\DateTime $DateOfBirth): Player - { - $this->DateOfBirth = $DateOfBirth; - return $this; - } - - /** - * @return float[] - */ - public function getTiebreaks(): array - { - return $this->Tiebreaks; - } - - /** - * @param float[] $Tiebreaks - * @return Player - */ - public function setTiebreaks(array $Tiebreaks): Player - { - $this->Tiebreaks = $Tiebreaks; - return $this; - } - - /** - * example value: BEL - * - * @return string - */ - public function getNation(): string - { - return $this->Nation; - } - - /** - * example value: BEL - * - * @param string $Nation - * @return Player - */ - public function setNation(string $Nation): Player - { - $this->Nation = $Nation; - return $this; - } - - /** - * @return string - */ - public function getCategory(): string - { - return $this->Category; - } - - /** - * @param string $Category - * @return Player - */ - public function setCategory(string $Category): Player - { - $this->Category = $Category; - return $this; - } - - /** - * @return Title - */ - public function getTitle(): Title - { - return $this->Title; - } - - /** - * @param Title $Title - * @return Player - */ - public function setTitle(Title $Title): Player - { - $this->Title = $Title; - return $this; - } - - /** - * @return Gender - */ - public function getGender(): Gender - { - return $this->Gender; - } - - /** - * @param Gender $Gender - * @return Player - */ - public function setGender(Gender $Gender): Player - { - $this->Gender = $Gender; - return $this; - } - - /** - * @return Pairing[] - */ - public function getPairings(): array - { - return $this->Pairings; - } - - /** - * @param Pairing[] $Pairings - * @return Player - */ - public function setPairings(array $Pairings): Player - { - $this->Pairings = $Pairings; - return $this; - } - - /** - * @param string $Key - * @return bool|DateTime|int|string - */ - public function getBinaryData(string $Key) - { - return $this->BinaryData[$Key]; - } - - /** - * @param string $Key - * @param bool|int|DateTime|string $Value - * @return Player - */ - public function setBinaryData(string $Key, $Value): Player - { - $this->BinaryData[$Key] = $Value; - return $this; - } -} diff --git a/src/Models/Round.php b/src/Models/Round.php deleted file mode 100644 index dcdd277..0000000 --- a/src/Models/Round.php +++ /dev/null @@ -1,100 +0,0 @@ -date; - } - - /** - * @param DateTime $date - * @return Round - */ - public function setDate(DateTime $date): Round - { - $this->date = $date; - return $this; - } - - /** - * @return Game[] - */ - public function getGames(): array - { - return $this->games; - } - - /** - * @param Game[] $games - * @return Round - */ - public function setGames(array $games): Round - { - $this->games = $games; - return $this; - } - - /** - * @return int - */ - public function getRoundNo(): int - { - return $this->roundNo; - } - - /** - * @param int $roundNo - * @return Round - */ - public function setRoundNo(int $roundNo): Round - { - $this->roundNo = $roundNo; - return $this; - } - - /** - * @return Pairing[] - */ - public function getPairings(): array - { - return $this->pairings; - } - - /** - * @param Pairing[] $pairings - * @return Round - */ - public function setPairings(array $pairings): Round - { - $this->pairings = $pairings; - return $this; - } -} diff --git a/src/Models/Tournament.php b/src/Models/Tournament.php deleted file mode 100644 index 281104c..0000000 --- a/src/Models/Tournament.php +++ /dev/null @@ -1,543 +0,0 @@ -. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -namespace JeroenED\Libpairtwo\Models; - -use JeroenED\Libpairtwo\Enums\Tiebreak; -use JeroenED\Libpairtwo\Enums\TournamentSystem; -use JeroenED\Libpairtwo\Player; -use DateTime; - -/** - * Description of Sws - * - * @author Jeroen De Meerleer - */ -abstract class Tournament -{ - /** @var string */ - private $Name; - - /** @var string */ - private $Organiser; - - /** @var int */ - private $OrganiserClubNo; - - /** @var string */ - private $OrganiserClub; - - /** @var string */ - private $OrganiserPlace; - - /** @var string */ - private $OrganiserCountry; - - /** @var int */ - private $FideHomol; - - /** @var DateTime */ - private $StartDate; - - /** @var DateTime */ - private $EndDate; - - /** @var string */ - private $Arbiter; - - /** @var int */ - private $NoOfRounds; - - /** @var Round[] */ - private $Rounds = []; - - /** @var string */ - private $Tempo; - - /** @var int */ - private $NonRatedElo; - - /** @var TournamentSystem */ - private $System; - - /** @var string */ - private $FirstPeriod; - - /** @var string */ - private $SecondPeriod; - - /** @var string */ - private $Federation; - - /** @var Player[] */ - private $Players = []; - - /** @var int */ - private $Year; - - /** @var Pairing[] */ - private $Pairings = []; - - /** @var Tiebreak[] */ - private $Tiebreaks = []; - - /** @var string */ - private $PriorityElo = 'Fide'; - - /** @var string */ - private $PriorityId = 'Nation'; - - /** - * @return string - */ - public function getName(): string - { - return $this->Name; - } - - /** - * @param string $Name - * @return Tournament - */ - public function setName(string $Name): Tournament - { - $this->Name = $Name; - return $this; - } - - /** - * @return string - */ - public function getOrganiser(): string - { - return $this->Organiser; - } - - /** - * @param string $Organiser - * @return Tournament - */ - public function setOrganiser(string $Organiser): Tournament - { - $this->Organiser = $Organiser; - return $this; - } - - /** - * @return int - */ - public function getOrganiserClubNo(): int - { - return $this->OrganiserClubNo; - } - - /** - * @param int $OrganiserClubNo - * @return Tournament - */ - public function setOrganiserClubNo(int $OrganiserClubNo): Tournament - { - $this->OrganiserClubNo = $OrganiserClubNo; - return $this; - } - - /** - * @return string - */ - public function getOrganiserClub(): string - { - return $this->OrganiserClub; - } - - /** - * @param string $OrganiserClub - * @return Tournament - */ - public function setOrganiserClub(string $OrganiserClub): Tournament - { - $this->OrganiserClub = $OrganiserClub; - return $this; - } - - /** - * @return string - */ - public function getOrganiserPlace(): string - { - return $this->OrganiserPlace; - } - - /** - * @param string $OrganiserPlace - * @return Tournament - */ - public function setOrganiserPlace(string $OrganiserPlace): Tournament - { - $this->OrganiserPlace = $OrganiserPlace; - return $this; - } - - /** - * @return string - */ - public function getOrganiserCountry(): string - { - return $this->OrganiserCountry; - } - - /** - * @param string $OrganiserCountry - * @return Tournament - */ - public function setOrganiserCountry(string $OrganiserCountry): Tournament - { - $this->OrganiserCountry = $OrganiserCountry; - return $this; - } - - /** - * @return int - */ - public function getFideHomol(): int - { - return $this->FideHomol; - } - - /** - * @param int $FideHomol - * @return Tournament - */ - public function setFideHomol(int $FideHomol): Tournament - { - $this->FideHomol = $FideHomol; - return $this; - } - - /** - * @return DateTime - */ - public function getStartDate(): DateTime - { - return $this->StartDate; - } - - /** - * @param DateTime $StartDate - * @return Tournament - */ - public function setStartDate(DateTime $StartDate): Tournament - { - $this->StartDate = $StartDate; - return $this; - } - - /** - * @return DateTime - */ - public function getEndDate(): DateTime - { - return $this->EndDate; - } - - /** - * @param DateTime $EndDate - * @return Tournament - */ - public function setEndDate(DateTime $EndDate): Tournament - { - $this->EndDate = $EndDate; - return $this; - } - - /** - * @return string - */ - public function getArbiter(): string - { - return $this->Arbiter; - } - - /** - * @param string $Arbiter - * @return Tournament - */ - public function setArbiter(string $Arbiter): Tournament - { - $this->Arbiter = $Arbiter; - return $this; - } - - /** - * @return int - */ - public function getNoOfRounds(): int - { - return $this->NoOfRounds; - } - - /** - * @param int $NoOfRounds - * @return Tournament - */ - public function setNoOfRounds(int $NoOfRounds): Tournament - { - $this->NoOfRounds = $NoOfRounds; - return $this; - } - - /** - * @return Round[] - */ - public function getRounds(): array - { - return $this->Rounds; - } - - /** - * @param Round[] $Rounds - * @return Tournament - */ - public function setRounds(array $Rounds): Tournament - { - $this->Rounds = $Rounds; - return $this; - } - - /** - * @return string - */ - public function getTempo(): string - { - return $this->Tempo; - } - - /** - * @param string $Tempo - * @return Tournament - */ - public function setTempo(string $Tempo): Tournament - { - $this->Tempo = $Tempo; - return $this; - } - - /** - * @return int - */ - public function getNonRatedElo(): int - { - return $this->NonRatedElo; - } - - /** - * @param int $NonRatedElo - * @return Tournament - */ - public function setNonRatedElo(int $NonRatedElo): Tournament - { - $this->NonRatedElo = $NonRatedElo; - return $this; - } - - /** - * @return TournamentSystem - */ - public function getSystem(): TournamentSystem - { - return $this->System; - } - - /** - * @param TournamentSystem $System - * @return Tournament - */ - public function setSystem(TournamentSystem $System): Tournament - { - $this->System = $System; - return $this; - } - - /** - * @return string - */ - public function getFirstPeriod(): string - { - return $this->FirstPeriod; - } - - /** - * @param string $FirstPeriod - * @return Tournament - */ - public function setFirstPeriod(string $FirstPeriod): Tournament - { - $this->FirstPeriod = $FirstPeriod; - return $this; - } - - /** - * @return string - */ - public function getSecondPeriod(): string - { - return $this->SecondPeriod; - } - - /** - * @param string $SecondPeriod - * @return Tournament - */ - public function setSecondPeriod(string $SecondPeriod): Tournament - { - $this->SecondPeriod = $SecondPeriod; - return $this; - } - - /** - * @return string - */ - public function getFederation(): string - { - return $this->Federation; - } - - /** - * @param string $Federation - * @return Tournament - */ - public function setFederation(string $Federation): Tournament - { - $this->Federation = $Federation; - return $this; - } - - /** - * @return Player[] - */ - public function getPlayers(): array - { - return $this->Players; - } - - /** - * @param Player[] $Players - * @return Tournament - */ - public function setPlayers(array $Players): Tournament - { - $this->Players = $Players; - return $this; - } - - /** - * @return int - */ - public function getYear(): int - { - return $this->Year; - } - - /** - * @param int $Year - * @return Tournament - */ - public function setYear(int $Year): Tournament - { - $this->Year = $Year; - return $this; - } - - /** - * @return Pairing[] - */ - public function getPairings(): array - { - return $this->Pairings; - } - - /** - * @param Pairing[] $Pairings - * @return Tournament - */ - public function setPairings(array $Pairings): Tournament - { - $this->Pairings = $Pairings; - return $this; - } - - /** - * @return Tiebreak[] - */ - public function getTiebreaks(): array - { - return $this->Tiebreaks; - } - - /** - * @param Tiebreak[] $Tiebreaks - * @return Tournament - */ - public function setTiebreaks(array $Tiebreaks): Tournament - { - $this->Tiebreaks = $Tiebreaks; - return $this; - } - - /** - * @return string - */ - public function getPriorityElo(): string - { - return $this->PriorityElo; - } - - /** - * @param string $PriorityElo - * @return Tournament - */ - public function setPriorityElo(string $PriorityElo): Tournament - { - $this->PriorityElo = $PriorityElo; - return $this; - } - /** - * @return string - */ - public function getPriorityId(): string - { - return $this->PriorityId; - } - - /** - * @param string $PriorityId - * @return Tournament - */ - public function setPriorityId(string $PriorityId): Tournament - { - $this->PriorityId = $PriorityId; - return $this; - } -} diff --git a/src/Pairing.php b/src/Pairing.php index 48e3b91..eaba02f 100644 --- a/src/Pairing.php +++ b/src/Pairing.php @@ -1,15 +1,134 @@ + * @category Main + * @package Libpairtwo + * @copyright Copyright (c) 2018-2019 Jeroen De Meerleer */ namespace JeroenED\Libpairtwo; -use JeroenED\Libpairtwo\Models\Pairing as PairingModel; +use JeroenED\Libpairtwo\Enums\Color; +use JeroenED\Libpairtwo\Enums\Result; -class Pairing extends PairingModel +/** + * Class Pairing + * + * Class for a pairing of the tournament + * + * @author Jeroen De Meerleer + * @category Main + * @package Libpairtwo + * @copyright Copyright (c) 2018-2019 Jeroen De Meerleer + */ +class Pairing { + /** @var Player|null */ + private $Player; + + /** @var Player|null */ + private $Opponent; + + /** @var Color */ + private $Color; + + /** @var Result */ + private $Result; + + /** @var int */ + private $Round; + + /** + * @return Player|null + */ + public function getPlayer(): ?Player + { + return $this->Player; + } + + /** + * @param Player|null $Player + * @return Pairing + */ + public function setPlayer(?Player $Player): Pairing + { + $this->Player = $Player; + return $this; + } + + /** + * @return Player|null + */ + public function getOpponent(): ?Player + { + return $this->Opponent; + } + + /** + * @param Player|null $Opponent + * @return Pairing + */ + public function setOpponent(?Player $Opponent): Pairing + { + $this->Opponent = $Opponent; + return $this; + } + + /** + * @return Color + */ + public function getColor(): Color + { + return $this->Color; + } + + /** + * @param Color $Color + * @return Pairing + */ + public function setColor(Color $Color): Pairing + { + $this->Color = $Color; + return $this; + } + + /** + * @return Result + */ + public function getResult(): Result + { + return $this->Result; + } + + /** + * @param Result $Result + * @return Pairing + */ + public function setResult(Result $Result): Pairing + { + $this->Result = $Result; + return $this; + } + + /** + * @return int + */ + public function getRound(): int + { + return $this->Round; + } + + /** + * @param int $Round + * @return Pairing + */ + public function setRound(int $Round): Pairing + { + $this->Round = $Round; + return $this; + } } diff --git a/src/Player.php b/src/Player.php index 12155cb..027f946 100644 --- a/src/Player.php +++ b/src/Player.php @@ -1,22 +1,67 @@ + * @category Main + * @package Libpairtwo + * @copyright Copyright (c) 2018-2019 Jeroen De Meerleer */ namespace JeroenED\Libpairtwo; -use JeroenED\Libpairtwo\Models\Player as PlayerModel; +use JeroenED\Libpairtwo\Enums\Title; +use JeroenED\Libpairtwo\Enums\Gender; +use DateTime; /** * Class Player - * @package JeroenED\Libpairtwo + * + * Class for a player of the tournament + * + * @author Jeroen De Meerleer + * @category Main + * @package Libpairtwo + * @copyright Copyright (c) 2018-2019 Jeroen De Meerleer */ -class Player extends PlayerModel +class Player { - + /** @var string */ + private $Name; + + /** @var int[] */ + private $Ids; + + /** @var int[] */ + private $Elos; + + /** @var DateTime */ + private $DateOfBirth; + + /** @var float[] */ + private $Tiebreaks = []; + + /** @var string */ + private $Nation; + + // TODO: Implement categories + /** @var string */ + private $Category; + + /** @var Title */ + private $Title; + + /** @var Gender */ + private $Gender; + + /** @var Pairing[] */ + private $Pairings = []; + + /** @var bool|DateTime|int|string[] */ + private $BinaryData; + /** * Adds a pairing to the tournament * @@ -166,4 +211,208 @@ class Player extends PlayerModel } return $total; } + + /** + * @return string + */ + public function getName(): string + { + return $this->Name; + } + + /** + * @param string $Name + * @return \JeroenED\Libpairtwo\Models\Player + */ + public function setName(string $Name): Player + { + $this->Name = $Name; + return $this; + } + + /** + * @return string[] + */ + public function getIds(): ?array + { + return $this->Ids; + } + + /** + * @param string[] $Ids + * @return Player + */ + public function setIds(array $Ids): Player + { + $this->Ids = $Ids; + return $this; + } + + /** + * @return int[] + */ + public function getElos(): ?array + { + return $this->Elos; + } + + /** + * @param int[] $Elos + * @return Player + */ + public function setElos(array $Elos): Player + { + $this->Elos = $Elos; + return $this; + } + + /** + * @return \DateTime + */ + public function getDateOfBirth(): \DateTime + { + return $this->DateOfBirth; + } + + /** + * @param \DateTime $DateOfBirth + * @return Player + */ + public function setDateOfBirth(\DateTime $DateOfBirth): Player + { + $this->DateOfBirth = $DateOfBirth; + return $this; + } + + /** + * @return float[] + */ + public function getTiebreaks(): array + { + return $this->Tiebreaks; + } + + /** + * @param float[] $Tiebreaks + * @return Player + */ + public function setTiebreaks(array $Tiebreaks): Player + { + $this->Tiebreaks = $Tiebreaks; + return $this; + } + + /** + * example value: BEL + * + * @return string + */ + public function getNation(): string + { + return $this->Nation; + } + + /** + * example value: BEL + * + * @param string $Nation + * @return Player + */ + public function setNation(string $Nation): Player + { + $this->Nation = $Nation; + return $this; + } + + /** + * @return string + */ + public function getCategory(): string + { + return $this->Category; + } + + /** + * @param string $Category + * @return Player + */ + public function setCategory(string $Category): Player + { + $this->Category = $Category; + return $this; + } + + /** + * @return Title + */ + public function getTitle(): Title + { + return $this->Title; + } + + /** + * @param Title $Title + * @return Player + */ + public function setTitle(Title $Title): Player + { + $this->Title = $Title; + return $this; + } + + /** + * @return Gender + */ + public function getGender(): Gender + { + return $this->Gender; + } + + /** + * @param Gender $Gender + * @return Player + */ + public function setGender(Gender $Gender): Player + { + $this->Gender = $Gender; + return $this; + } + + /** + * @return Pairing[] + */ + public function getPairings(): array + { + return $this->Pairings; + } + + /** + * @param Pairing[] $Pairings + * @return Player + */ + public function setPairings(array $Pairings): Player + { + $this->Pairings = $Pairings; + return $this; + } + + /** + * @param string $Key + * @return bool|DateTime|int|string + */ + public function getBinaryData(string $Key) + { + return $this->BinaryData[$Key]; + } + + /** + * @param string $Key + * @param bool|int|DateTime|string $Value + * @return Player + */ + public function setBinaryData(string $Key, $Value): Player + { + $this->BinaryData[$Key] = $Value; + return $this; + } } diff --git a/src/Readers/Models/Pairtwo6.php b/src/Readers/Models/Pairtwo6.php deleted file mode 100644 index 84ee58c..0000000 --- a/src/Readers/Models/Pairtwo6.php +++ /dev/null @@ -1,75 +0,0 @@ -Release; - } - - /** - * @param string $Release - * @return Pairtwo6 - */ - public function setRelease(string $Release): Pairtwo6 - { - $this->Release = $Release; - return $this; - } - - /** - * @return Tournament - */ - public function getTournament(): Tournament - { - return $this->Tournament; - } - - /** - * @param Tournament $Tournament - * @return Pairtwo6 - */ - public function setTournament(Tournament $Tournament): Pairtwo6 - { - $this->Tournament = $Tournament; - return $this; - } - - - /** - * @param string $Key - * @return bool|DateTime|int|string - */ - public function getBinaryData(string $Key) - { - return $this->BinaryData[$Key]; - } - - - /** - * @param string $Key - * @param bool|int|DateTime|string $Value - * @return Pairtwo6 - */ - public function setBinaryData(string $Key, $Value): Pairtwo6 - { - $this->BinaryData[$Key] = $Value; - return $this; - } -} diff --git a/src/Readers/Pairtwo6.php b/src/Readers/Pairtwo6.php index eedcefe..f79fd27 100644 --- a/src/Readers/Pairtwo6.php +++ b/src/Readers/Pairtwo6.php @@ -1,29 +1,16 @@ . + * Reads out Pairtwo-6 files * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. + * @author Jeroen De Meerleer + * @category Main + * @package Libpairtwo + * @copyright Copyright (c) 2018-2019 Jeroen De Meerleer */ + namespace JeroenED\Libpairtwo\Readers; use JeroenED\Libpairtwo\Enums\Tiebreak; @@ -37,16 +24,20 @@ use JeroenED\Libpairtwo\Player; use JeroenED\Libpairtwo\Round; use JeroenED\Libpairtwo\Pairing; use JeroenED\Libpairtwo\Interfaces\ReaderInterface; -use JeroenED\Libpairtwo\Readers\Models\Pairtwo6 as Pairtwo6Model; use JeroenED\Libpairtwo\Enums\TournamentSystem; use DateTime; /** - * This class reads a SWS file + * Reader Pairtwo6 * - * @author Jeroen De Meerleer + * Reads out Pairtwo-6 files + * + * @author Jeroen De Meerleer + * @category Main + * @package Libpairtwo + * @copyright Copyright (c) 2018-2019 Jeroen De Meerleer */ -class Pairtwo6 extends Pairtwo6Model implements ReaderInterface +class Pairtwo6 implements ReaderInterface { private const PT_DAYFACTOR = 32; private const PT_MONTHFACTOR = 16; @@ -54,11 +45,79 @@ class Pairtwo6 extends Pairtwo6Model implements ReaderInterface private const PT_PASTOFFSET = 117; private const CompatibleVersions = ['6.', '5.']; + /** @var string */ + private $Release; + + /** @var Tournament */ + private $Tournament; + + /** @var bool|DateTime|int|string[] */ + private $BinaryData; + + /** + * @return string + */ + public function getRelease(): string + { + return $this->Release; + } + + /** + * @param string $Release + * @return \JeroenED\Libpairtwo\Readers\Models\Pairtwo6 + */ + public function setRelease(string $Release): Pairtwo6 + { + $this->Release = $Release; + return $this; + } + + /** + * @return Tournament + */ + public function getTournament(): Tournament + { + return $this->Tournament; + } + + /** + * @param Tournament $Tournament + * @return Pairtwo6 + */ + public function setTournament(Tournament $Tournament): Pairtwo6 + { + $this->Tournament = $Tournament; + return $this; + } + + + /** + * @param string $Key + * @return bool|DateTime|int|string + */ + public function getBinaryData(string $Key) + { + return $this->BinaryData[$Key]; + } + + + /** + * @param string $Key + * @param bool|int|DateTime|string $Value + * @return Pairtwo6 + */ + public function setBinaryData(string $Key, $Value): Pairtwo6 + { + $this->BinaryData[$Key] = $Value; + return $this; + } + /** * Reads out $swsfile and returns a Pairtwo6 class object * * @param string $filename * @return Pairtwo6 + * @throws IncompatibleReaderException */ public function read($filename): ReaderInterface { @@ -507,7 +566,7 @@ class Pairtwo6 extends Pairtwo6Model implements ReaderInterface // Participants $length = 4; - $this->getTournament()->setBinaryData('Participants', $this->readData('Int', substr($swscontents, $offset, $length))); + $this->setBinaryData('Participants', $this->readData('Int', substr($swscontents, $offset, $length))); $offset += $length; // Fidehomol diff --git a/src/Round.php b/src/Round.php index f6a6b59..57bd521 100644 --- a/src/Round.php +++ b/src/Round.php @@ -1,42 +1,88 @@ + * @category Main + * @package Libpairtwo + * @copyright Copyright (c) 2018-2019 Jeroen De Meerleer */ namespace JeroenED\Libpairtwo; +use DateTime; use JeroenED\Libpairtwo\Enums\Result; -use JeroenED\Libpairtwo\Models\Round as RoundModel; use JeroenED\Libpairtwo\Game; use JeroenED\Libpairtwo\Pairing; -class Round extends RoundModel +/** + * Class Round + * + * Class for a round of the tournament + * + * @author Jeroen De Meerleer + * @category Main + * @package Libpairtwo + * @copyright Copyright (c) 2018-2019 Jeroen De Meerleer + */ +class Round { + /** + * Date of the round + * + * @var DateTime + */ + private $date; + + /** + * Array of all games + * + * @var Game[] + */ + private $games = []; + + /** + * Number of the round + * + * @var int + */ + private $roundNo; + + /** + * Array of all pairings for this round + * + * @var Pairing[] + */ + private $pairings = []; + /** * Adds a game to the round * * @param Game $game + * @return Round */ - public function addGame(Game $game) + public function addGame(Game $game): Round { $newarray = $this->getGames(); $newarray[] = $game; $this->setGames($newarray); + return $this; } /** * Adds a pairing to the round * * @param Pairing $pairing + * @return Round */ - public function addPairing(Pairing $pairing) + public function addPairing(Pairing $pairing): Round { $newarray = $this->getPairings(); $newarray[] = $pairing; $this->setPairings($newarray); + return $this; } @@ -74,4 +120,85 @@ class Round extends RoundModel } return $absentPairings; } + + /** + * Returns the date of the round + * + * @return DateTime + */ + public function getDate(): DateTime + { + return $this->date; + } + /** + * Sets the date of the round + * + * @param DateTime $date + * @return Round + */ + public function setDate(DateTime $date): Round + { + $this->date = $date; + return $this; + } + /** + * Returns an array of all games in the tournament + * + * @return Game[] + */ + public function getGames(): array + { + return $this->games; + } + /** + * Sets Round::games to $games + * + * @param Game[] $games + * @return Round + */ + public function setGames(array $games): Round + { + $this->games = $games; + return $this; + } + /** + * Returns the round number + * + * @return int + */ + public function getRoundNo(): int + { + return $this->roundNo; + } + /** + * Sets the round number + * + * @param int $roundNo + * @return Round + */ + public function setRoundNo(int $roundNo): Round + { + $this->roundNo = $roundNo; + return $this; + } + /** + * Returns an array of all pairings for this round + * + * @return Pairing[] + */ + public function getPairings(): array + { + return $this->pairings; + } + /** + * Sets Round::Pairings to $pairings + * + * @param Pairing[] $pairings + * @return Round + */ + public function setPairings(array $pairings): Round + { + $this->pairings = $pairings; + return $this; + } } diff --git a/src/Tiebreaks.php b/src/Tiebreaks.php deleted file mode 100644 index 1157cc7..0000000 --- a/src/Tiebreaks.php +++ /dev/null @@ -1,325 +0,0 @@ -getBinaryData('ScoreAmerican'); - } - - - /** - * @param Player $player - * @return float|null - */ - protected function calculateAmerican(Player $player): ?float - { - return $player->getBinaryData('ScoreAmerican'); - } - - - /** - * @param Player $player - * @return float|null - */ - protected function calculatePoints(Player $player): ?float - { - return $player->getPoints(); - } - - - /** - * @param Player $player - * @return float|null - */ - protected function calculateBaumbach(Player $player): ?float - { - $totalwins = 0; - foreach ($player->getPairings() as $pairing) { - if (array_search($pairing->getResult(), Constants::Won) !== false) { - $totalwins++; - } - } - return $totalwins; - } - - - /** - * @param Player $player - * @return float|null - */ - protected function calculateBlackPlayed(Player $player): ?float - { - $totalwins = 0; - foreach ($player->getPairings() as $pairing) { - if (array_search($pairing->getColor(), Constants::Black) !== false) { - $totalwins++; - } - } - return $totalwins; - } - - /** - * @param Player $player - * @return float|null - */ - protected function calculateBlackWin(Player $player): ?float - { - $totalwins = 0; - foreach ($player->getPairings() as $pairing) { - if (array_search($pairing->getColor(), Constants::Black) !== false && array_search($pairing->getResult(), Constants::Won) !== false) { - $totalwins++; - } - } - return $totalwins; - } - - - /** - * @param Player $player - * @param array $opponents - * @param int $key - * @return float|null - */ - protected function calculateMutualResult(Player $player, array $opponents, int $key): ?float - { - $interestingplayers = $opponents; - if ($key != 0) { - $interestingplayers = []; - $playerstiebreaks = $player->getTiebreaks(); - array_splice($playerstiebreaks, $key); - foreach ($opponents as $opponent) { - $opponenttiebreaks = $opponent->getTiebreaks(); - array_splice($opponenttiebreaks, $key); - if (($playerstiebreaks == $opponenttiebreaks) && ($player != $opponent)) { - $interestingplayers[] = $opponent; - } - } - } - $points = 0; - $totalmatches = 0; - foreach ($player->getPairings() as $pairing) { - if (array_search($pairing->getOpponent(), $interestingplayers) !== false) { - if (array_search($pairing->getResult(), Constants::Won) !== false) { - $points = $points + 1; - } elseif (array_search($pairing->getResult(), Constants::Draw) !== false) { - $points = $points + 0.5; - } - $totalmatches++; - } - } - if ($totalmatches != count($interestingplayers)) { - $points = null; - } - return $points; - } - - - /** - * @param Player $player - * @param int $cut - * @return float - */ - protected function calculateAverageRating(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()->getElo($type); - if ($toadd != 0) { - $allratings[] = $toadd; - } - } - } - sort($allratings); - $allratings = array_slice($allratings, $cut); - return round(array_sum($allratings) / count($allratings)); - } - - - /** - * @param Player $player - * @param int $cut - * @return float|null - */ - 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($type, $this->getNonRatedElo()); - if ($toadd != 0) { - $allratings[] = $toadd; - } - } - } - sort($allratings); - $allratings = array_slice($allratings, $cut); - return round(array_sum($allratings) / count($allratings)); - } - - - /** - * @param Player $player - * @param int $cut - * @return float|null - */ - protected function calculateKoya(Player $player, int $cut = 50): ?float - { - $tiebreak = 0; - foreach ($player->getPairings() as $plkey => $plpairing) { - if (($plpairing->getOpponent()->getPoints() / count($plpairing->getOpponent()->getPairings()) * 100) >= $cut) { - if (array_search($plpairing->getResult(), Constants::Won) !== false) { - $tiebreak += 1; - } elseif (array_search($plpairing->getResult(), Constants::Draw) !== false) { - $tiebreak += 0.5; - } - } - } - return $tiebreak; - } - - - /** - * @param Player $player - * @param int $cutlowest - * @param int $cuthighest - * @return float|null - */ - protected function calculateBuchholz(Player $player, int $cutlowest = 0, int $cuthighest = 0): ?float - { - $tiebreak = 0; - $intpairings = $player->getPairings(); - - usort($intpairings, function ($a, $b) { - if (is_null($a->getOpponent())) { - return -1; - } - if (is_null($b->getOpponent())) { - return 1; - } - - if ($b->getOpponent()->getPoints() == $a->getOpponent()->getPoints()) { - return 0; - } - return ($a->getOpponent()->getPoints() > $b->getOpponent()->getPoints()) ? 1 : -1; - }); - - $intpairings = array_slice($intpairings, $cutlowest); - $intpairings = array_slice($intpairings, 0 - $cuthighest); - - foreach ($intpairings as $intkey => $intpairing) { - if (!is_null($intpairing->getOpponent())) { - $tiebreak += $intpairing->getOpponent()->getPoints(); - } - } - return $tiebreak; - } - - - /** - * @param Player $player - * @return float|null - */ - protected function calculateSonneborn(Player $player): ?float - { - $tiebreak = 0; - foreach ($player->getPairings() as $key => $pairing) { - if ($pairing->getOpponent()) { - if (array_search($pairing->getResult(), Constants::Won) !== false) { - $tiebreak += $pairing->getOpponent()->getPoints(); - } elseif (array_search($pairing->getResult(), Constants::Draw) !== false) { - $tiebreak += $pairing->getOpponent()->getPoints() / 2; - } - } - } - return $tiebreak; - } - - - /** - * @param Player $player - * @return float|null - */ - protected function calculateSoccerKashdan(Player $player): ?float - { - $tiebreak = 0; - foreach ($player->getPairings() as $pairing) { - $toadd = 0; - if (array_search($pairing->getResult(), Constants::Won) !== false) { - $toadd = 3; - } elseif (array_search($pairing->getResult(), Constants::Draw) !== false) { - $toadd = 1; - } elseif (array_search($pairing->getResult(), Constants::Lost) !== false) { - $toadd = 0; - } - - if (array_search($pairing->getResult(), Constants::NotPlayed) !== false) { - $toadd = -1; - } - $tiebreak += $toadd; - } - return $tiebreak; // - $player->getNoOfWins(); - } - - - /** - * @param Player $player - * @return float|null - */ - protected function calculateKashdan(Player $player): ?float - { - $tiebreak = 0; - foreach ($player->getPairings() as $pairing) { - $toadd = 0; - if (array_search($pairing->getResult(), Constants::Won) !== false) { - $toadd = 4; - } elseif (array_search($pairing->getResult(), Constants::Draw) !== false) { - $toadd = 2; - } elseif (array_search($pairing->getResult(), Constants::Lost) !== false) { - $toadd = 1; - } - - if (array_search($pairing->getResult(), Constants::NotPlayed) !== false) { - $toadd = 0; - } - $tiebreak += $toadd; - } - return $tiebreak; // - $player->getNoOfWins(); - } - - /** - * @param Player $player - * @return float|null - */ - protected function calculateCumulative(Player $player): ?float - { - $tiebreak = 0; - $score = []; - foreach ($player->getPairings() as $pairing) { - $toadd = 0; - if (array_search($pairing->getResult(), Constants::Won) !== false) { - $toadd = 1; - } elseif (array_search($pairing->getResult(), Constants::Draw) !== false) { - $toadd = 0.5; - } - $tiebreak += $toadd; - $score[] = $tiebreak; - } - return array_sum($score); - } -} diff --git a/src/Tournament.php b/src/Tournament.php index db508aa..e7322fe 100644 --- a/src/Tournament.php +++ b/src/Tournament.php @@ -1,18 +1,106 @@ + * @category Main + * @package Libpairtwo + * @copyright Copyright (c) 2018-2019 Jeroen De Meerleer */ namespace JeroenED\Libpairtwo; +use DateTime; use JeroenED\Libpairtwo\Enums\Tiebreak; use JeroenED\Libpairtwo\Enums\Color; +use JeroenED\Libpairtwo\Enums\TournamentSystem; -class Tournament extends Tiebreaks +/** + * Class Tournament + * + * Class for the tournament from the pairing file + * + * @author Jeroen De Meerleer + * @category Main + * @package Libpairtwo + * @copyright Copyright (c) 2018-2019 Jeroen De Meerleer + */ +class Tournament { + /** @var string */ + private $Name; + + /** @var string */ + private $Organiser; + + /** @var int */ + private $OrganiserClubNo; + + /** @var string */ + private $OrganiserClub; + + /** @var string */ + private $OrganiserPlace; + + /** @var string */ + private $OrganiserCountry; + + /** @var int */ + private $FideHomol; + + /** @var DateTime */ + private $StartDate; + + /** @var DateTime */ + private $EndDate; + + /** @var string */ + private $Arbiter; + + /** @var int */ + private $NoOfRounds; + + /** @var Round[] */ + private $Rounds = []; + + /** @var string */ + private $Tempo; + + /** @var int */ + private $NonRatedElo; + + /** @var TournamentSystem */ + private $System; + + /** @var string */ + private $FirstPeriod; + + /** @var string */ + private $SecondPeriod; + + /** @var string */ + private $Federation; + + /** @var Player[] */ + private $Players = []; + + /** @var int */ + private $Year; + + /** @var Pairing[] */ + private $Pairings = []; + + /** @var Tiebreak[] */ + private $Tiebreaks = []; + + /** @var string */ + private $PriorityElo = 'Fide'; + + /** @var string */ + private $PriorityId = 'Nation'; + /** * Gets a player by its ID * @@ -357,7 +445,751 @@ class Tournament extends Tiebreaks * * @return int */ - public function getParticipants(): int { + public function getParticipants(): int + { return count($this->getPlayers()); } + + /** + * @param Player $player + * @return float|null + */ + private function calculateKeizer(Player $player): ?float + { + return $player->getBinaryData('ScoreAmerican'); + } + + + /** + * @param Player $player + * @return float|null + */ + private function calculateAmerican(Player $player): ?float + { + return $player->getBinaryData('ScoreAmerican'); + } + + + /** + * @param Player $player + * @return float|null + */ + private function calculatePoints(Player $player): ?float + { + return $player->getPoints(); + } + + + /** + * @param Player $player + * @return float|null + */ + private function calculateBaumbach(Player $player): ?float + { + $totalwins = 0; + foreach ($player->getPairings() as $pairing) { + if (array_search($pairing->getResult(), Constants::Won) !== false) { + $totalwins++; + } + } + return $totalwins; + } + + + /** + * @param Player $player + * @return float|null + */ + private function calculateBlackPlayed(Player $player): ?float + { + $totalwins = 0; + foreach ($player->getPairings() as $pairing) { + if (array_search($pairing->getColor(), Constants::Black) !== false) { + $totalwins++; + } + } + return $totalwins; + } + + /** + * @param Player $player + * @return float|null + */ + private function calculateBlackWin(Player $player): ?float + { + $totalwins = 0; + foreach ($player->getPairings() as $pairing) { + if (array_search($pairing->getColor(), Constants::Black) !== false && array_search($pairing->getResult(), Constants::Won) !== false) { + $totalwins++; + } + } + return $totalwins; + } + + + /** + * @param Player $player + * @param array $opponents + * @param int $key + * @return float|null + */ + private function calculateMutualResult(Player $player, array $opponents, int $key): ?float + { + $interestingplayers = $opponents; + if ($key != 0) { + $interestingplayers = []; + $playerstiebreaks = $player->getTiebreaks(); + array_splice($playerstiebreaks, $key); + foreach ($opponents as $opponent) { + $opponenttiebreaks = $opponent->getTiebreaks(); + array_splice($opponenttiebreaks, $key); + if (($playerstiebreaks == $opponenttiebreaks) && ($player != $opponent)) { + $interestingplayers[] = $opponent; + } + } + } + $points = 0; + $totalmatches = 0; + foreach ($player->getPairings() as $pairing) { + if (array_search($pairing->getOpponent(), $interestingplayers) !== false) { + if (array_search($pairing->getResult(), Constants::Won) !== false) { + $points = $points + 1; + } elseif (array_search($pairing->getResult(), Constants::Draw) !== false) { + $points = $points + 0.5; + } + $totalmatches++; + } + } + if ($totalmatches != count($interestingplayers)) { + $points = null; + } + return $points; + } + + + /** + * @param Player $player + * @param int $cut + * @return float + */ + private function calculateAverageRating(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()->getElo($type); + if ($toadd != 0) { + $allratings[] = $toadd; + } + } + } + sort($allratings); + $allratings = array_slice($allratings, $cut); + return round(array_sum($allratings) / count($allratings)); + } + + + /** + * @param Player $player + * @param int $cut + * @return float|null + */ + private 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($type, $this->getNonRatedElo()); + if ($toadd != 0) { + $allratings[] = $toadd; + } + } + } + sort($allratings); + $allratings = array_slice($allratings, $cut); + return round(array_sum($allratings) / count($allratings)); + } + + + /** + * @param Player $player + * @param int $cut + * @return float|null + */ + private function calculateKoya(Player $player, int $cut = 50): ?float + { + $tiebreak = 0; + foreach ($player->getPairings() as $plkey => $plpairing) { + if (($plpairing->getOpponent()->getPoints() / count($plpairing->getOpponent()->getPairings()) * 100) >= $cut) { + if (array_search($plpairing->getResult(), Constants::Won) !== false) { + $tiebreak += 1; + } elseif (array_search($plpairing->getResult(), Constants::Draw) !== false) { + $tiebreak += 0.5; + } + } + } + return $tiebreak; + } + + + /** + * @param Player $player + * @param int $cutlowest + * @param int $cuthighest + * @return float|null + */ + private function calculateBuchholz(Player $player, int $cutlowest = 0, int $cuthighest = 0): ?float + { + $tiebreak = 0; + $intpairings = $player->getPairings(); + + usort($intpairings, function ($a, $b) { + if (is_null($a->getOpponent())) { + return -1; + } + if (is_null($b->getOpponent())) { + return 1; + } + + if ($b->getOpponent()->getPoints() == $a->getOpponent()->getPoints()) { + return 0; + } + return ($a->getOpponent()->getPoints() > $b->getOpponent()->getPoints()) ? 1 : -1; + }); + + $intpairings = array_slice($intpairings, $cutlowest); + $intpairings = array_slice($intpairings, 0 - $cuthighest); + + foreach ($intpairings as $intkey => $intpairing) { + if (!is_null($intpairing->getOpponent())) { + $tiebreak += $intpairing->getOpponent()->getPoints(); + } + } + return $tiebreak; + } + + + /** + * @param Player $player + * @return float|null + */ + private function calculateSonneborn(Player $player): ?float + { + $tiebreak = 0; + foreach ($player->getPairings() as $key => $pairing) { + if ($pairing->getOpponent()) { + if (array_search($pairing->getResult(), Constants::Won) !== false) { + $tiebreak += $pairing->getOpponent()->getPoints(); + } elseif (array_search($pairing->getResult(), Constants::Draw) !== false) { + $tiebreak += $pairing->getOpponent()->getPoints() / 2; + } + } + } + return $tiebreak; + } + + + /** + * @param Player $player + * @return float|null + */ + private function calculateSoccerKashdan(Player $player): ?float + { + $tiebreak = 0; + foreach ($player->getPairings() as $pairing) { + $toadd = 0; + if (array_search($pairing->getResult(), Constants::Won) !== false) { + $toadd = 3; + } elseif (array_search($pairing->getResult(), Constants::Draw) !== false) { + $toadd = 1; + } elseif (array_search($pairing->getResult(), Constants::Lost) !== false) { + $toadd = 0; + } + + if (array_search($pairing->getResult(), Constants::NotPlayed) !== false) { + $toadd = -1; + } + $tiebreak += $toadd; + } + return $tiebreak; // - $player->getNoOfWins(); + } + + /** + * @param Player $player + * @return float|null + */ + private function calculateKashdan(Player $player): ?float + { + $tiebreak = 0; + foreach ($player->getPairings() as $pairing) { + $toadd = 0; + if (array_search($pairing->getResult(), Constants::Won) !== false) { + $toadd = 4; + } elseif (array_search($pairing->getResult(), Constants::Draw) !== false) { + $toadd = 2; + } elseif (array_search($pairing->getResult(), Constants::Lost) !== false) { + $toadd = 1; + } + + if (array_search($pairing->getResult(), Constants::NotPlayed) !== false) { + $toadd = 0; + } + $tiebreak += $toadd; + } + return $tiebreak; // - $player->getNoOfWins(); + } + + /** + * @param Player $player + * @return float|null + */ + private function calculateCumulative(Player $player): ?float + { + $tiebreak = 0; + $score = []; + foreach ($player->getPairings() as $pairing) { + $toadd = 0; + if (array_search($pairing->getResult(), Constants::Won) !== false) { + $toadd = 1; + } elseif (array_search($pairing->getResult(), Constants::Draw) !== false) { + $toadd = 0.5; + } + $tiebreak += $toadd; + $score[] = $tiebreak; + } + return array_sum($score); + } + + /** + * @return string + */ + public function getName(): string + { + return $this->Name; + } + + /** + * @param string $Name + * @return \JeroenED\Libpairtwo\Models\Tournament + */ + public function setName(string $Name): Tournament + { + $this->Name = $Name; + return $this; + } + + /** + * @return string + */ + public function getOrganiser(): string + { + return $this->Organiser; + } + + /** + * @param string $Organiser + * @return Tournament + */ + public function setOrganiser(string $Organiser): Tournament + { + $this->Organiser = $Organiser; + return $this; + } + + /** + * @return int + */ + public function getOrganiserClubNo(): int + { + return $this->OrganiserClubNo; + } + + /** + * @param int $OrganiserClubNo + * @return Tournament + */ + public function setOrganiserClubNo(int $OrganiserClubNo): Tournament + { + $this->OrganiserClubNo = $OrganiserClubNo; + return $this; + } + + /** + * @return string + */ + public function getOrganiserClub(): string + { + return $this->OrganiserClub; + } + + /** + * @param string $OrganiserClub + * @return Tournament + */ + public function setOrganiserClub(string $OrganiserClub): Tournament + { + $this->OrganiserClub = $OrganiserClub; + return $this; + } + + /** + * @return string + */ + public function getOrganiserPlace(): string + { + return $this->OrganiserPlace; + } + + /** + * @param string $OrganiserPlace + * @return Tournament + */ + public function setOrganiserPlace(string $OrganiserPlace): Tournament + { + $this->OrganiserPlace = $OrganiserPlace; + return $this; + } + + /** + * @return string + */ + public function getOrganiserCountry(): string + { + return $this->OrganiserCountry; + } + + /** + * @param string $OrganiserCountry + * @return Tournament + */ + public function setOrganiserCountry(string $OrganiserCountry): Tournament + { + $this->OrganiserCountry = $OrganiserCountry; + return $this; + } + + /** + * @return int + */ + public function getFideHomol(): int + { + return $this->FideHomol; + } + + /** + * @param int $FideHomol + * @return Tournament + */ + public function setFideHomol(int $FideHomol): Tournament + { + $this->FideHomol = $FideHomol; + return $this; + } + + /** + * @return DateTime + */ + public function getStartDate(): DateTime + { + return $this->StartDate; + } + + /** + * @param DateTime $StartDate + * @return Tournament + */ + public function setStartDate(DateTime $StartDate): Tournament + { + $this->StartDate = $StartDate; + return $this; + } + + /** + * @return DateTime + */ + public function getEndDate(): DateTime + { + return $this->EndDate; + } + + /** + * @param DateTime $EndDate + * @return Tournament + */ + public function setEndDate(DateTime $EndDate): Tournament + { + $this->EndDate = $EndDate; + return $this; + } + + /** + * @return string + */ + public function getArbiter(): string + { + return $this->Arbiter; + } + + /** + * @param string $Arbiter + * @return Tournament + */ + public function setArbiter(string $Arbiter): Tournament + { + $this->Arbiter = $Arbiter; + return $this; + } + + /** + * @return int + */ + public function getNoOfRounds(): int + { + return $this->NoOfRounds; + } + + /** + * @param int $NoOfRounds + * @return Tournament + */ + public function setNoOfRounds(int $NoOfRounds): Tournament + { + $this->NoOfRounds = $NoOfRounds; + return $this; + } + + /** + * @return Round[] + */ + public function getRounds(): array + { + return $this->Rounds; + } + + /** + * @param Round[] $Rounds + * @return Tournament + */ + public function setRounds(array $Rounds): Tournament + { + $this->Rounds = $Rounds; + return $this; + } + + /** + * @return string + */ + public function getTempo(): string + { + return $this->Tempo; + } + + /** + * @param string $Tempo + * @return Tournament + */ + public function setTempo(string $Tempo): Tournament + { + $this->Tempo = $Tempo; + return $this; + } + + /** + * @return int + */ + public function getNonRatedElo(): int + { + return $this->NonRatedElo; + } + + /** + * @param int $NonRatedElo + * @return Tournament + */ + public function setNonRatedElo(int $NonRatedElo): Tournament + { + $this->NonRatedElo = $NonRatedElo; + return $this; + } + + /** + * @return TournamentSystem + */ + public function getSystem(): TournamentSystem + { + return $this->System; + } + + /** + * @param TournamentSystem $System + * @return Tournament + */ + public function setSystem(TournamentSystem $System): Tournament + { + $this->System = $System; + return $this; + } + + /** + * @return string + */ + public function getFirstPeriod(): string + { + return $this->FirstPeriod; + } + + /** + * @param string $FirstPeriod + * @return Tournament + */ + public function setFirstPeriod(string $FirstPeriod): Tournament + { + $this->FirstPeriod = $FirstPeriod; + return $this; + } + + /** + * @return string + */ + public function getSecondPeriod(): string + { + return $this->SecondPeriod; + } + + /** + * @param string $SecondPeriod + * @return Tournament + */ + public function setSecondPeriod(string $SecondPeriod): Tournament + { + $this->SecondPeriod = $SecondPeriod; + return $this; + } + + /** + * @return string + */ + public function getFederation(): string + { + return $this->Federation; + } + + /** + * @param string $Federation + * @return Tournament + */ + public function setFederation(string $Federation): Tournament + { + $this->Federation = $Federation; + return $this; + } + + /** + * @return Player[] + */ + public function getPlayers(): array + { + return $this->Players; + } + + /** + * @param Player[] $Players + * @return Tournament + */ + public function setPlayers(array $Players): Tournament + { + $this->Players = $Players; + return $this; + } + + /** + * @return int + */ + public function getYear(): int + { + return $this->Year; + } + + /** + * @param int $Year + * @return Tournament + */ + public function setYear(int $Year): Tournament + { + $this->Year = $Year; + return $this; + } + + /** + * @return Pairing[] + */ + public function getPairings(): array + { + return $this->Pairings; + } + + /** + * @param Pairing[] $Pairings + * @return Tournament + */ + public function setPairings(array $Pairings): Tournament + { + $this->Pairings = $Pairings; + return $this; + } + + /** + * @return Tiebreak[] + */ + public function getTiebreaks(): array + { + return $this->Tiebreaks; + } + + /** + * @param Tiebreak[] $Tiebreaks + * @return Tournament + */ + public function setTiebreaks(array $Tiebreaks): Tournament + { + $this->Tiebreaks = $Tiebreaks; + return $this; + } + + /** + * @return string + */ + public function getPriorityElo(): string + { + return $this->PriorityElo; + } + + /** + * @param string $PriorityElo + * @return Tournament + */ + public function setPriorityElo(string $PriorityElo): Tournament + { + $this->PriorityElo = $PriorityElo; + return $this; + } + /** + * @return string + */ + public function getPriorityId(): string + { + return $this->PriorityId; + } + + /** + * @param string $PriorityId + * @return Tournament + */ + public function setPriorityId(string $PriorityId): Tournament + { + $this->PriorityId = $PriorityId; + return $this; + } }