mirror of
https://github.com/JeroenED/libpairtwo.git
synced 2024-11-22 06:26:57 +01:00
Merge branch 'task/tie-breaks' into develop
This commit is contained in:
commit
e3175568a4
27
src/Enums/Tiebreak.php
Normal file
27
src/Enums/Tiebreak.php
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace JeroenED\Libpairtwo\Enums;
|
||||||
|
|
||||||
|
use MyCLabs\Enum\Enum;
|
||||||
|
|
||||||
|
class Tiebreak extends Enum
|
||||||
|
{
|
||||||
|
const None = "";
|
||||||
|
const Buchholz = "Buchholz";
|
||||||
|
const BuchholzMed = "Buchholz Median";
|
||||||
|
const BuchholzCut = "Buchholz Cut";
|
||||||
|
const Sonneborn = "Sonneborn-Berger";
|
||||||
|
const Kashdan = "Kashdan";
|
||||||
|
const Cumulative = "Cumulative";
|
||||||
|
const Between = "Mutual Result";
|
||||||
|
const Koya = "Koya";
|
||||||
|
const Baumbach = "Baumbach";
|
||||||
|
const Performance = "Performance";
|
||||||
|
const Aro = "Average Rating";
|
||||||
|
const AroCut = "Average Rating Cut";
|
||||||
|
const BlackPlayed = "Black played";
|
||||||
|
const BlackWin = "Black Winned";
|
||||||
|
const Testmatch = "Testmatch";
|
||||||
|
const Drawing = "Drawing of lot";
|
||||||
|
}
|
@ -3,8 +3,6 @@
|
|||||||
|
|
||||||
namespace JeroenED\Libpairtwo\Exceptions;
|
namespace JeroenED\Libpairtwo\Exceptions;
|
||||||
|
|
||||||
|
class IncompatibleReaderException extends LibpairtwoException
|
||||||
class IncompatibleReaderException Extends LibpairtwoException
|
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
@ -3,8 +3,6 @@
|
|||||||
|
|
||||||
namespace JeroenED\LibPairtwo\Exceptions;
|
namespace JeroenED\LibPairtwo\Exceptions;
|
||||||
|
|
||||||
|
|
||||||
class LibpairtwoException extends \Exception
|
class LibpairtwoException extends \Exception
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
namespace JeroenED\Libpairtwo\Models;
|
namespace JeroenED\Libpairtwo\Models;
|
||||||
|
|
||||||
|
use JeroenED\Libpairtwo\Enums\Tiebreak;
|
||||||
use JeroenED\Libpairtwo\Enums\TournamentSystem;
|
use JeroenED\Libpairtwo\Enums\TournamentSystem;
|
||||||
use JeroenED\Libpairtwo\Player;
|
use JeroenED\Libpairtwo\Player;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
@ -103,6 +104,9 @@ abstract class Tournament
|
|||||||
/** @var Pairing[] */
|
/** @var Pairing[] */
|
||||||
private $Pairings;
|
private $Pairings;
|
||||||
|
|
||||||
|
/** @var Tiebreak[] */
|
||||||
|
private $Tiebreaks = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
@ -454,4 +458,20 @@ abstract class Tournament
|
|||||||
{
|
{
|
||||||
$this->Pairings = $Pairings;
|
$this->Pairings = $Pairings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Tiebreak[]
|
||||||
|
*/
|
||||||
|
public function getTiebreaks(): array
|
||||||
|
{
|
||||||
|
return $this->Tiebreaks;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Tiebreak[] $Tiebreaks
|
||||||
|
*/
|
||||||
|
public function setTiebreaks(array $Tiebreaks): void
|
||||||
|
{
|
||||||
|
$this->Tiebreaks = $Tiebreaks;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
namespace JeroenED\Libpairtwo\Readers;
|
namespace JeroenED\Libpairtwo\Readers;
|
||||||
|
|
||||||
|
use JeroenED\Libpairtwo\Enums\Tiebreak;
|
||||||
use JeroenED\Libpairtwo\Enums\Title;
|
use JeroenED\Libpairtwo\Enums\Title;
|
||||||
use JeroenED\Libpairtwo\Enums\Gender;
|
use JeroenED\Libpairtwo\Enums\Gender;
|
||||||
use JeroenED\Libpairtwo\Enums\Color;
|
use JeroenED\Libpairtwo\Enums\Color;
|
||||||
@ -218,9 +219,62 @@ class Pairtwo6 extends Pairtwo6Model implements ReaderInterface
|
|||||||
$offset += $length;
|
$offset += $length;
|
||||||
|
|
||||||
// TieOrder
|
// TieOrder
|
||||||
$length = 4 * 5;
|
for ($i = 0; $i < 5; $i++) {
|
||||||
$this->setBinaryData("TieOrder", $this->readData('Int', substr($swscontents, $offset, $length)));
|
$length = 4;
|
||||||
|
switch ($this->readData('Int', substr($swscontents, $offset, $length))) {
|
||||||
|
case 1:
|
||||||
|
$tiebreak = Tiebreak::Buchholz;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
$tiebreak = Tiebreak::BuchholzMed;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
$tiebreak = Tiebreak::BuchholzMed;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
$tiebreak = Tiebreak::Sonneborn;
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
$tiebreak = Tiebreak::Kashdan;
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
$tiebreak = Tiebreak::Cumulative;
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
$tiebreak = Tiebreak::Between;
|
||||||
|
break;
|
||||||
|
case 8:
|
||||||
|
$tiebreak = Tiebreak::Koya;
|
||||||
|
break;
|
||||||
|
case 9:
|
||||||
|
$tiebreak = Tiebreak::Baumbach;
|
||||||
|
break;
|
||||||
|
case 10:
|
||||||
|
$tiebreak = Tiebreak::Performance;
|
||||||
|
break;
|
||||||
|
case 11:
|
||||||
|
$tiebreak = Tiebreak::Aro;
|
||||||
|
break;
|
||||||
|
case 12:
|
||||||
|
$tiebreak = Tiebreak::AroCut;
|
||||||
|
break;
|
||||||
|
case 13:
|
||||||
|
$tiebreak = Tiebreak::BlackPlayed;
|
||||||
|
break;
|
||||||
|
case 14:
|
||||||
|
$tiebreak = Tiebreak::Testmatch;
|
||||||
|
break;
|
||||||
|
case 15:
|
||||||
|
$tiebreak = Tiebreak::Drawing;
|
||||||
|
break;
|
||||||
|
case 0:
|
||||||
|
default:
|
||||||
|
$tiebreak = Tiebreak::None;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$this->getTournament()->addTieBreak(new Tiebreak($tiebreak));
|
||||||
$offset += $length;
|
$offset += $length;
|
||||||
|
}
|
||||||
|
|
||||||
// Categorie
|
// Categorie
|
||||||
$length = 4 * 10;
|
$length = 4 * 10;
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
namespace JeroenED\Libpairtwo;
|
namespace JeroenED\Libpairtwo;
|
||||||
|
|
||||||
|
use JeroenED\LibPairtwo\Exceptions\LibpairtwoException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class reads a SWS file
|
* This class reads a SWS file
|
||||||
@ -41,6 +41,7 @@ class Sws
|
|||||||
* Reads out $swsfile and returns a Pairtwo6 class object
|
* Reads out $swsfile and returns a Pairtwo6 class object
|
||||||
*
|
*
|
||||||
* @param string $swsfile
|
* @param string $swsfile
|
||||||
|
* @throws LibpairtwoException
|
||||||
* @deprecated
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
public static function ReadSws(string $swsfile)
|
public static function ReadSws(string $swsfile)
|
||||||
@ -49,5 +50,4 @@ class Sws
|
|||||||
$reader = IOFactory::createReader("Pairtwo-6");
|
$reader = IOFactory::createReader("Pairtwo-6");
|
||||||
return $reader->read($swsfile);
|
return $reader->read($swsfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
namespace JeroenED\Libpairtwo;
|
namespace JeroenED\Libpairtwo;
|
||||||
|
|
||||||
|
use JeroenED\Libpairtwo\Enums\Tiebreak;
|
||||||
use JeroenED\Libpairtwo\Models\Tournament as TournamentModel;
|
use JeroenED\Libpairtwo\Models\Tournament as TournamentModel;
|
||||||
use JeroenED\Libpairtwo\Enums\Color;
|
use JeroenED\Libpairtwo\Enums\Color;
|
||||||
|
|
||||||
@ -49,6 +50,18 @@ class Tournament extends TournamentModel
|
|||||||
$this->setPlayers($newArray);
|
$this->setPlayers($newArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a Tiebreak
|
||||||
|
*
|
||||||
|
* @param Tiebreak $tiebreak
|
||||||
|
*/
|
||||||
|
public function addTiebreak(Tiebreak $tiebreak)
|
||||||
|
{
|
||||||
|
$newArray = $this->getTiebreaks();
|
||||||
|
$newArray[] = $tiebreak;
|
||||||
|
$this->setTiebreaks($newArray);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a round with given Round object
|
* Adds a round with given Round object
|
||||||
*
|
*
|
||||||
|
@ -70,3 +70,6 @@ echo "Color Pairing 3: " . $sws->getTournament()->getPairings()[3]->getColor()->
|
|||||||
echo "Player Pairing 1: " . $sws->getTournament()->getPairings()[0]->getPlayer()->getName() . PHP_EOL;
|
echo "Player Pairing 1: " . $sws->getTournament()->getPairings()[0]->getPlayer()->getName() . PHP_EOL;
|
||||||
echo "Player Pairing 2: " . $sws->getTournament()->getPairings()[1]->getPlayer()->getName() . PHP_EOL;
|
echo "Player Pairing 2: " . $sws->getTournament()->getPairings()[1]->getPlayer()->getName() . PHP_EOL;
|
||||||
echo "Player Pairing 3: " . $sws->getTournament()->getPairings()[2]->getPlayer()->getName() . PHP_EOL;
|
echo "Player Pairing 3: " . $sws->getTournament()->getPairings()[2]->getPlayer()->getName() . PHP_EOL;
|
||||||
|
echo "Tiebreak 1: " . $sws->getTournament()->getTiebreaks()[0]->getValue() . PHP_EOL;
|
||||||
|
echo "Tiebreak 2: " . $sws->getTournament()->getTiebreaks()[1]->getValue() . PHP_EOL;
|
||||||
|
echo "Tiebreak 3: " . $sws->getTournament()->getTiebreaks()[2]->getValue() . PHP_EOL;
|
||||||
|
Loading…
Reference in New Issue
Block a user