mirror of
https://github.com/JeroenED/libpairtwo.git
synced 2024-11-22 06:26:57 +01:00
Merge branch 'task/generalization-2' into develop
This commit is contained in:
commit
ce1c0abe52
@ -8,6 +8,9 @@ use MyCLabs\Enum\Enum;
|
|||||||
class Tiebreak extends Enum
|
class Tiebreak extends Enum
|
||||||
{
|
{
|
||||||
const None = "";
|
const None = "";
|
||||||
|
const Keizer = "Keizer";
|
||||||
|
const Points = "Points";
|
||||||
|
const American = "American";
|
||||||
const Buchholz = "Buchholz";
|
const Buchholz = "Buchholz";
|
||||||
const BuchholzMed = "Buchholz Median";
|
const BuchholzMed = "Buchholz Median";
|
||||||
const BuchholzCut = "Buchholz Cut";
|
const BuchholzCut = "Buchholz Cut";
|
||||||
@ -16,7 +19,7 @@ class Tiebreak extends Enum
|
|||||||
const Cumulative = "Cumulative";
|
const Cumulative = "Cumulative";
|
||||||
const Between = "Mutual Result";
|
const Between = "Mutual Result";
|
||||||
const Koya = "Koya";
|
const Koya = "Koya";
|
||||||
const Baumbach = "Baumbach";
|
const Baumbach = "Most wins"; // Ref: https://en.wikipedia.org/wiki/Tie-breaking_in_Swiss-system_tournaments#Most_wins_(Baumbach) Please tell me why?
|
||||||
const Performance = "Performance";
|
const Performance = "Performance";
|
||||||
const Aro = "Average Rating";
|
const Aro = "Average Rating";
|
||||||
const AroCut = "Average Rating Cut";
|
const AroCut = "Average Rating Cut";
|
||||||
|
@ -15,5 +15,5 @@ class TournamentSystem extends Enum
|
|||||||
const Swiss = 'Swiss';
|
const Swiss = 'Swiss';
|
||||||
const Closed = 'Closed';
|
const Closed = 'Closed';
|
||||||
const American = 'American';
|
const American = 'American';
|
||||||
const Imperial = 'Imperial';
|
const Keizer = 'Keizer';
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,6 @@ use JeroenED\Libpairtwo\Tournament;
|
|||||||
|
|
||||||
interface ReaderInterface
|
interface ReaderInterface
|
||||||
{
|
{
|
||||||
public function read($filename);
|
public function read($filename): ReaderInterface;
|
||||||
public function getTournament(): Tournament;
|
public function getTournament(): Tournament;
|
||||||
}
|
}
|
||||||
|
@ -75,6 +75,4 @@ abstract class Game
|
|||||||
$this->result = $result;
|
$this->result = $result;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,42 +18,22 @@ abstract class Player
|
|||||||
/** @var string */
|
/** @var string */
|
||||||
private $Name;
|
private $Name;
|
||||||
|
|
||||||
/** @var int */
|
/** @var int[] */
|
||||||
private $Rank;
|
private $Ids;
|
||||||
|
|
||||||
/** @var int */
|
/** @var int[] */
|
||||||
private $FideId;
|
private $Elos;
|
||||||
|
|
||||||
/** @var int */
|
|
||||||
private $ExtraPts;
|
|
||||||
|
|
||||||
/** @var int */
|
|
||||||
private $KbsbElo;
|
|
||||||
|
|
||||||
/** @var DateTime */
|
/** @var DateTime */
|
||||||
private $dateofbirth;
|
private $DateOfBirth;
|
||||||
|
|
||||||
/** @var int */
|
/** @var float[] */
|
||||||
private $KbsbID;
|
private $Tiebreaks = [];
|
||||||
|
|
||||||
/** @var float */
|
|
||||||
private $Points;
|
|
||||||
|
|
||||||
/** @var int */
|
|
||||||
private $ClubNr;
|
|
||||||
|
|
||||||
/** @var float */
|
|
||||||
private $ScoreBucholtz;
|
|
||||||
|
|
||||||
/** @var float */
|
|
||||||
private $ScoreAmerican;
|
|
||||||
|
|
||||||
/** @var int */
|
|
||||||
private $FideElo;
|
|
||||||
|
|
||||||
/** @var string */
|
/** @var string */
|
||||||
private $Nation;
|
private $Nation;
|
||||||
|
|
||||||
|
// TODO: Implement categories
|
||||||
/** @var string */
|
/** @var string */
|
||||||
private $Category;
|
private $Category;
|
||||||
|
|
||||||
@ -63,15 +43,12 @@ abstract class Player
|
|||||||
/** @var Gender */
|
/** @var Gender */
|
||||||
private $Gender;
|
private $Gender;
|
||||||
|
|
||||||
/** @var int */
|
|
||||||
private $NumberOfTies;
|
|
||||||
|
|
||||||
/** @var bool */
|
|
||||||
private $Absent;
|
|
||||||
|
|
||||||
/** @var Pairing[] */
|
/** @var Pairing[] */
|
||||||
private $Pairings = [];
|
private $Pairings = [];
|
||||||
|
|
||||||
|
/** @var bool|DateTime|int|string[] */
|
||||||
|
private $BinaryData;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
@ -91,200 +68,74 @@ abstract class Player
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return int
|
* @return int[]
|
||||||
*/
|
*/
|
||||||
public function getRank(): int
|
public function getIds(): array
|
||||||
{
|
{
|
||||||
return $this->Rank;
|
return $this->Ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $Rank
|
* @param int[] $Ids
|
||||||
* @return Player
|
* @return Player
|
||||||
*/
|
*/
|
||||||
public function setRank(int $Rank): Player
|
public function setIds(array $Ids): Player
|
||||||
{
|
{
|
||||||
$this->Rank = $Rank;
|
$this->Ids = $Ids;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return int
|
* @return int[]
|
||||||
*/
|
*/
|
||||||
public function getFideId(): int
|
public function getElos(): array
|
||||||
{
|
{
|
||||||
return $this->FideId;
|
return $this->Elos;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $FideId
|
* @param int[] $Elos
|
||||||
* @return Player
|
* @return Player
|
||||||
*/
|
*/
|
||||||
public function setFideId(int $FideId): Player
|
public function setElos(array $Elos): Player
|
||||||
{
|
{
|
||||||
$this->FideId = $FideId;
|
$this->Elos = $Elos;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return int
|
* @return \DateTime
|
||||||
*/
|
*/
|
||||||
public function getExtraPts(): int
|
public function getDateOfBirth(): \DateTime
|
||||||
{
|
{
|
||||||
return $this->ExtraPts;
|
return $this->DateOfBirth;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $ExtraPts
|
* @param \DateTime $DateOfBirth
|
||||||
* @return Player
|
* @return Player
|
||||||
*/
|
*/
|
||||||
public function setExtraPts(int $ExtraPts): Player
|
public function setDateOfBirth(\DateTime $DateOfBirth): Player
|
||||||
{
|
{
|
||||||
$this->ExtraPts = $ExtraPts;
|
$this->DateOfBirth = $DateOfBirth;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return int
|
* @return float[]
|
||||||
*/
|
*/
|
||||||
public function getKbsbElo(): int
|
public function getTiebreaks(): array
|
||||||
{
|
{
|
||||||
return $this->KbsbElo;
|
return $this->Tiebreaks;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $KbsbElo
|
* @param float[] $Tiebreaks
|
||||||
* @return Player
|
* @return Player
|
||||||
*/
|
*/
|
||||||
public function setKbsbElo(int $KbsbElo): Player
|
public function setTiebreaks(array $Tiebreaks): Player
|
||||||
{
|
{
|
||||||
$this->KbsbElo = $KbsbElo;
|
$this->Tiebreaks = $Tiebreaks;
|
||||||
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 int
|
|
||||||
*/
|
|
||||||
public function getKbsbID(): int
|
|
||||||
{
|
|
||||||
return $this->KbsbID;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $KbsbID
|
|
||||||
* @return Player
|
|
||||||
*/
|
|
||||||
public function setKbsbID(int $KbsbID): Player
|
|
||||||
{
|
|
||||||
$this->KbsbID = $KbsbID;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return float
|
|
||||||
*/
|
|
||||||
public function getPoints(): float
|
|
||||||
{
|
|
||||||
return $this->Points;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param float $Points
|
|
||||||
* @return Player
|
|
||||||
*/
|
|
||||||
public function setPoints(float $Points): Player
|
|
||||||
{
|
|
||||||
$this->Points = $Points;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getClubNr(): int
|
|
||||||
{
|
|
||||||
return $this->ClubNr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $ClubNr
|
|
||||||
* @return Player
|
|
||||||
*/
|
|
||||||
public function setClubNr(int $ClubNr): Player
|
|
||||||
{
|
|
||||||
$this->ClubNr = $ClubNr;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return float
|
|
||||||
*/
|
|
||||||
public function getScoreBucholtz(): float
|
|
||||||
{
|
|
||||||
return $this->ScoreBucholtz;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param float $ScoreBucholtz
|
|
||||||
* @return Player
|
|
||||||
*/
|
|
||||||
public function setScoreBucholtz(float $ScoreBucholtz): Player
|
|
||||||
{
|
|
||||||
$this->ScoreBucholtz = $ScoreBucholtz;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return float
|
|
||||||
*/
|
|
||||||
public function getScoreAmerican(): float
|
|
||||||
{
|
|
||||||
return $this->ScoreAmerican;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param float $ScoreAmerican
|
|
||||||
* @return Player
|
|
||||||
*/
|
|
||||||
public function setScoreAmerican(float $ScoreAmerican): Player
|
|
||||||
{
|
|
||||||
$this->ScoreAmerican = $ScoreAmerican;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getFideElo(): int
|
|
||||||
{
|
|
||||||
return $this->FideElo;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $FideElo
|
|
||||||
* @return Player
|
|
||||||
*/
|
|
||||||
public function setFideElo(int $FideElo): Player
|
|
||||||
{
|
|
||||||
$this->FideElo = $FideElo;
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -364,42 +215,6 @@ abstract class Player
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getNumberOfTies(): int
|
|
||||||
{
|
|
||||||
return $this->NumberOfTies;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $NumberOfTies
|
|
||||||
* @return Player
|
|
||||||
*/
|
|
||||||
public function setNumberOfTies(int $NumberOfTies): Player
|
|
||||||
{
|
|
||||||
$this->NumberOfTies = $NumberOfTies;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function isAbsent(): bool
|
|
||||||
{
|
|
||||||
return $this->Absent;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param bool $Absent
|
|
||||||
* @return Player
|
|
||||||
*/
|
|
||||||
public function setAbsent(bool $Absent): Player
|
|
||||||
{
|
|
||||||
$this->Absent = $Absent;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Pairing[]
|
* @return Pairing[]
|
||||||
*/
|
*/
|
||||||
@ -417,4 +232,24 @@ abstract class Player
|
|||||||
$this->Pairings = $Pairings;
|
$this->Pairings = $Pairings;
|
||||||
return $this;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -520,5 +520,4 @@ abstract class Tournament
|
|||||||
$this->Tiebreaks = $Tiebreaks;
|
$this->Tiebreaks = $Tiebreaks;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -72,6 +72,4 @@ abstract class Pairtwo6
|
|||||||
$this->BinaryData[$Key] = $Value;
|
$this->BinaryData[$Key] = $Value;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ class Pairtwo6 extends Pairtwo6Model implements ReaderInterface
|
|||||||
* @param string $filename
|
* @param string $filename
|
||||||
* @return Pairtwo6
|
* @return Pairtwo6
|
||||||
*/
|
*/
|
||||||
public function read($filename)
|
public function read($filename): ReaderInterface
|
||||||
{
|
{
|
||||||
$swshandle = fopen($filename, 'rb');
|
$swshandle = fopen($filename, 'rb');
|
||||||
$swscontents = fread($swshandle, filesize($filename));
|
$swscontents = fread($swshandle, filesize($filename));
|
||||||
@ -296,24 +296,25 @@ class Pairtwo6 extends Pairtwo6Model implements ReaderInterface
|
|||||||
for ($i = 0; $i < $this->getBinaryData("NewPlayer"); $i++) {
|
for ($i = 0; $i < $this->getBinaryData("NewPlayer"); $i++) {
|
||||||
$player = new Player();
|
$player = new Player();
|
||||||
|
|
||||||
|
// Rank (Unused value)
|
||||||
$length = 4;
|
$length = 4;
|
||||||
$player->SetRank($this->readData('Int', substr($swscontents, $offset, $length)));
|
$player->setBinaryData("Rank", $this->readData('Int', substr($swscontents, $offset, $length)));
|
||||||
$offset += $length;
|
$offset += $length;
|
||||||
|
|
||||||
$length = 4;
|
$length = 4;
|
||||||
$this->setBinaryData("Players($i)_NamePos", $this->readData('Int', substr($swscontents, $offset, $length)));
|
$player->setBinaryData("NamePos", $this->readData('Int', substr($swscontents, $offset, $length)));
|
||||||
$offset += $length;
|
$offset += $length;
|
||||||
|
|
||||||
$length = 4;
|
$length = 4;
|
||||||
$player->SetFideId($this->readData('Int', substr($swscontents, $offset, $length)));
|
$ids['fide'] = $this->readData('Int', substr($swscontents, $offset, $length));
|
||||||
$offset += $length;
|
$offset += $length;
|
||||||
|
|
||||||
$length = 4;
|
$length = 4;
|
||||||
$player->SetExtraPts($this->readData('Int', substr($swscontents, $offset, $length)));
|
$player->setBinaryData("ExtraPts", $this->readData('Int', substr($swscontents, $offset, $length)));
|
||||||
$offset += $length;
|
$offset += $length;
|
||||||
|
|
||||||
$length = 4;
|
$length = 4;
|
||||||
$player->SetKbsbElo($this->readData('Int', substr($swscontents, $offset, $length)));
|
$elos['kbsb'] = $this->readData('Int', substr($swscontents, $offset, $length));
|
||||||
$offset += $length;
|
$offset += $length;
|
||||||
|
|
||||||
$length = 4;
|
$length = 4;
|
||||||
@ -321,35 +322,35 @@ class Pairtwo6 extends Pairtwo6Model implements ReaderInterface
|
|||||||
$offset += $length;
|
$offset += $length;
|
||||||
|
|
||||||
$length = 4;
|
$length = 4;
|
||||||
$player->setKbsbID($this->readData('Int', substr($swscontents, $offset, $length)));
|
$ids['kbsb'] = $this->readData('Int', substr($swscontents, $offset, $length));
|
||||||
$offset += $length;
|
$offset += $length;
|
||||||
|
|
||||||
$length = 4;
|
$length = 4;
|
||||||
$player->setPoints($this->readData('Int', substr($swscontents, $offset, $length)) / 2);
|
$player->setBinaryData("Points", $this->readData('Int', substr($swscontents, $offset, $length)) / 2);
|
||||||
$offset += $length;
|
$offset += $length;
|
||||||
|
|
||||||
$length = 4;
|
$length = 4;
|
||||||
$player->setClubNr($this->readData('Int', substr($swscontents, $offset, $length)));
|
$ids['club'] = $this->readData('Int', substr($swscontents, $offset, $length));
|
||||||
$offset += $length;
|
$offset += $length;
|
||||||
|
|
||||||
$length = 4;
|
$length = 4;
|
||||||
$player->setScoreBucholtz($this->readData('Int', substr($swscontents, $offset, $length)) / 2);
|
$player->setBinaryData("ScoreBuchholz", $this->readData('Int', substr($swscontents, $offset, $length)) / 2);
|
||||||
$offset += $length;
|
$offset += $length;
|
||||||
|
|
||||||
$length = 4;
|
$length = 4;
|
||||||
$player->setScoreAmerican($this->readData('Int', substr($swscontents, $offset, $length)) / 2);
|
$player->setBinaryData("ScoreAmerican", $this->readData('Int', substr($swscontents, $offset, $length)) / 2);
|
||||||
$offset += $length;
|
$offset += $length;
|
||||||
|
|
||||||
$length = 4;
|
$length = 4;
|
||||||
$this->setBinaryData("Players($i)_HelpValue", $this->readData('Int', substr($swscontents, $offset, $length)));
|
$player->setBinaryData("HelpValue", $this->readData('Int', substr($swscontents, $offset, $length)));
|
||||||
$offset += $length;
|
$offset += $length;
|
||||||
|
|
||||||
$length = 4;
|
$length = 4;
|
||||||
$player->setFideElo($this->readData('Int', substr($swscontents, $offset, $length)));
|
$elos['fide'] = $this->readData('Int', substr($swscontents, $offset, $length));
|
||||||
$offset += $length;
|
$offset += $length;
|
||||||
|
|
||||||
$length = 1;
|
$length = 1;
|
||||||
$this->setBinaryData("Players($i)_NameLength", $this->readData('Int', substr($swscontents, $offset, $length)));
|
$player->setBinaryData("NameLength", $this->readData('Int', substr($swscontents, $offset, $length)));
|
||||||
$offset += $length;
|
$offset += $length;
|
||||||
|
|
||||||
$length = 3;
|
$length = 3;
|
||||||
@ -422,41 +423,43 @@ class Pairtwo6 extends Pairtwo6Model implements ReaderInterface
|
|||||||
$offset += $length;
|
$offset += $length;
|
||||||
|
|
||||||
$length = 1;
|
$length = 1;
|
||||||
$player->setNumberOfTies($this->readData('Int', substr($swscontents, $offset, $length)));
|
$player->setBinaryData('NumberOfTies', $this->readData('Int', substr($swscontents, $offset, $length)));
|
||||||
$offset += $length;
|
$offset += $length;
|
||||||
|
|
||||||
$length = 1;
|
$length = 1;
|
||||||
$player->setAbsent($this->readData('Bool', substr($swscontents, $offset, $length)));
|
$player->setBinaryData('Absent', $this->readData('Bool', substr($swscontents, $offset, $length)));
|
||||||
$offset += $length;
|
$offset += $length;
|
||||||
|
|
||||||
$length = 1;
|
$length = 1;
|
||||||
$this->setBinaryData("Players($i)_ColorDiff", $this->readData('Int', substr($swscontents, $offset, $length)));
|
$player->setBinaryData("ColorDiff", $this->readData('Int', substr($swscontents, $offset, $length)));
|
||||||
$offset += $length;
|
$offset += $length;
|
||||||
|
|
||||||
$length = 1;
|
$length = 1;
|
||||||
$this->setBinaryData("Players($i)_ColorPref", $this->readData('Int', substr($swscontents, $offset, $length)));
|
$player->setBinaryData("ColorPref", $this->readData('Int', substr($swscontents, $offset, $length)));
|
||||||
$offset += $length;
|
$offset += $length;
|
||||||
|
|
||||||
$length = 1;
|
$length = 1;
|
||||||
$this->setBinaryData("Players($i)_Paired", $this->readData('Int', substr($swscontents, $offset, $length)));
|
$player->setBinaryData("Paired", $this->readData('Int', substr($swscontents, $offset, $length)));
|
||||||
$offset += $length;
|
$offset += $length;
|
||||||
|
|
||||||
$length = 1;
|
$length = 1;
|
||||||
$this->setBinaryData("Players($i)_Float", $this->readData('Int', substr($swscontents, $offset, $length)));
|
$player->setBinaryData("Float", $this->readData('Int', substr($swscontents, $offset, $length)));
|
||||||
$offset += $length;
|
$offset += $length;
|
||||||
|
|
||||||
$length = 1;
|
$length = 1;
|
||||||
$this->setBinaryData("Players($i)_FloatPrev", $this->readData('Int', substr($swscontents, $offset, $length)));
|
$player->setBinaryData("FloatPrev", $this->readData('Int', substr($swscontents, $offset, $length)));
|
||||||
$offset += $length;
|
$offset += $length;
|
||||||
|
|
||||||
$length = 1;
|
$length = 1;
|
||||||
$this->setBinaryData("Players($i)_FloatBefore", $this->readData('Int', substr($swscontents, $offset, $length)));
|
$player->setBinaryData("FloatBefore", $this->readData('Int', substr($swscontents, $offset, $length)));
|
||||||
$offset += $length;
|
$offset += $length;
|
||||||
|
|
||||||
$length = 1;
|
$length = 1;
|
||||||
$this->setBinaryData("Players($i)_TieMatch", $this->readData('Int', substr($swscontents, $offset, $length)));
|
$player->setBinaryData("TieMatch", $this->readData('Int', substr($swscontents, $offset, $length)));
|
||||||
$offset += $length;
|
$offset += $length;
|
||||||
|
|
||||||
|
$player->setElos($elos);
|
||||||
|
$player->setIds($ids);
|
||||||
$this->getTournament()->addPlayer($player);
|
$this->getTournament()->addPlayer($player);
|
||||||
}
|
}
|
||||||
// PlayerNames
|
// PlayerNames
|
||||||
@ -465,9 +468,9 @@ class Pairtwo6 extends Pairtwo6Model implements ReaderInterface
|
|||||||
$offset += $length;
|
$offset += $length;
|
||||||
|
|
||||||
for ($i = 0; $i < $this->getBinaryData("NewPlayer"); $i++) {
|
for ($i = 0; $i < $this->getBinaryData("NewPlayer"); $i++) {
|
||||||
$namelength = $this->getBinaryData("Players($i)_NameLength");
|
|
||||||
$nameoffset = $this->getBinaryData("Players($i)_NamePos");
|
|
||||||
$player = $this->getTournament()->getPlayerById($i);
|
$player = $this->getTournament()->getPlayerById($i);
|
||||||
|
$namelength = $player->getBinaryData("NameLength");
|
||||||
|
$nameoffset = $player->getBinaryData("NamePos");
|
||||||
$player->setName($this->readData("String", substr($this->getBinaryData("PlayerNames"), $nameoffset, $namelength)));
|
$player->setName($this->readData("String", substr($this->getBinaryData("PlayerNames"), $nameoffset, $namelength)));
|
||||||
|
|
||||||
$this->getTournament()->updatePlayer($i, $player);
|
$this->getTournament()->updatePlayer($i, $player);
|
||||||
@ -553,7 +556,7 @@ class Pairtwo6 extends Pairtwo6Model implements ReaderInterface
|
|||||||
$system = TournamentSystem::American;
|
$system = TournamentSystem::American;
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
$system = TournamentSystem::Imperial;
|
$system = TournamentSystem::Keizer;
|
||||||
break;
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
default:
|
default:
|
||||||
@ -691,6 +694,8 @@ class Pairtwo6 extends Pairtwo6Model implements ReaderInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->addTiebreaks();
|
||||||
|
|
||||||
$this->getTournament()->pairingsToRounds();
|
$this->getTournament()->pairingsToRounds();
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@ -796,4 +801,27 @@ class Pairtwo6 extends Pairtwo6Model implements ReaderInterface
|
|||||||
|
|
||||||
return DateTime::createFromFormat($format, $concat);
|
return DateTime::createFromFormat($format, $concat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
private function addTiebreaks(): Pairtwo6
|
||||||
|
{
|
||||||
|
switch ($this->getTournament()->getSystem()) {
|
||||||
|
case TournamentSystem::Keizer:
|
||||||
|
$firstElement = new Tiebreak(Tiebreak::Keizer);
|
||||||
|
break;
|
||||||
|
case TournamentSystem::American:
|
||||||
|
$firstElement = new Tiebreak(Tiebreak::American);
|
||||||
|
break;
|
||||||
|
case TournamentSystem::Closed:
|
||||||
|
case TournamentSystem::Swiss:
|
||||||
|
$firstElement = new Tiebreak(Tiebreak::Points);
|
||||||
|
}
|
||||||
|
$tiebreaks = $this->getTournament()->getTiebreaks();
|
||||||
|
array_unshift($tiebreaks, $firstElement);
|
||||||
|
$this->getTournament()->setTiebreaks($tiebreaks);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
113
src/Tiebreaks.php
Normal file
113
src/Tiebreaks.php
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace JeroenED\Libpairtwo;
|
||||||
|
|
||||||
|
use JeroenED\Libpairtwo\Enums\Color;
|
||||||
|
use JeroenED\Libpairtwo\Models\Tournament;
|
||||||
|
use JeroenED\Libpairtwo\Enums\Result;
|
||||||
|
|
||||||
|
abstract class Tiebreaks extends Tournament
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $key
|
||||||
|
* @param Player $player
|
||||||
|
* @return float
|
||||||
|
*/
|
||||||
|
protected function calculateKeizer(int $key, Player $player): float
|
||||||
|
{
|
||||||
|
$currentTiebreaks = $player->getTiebreaks();
|
||||||
|
$currentTiebreaks[$key] = $player->getBinaryData('ScoreAmerican');
|
||||||
|
$player->setTiebreaks($currentTiebreaks);
|
||||||
|
return $currentTiebreaks[$key];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $key
|
||||||
|
* @param Player $player
|
||||||
|
* @return float
|
||||||
|
*/
|
||||||
|
protected function calculateAmerican(int $key, Player $player): float
|
||||||
|
{
|
||||||
|
$currentTiebreaks = $player->getTiebreaks();
|
||||||
|
$currentTiebreaks[$key] = $player->getBinaryData('ScoreAmerican');
|
||||||
|
$player->setTiebreaks($currentTiebreaks);
|
||||||
|
return $currentTiebreaks[$key];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $key
|
||||||
|
* @param Player $player
|
||||||
|
* @return float
|
||||||
|
*/
|
||||||
|
protected function calculatePoints(int $key, Player $player): float
|
||||||
|
{
|
||||||
|
$currentTiebreaks = $player->getTiebreaks();
|
||||||
|
$currentTiebreaks[$key] = $player->getBinaryData('Points');
|
||||||
|
$player->setTiebreaks($currentTiebreaks);
|
||||||
|
return $currentTiebreaks[$key];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $key
|
||||||
|
* @param Player $player
|
||||||
|
* @return float
|
||||||
|
*/
|
||||||
|
protected function calculateBaumbach(int $key, Player $player): float
|
||||||
|
{
|
||||||
|
$wonArray = [Result::won, Result::wonadjourned, Result::wonbye, Result::wonforfait];
|
||||||
|
$totalwins = 0;
|
||||||
|
foreach ($player->getPairings() as $pairing) {
|
||||||
|
if (array_search($pairing->getResult(), $wonArray) !== false) {
|
||||||
|
$totalwins++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$currentTiebreaks = $player->getTiebreaks();
|
||||||
|
$currentTiebreaks[$key] = $totalwins;
|
||||||
|
$player->setTiebreaks($currentTiebreaks);
|
||||||
|
return $currentTiebreaks[$key];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $key
|
||||||
|
* @param Player $player
|
||||||
|
* @return float
|
||||||
|
*/
|
||||||
|
protected function calculateBlackPlayed(int $key, Player $player): float
|
||||||
|
{
|
||||||
|
$blackArray = [Color::black];
|
||||||
|
$totalwins = 0;
|
||||||
|
foreach ($player->getPairings() as $pairing) {
|
||||||
|
if (array_search($pairing->getColor(), $blackArray) !== false) {
|
||||||
|
$totalwins++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$currentTiebreaks = $player->getTiebreaks();
|
||||||
|
$currentTiebreaks[$key] = $totalwins;
|
||||||
|
$player->setTiebreaks($currentTiebreaks);
|
||||||
|
return $currentTiebreaks[$key];
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @param int $key
|
||||||
|
* @param Player $player
|
||||||
|
* @return float
|
||||||
|
*/
|
||||||
|
protected function calculateBlackWin(int $key, Player $player): float
|
||||||
|
{
|
||||||
|
$wonArray = [Result::won, Result::wonadjourned, Result::wonbye, Result::wonforfait];
|
||||||
|
$blackArray = [Color::black];
|
||||||
|
$totalwins = 0;
|
||||||
|
foreach ($player->getPairings() as $pairing) {
|
||||||
|
if (array_search($pairing->getColor(), $blackArray) !== false && array_search($pairing->getResult(), $wonArray) !== false) {
|
||||||
|
$totalwins++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$currentTiebreaks = $player->getTiebreaks();
|
||||||
|
$currentTiebreaks[$key] = $totalwins;
|
||||||
|
$player->setTiebreaks($currentTiebreaks);
|
||||||
|
return $currentTiebreaks[$key];
|
||||||
|
}
|
||||||
|
}
|
@ -9,10 +9,9 @@
|
|||||||
namespace JeroenED\Libpairtwo;
|
namespace JeroenED\Libpairtwo;
|
||||||
|
|
||||||
use JeroenED\Libpairtwo\Enums\Tiebreak;
|
use JeroenED\Libpairtwo\Enums\Tiebreak;
|
||||||
use JeroenED\Libpairtwo\Models\Tournament as TournamentModel;
|
|
||||||
use JeroenED\Libpairtwo\Enums\Color;
|
use JeroenED\Libpairtwo\Enums\Color;
|
||||||
|
|
||||||
class Tournament extends TournamentModel
|
class Tournament extends Tiebreaks
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Gets a player by its ID
|
* Gets a player by its ID
|
||||||
@ -203,14 +202,13 @@ class Tournament extends TournamentModel
|
|||||||
/**
|
/**
|
||||||
* Gets the ranking of the tournament
|
* Gets the ranking of the tournament
|
||||||
*
|
*
|
||||||
* @param bool $americansort
|
|
||||||
* @return Player[]
|
* @return Player[]
|
||||||
*/
|
*/
|
||||||
public function getRanking(bool $americansort = false)
|
public function getRanking()
|
||||||
{
|
{
|
||||||
$players = $this->getPlayers();
|
$players = $this->getPlayers();
|
||||||
|
|
||||||
$americansort ? usort($players, array($this, "SortAmerican")) : usort($players, array($this, "SortNormal"));
|
usort($players, array($this, "SortTiebreak"));
|
||||||
|
|
||||||
return $players;
|
return $players;
|
||||||
}
|
}
|
||||||
@ -220,18 +218,43 @@ class Tournament extends TournamentModel
|
|||||||
* @param Player $b
|
* @param Player $b
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
private function sortNormal(Player $a, Player $b)
|
private function sortTiebreak(Player $a, Player $b)
|
||||||
{
|
{
|
||||||
return $b->getPoints() - $a->getPoints();
|
$result = 0;
|
||||||
|
foreach ($this->getTiebreaks() as $key=>$tiebreak) {
|
||||||
|
$result = $this->CalculateTiebreak($key, $b, $a) - $this->CalculateTiebreak($key, $a, $b);
|
||||||
|
if ($result != 0) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Player $a
|
* @return float
|
||||||
* @param Player $b
|
|
||||||
* @return int
|
|
||||||
*/
|
*/
|
||||||
private function sortAmerican(Player $a, Player $b)
|
private function calculateTiebreak(int $key, Player $player, Player $opponent): float
|
||||||
{
|
{
|
||||||
return $b->getScoreAmerican() - $a->getScoreAmerican();
|
$tiebreak = $this->getTiebreaks()[$key];
|
||||||
|
switch ($tiebreak) {
|
||||||
|
case Tiebreak::Keizer:
|
||||||
|
return $this->calculateKeizer($key, $player);
|
||||||
|
break;
|
||||||
|
case Tiebreak::American:
|
||||||
|
return $this->calculateAmerican($key, $player);
|
||||||
|
break;
|
||||||
|
case Tiebreak::Points:
|
||||||
|
return $this->calculatePoints($key, $player);
|
||||||
|
break;
|
||||||
|
case Tiebreak::Baumbach:
|
||||||
|
return $this->calculateBaumbach($key, $player);
|
||||||
|
break;
|
||||||
|
case Tiebreak::BlackPlayed:
|
||||||
|
return $this->calculateBlackPlayed($key, $player);
|
||||||
|
break;
|
||||||
|
case Tiebreak::BlackWin:
|
||||||
|
return $this->calculateBlackWin($key, $player);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,21 +46,21 @@ echo "Place: " . $sws->getTournament()->getOrganiserPlace() . PHP_EOL;
|
|||||||
echo "Unrated-Elo: " . $sws->getTournament()->getNonRatedElo() . PHP_EOL;
|
echo "Unrated-Elo: " . $sws->getTournament()->getNonRatedElo() . PHP_EOL;
|
||||||
echo "Federation: " . $sws->getTournament()->getFederation() . PHP_EOL;
|
echo "Federation: " . $sws->getTournament()->getFederation() . PHP_EOL;
|
||||||
echo "Organiser: " . $sws->getTournament()->getOrganiserClubNo() . PHP_EOL;
|
echo "Organiser: " . $sws->getTournament()->getOrganiserClubNo() . PHP_EOL;
|
||||||
echo "Fide Elo P1: " . $sws->getTournament()->getPlayerById(0)->getFideElo() . PHP_EOL;
|
echo "Fide Elo P1: " . $sws->getTournament()->getPlayerById(0)->getElos()['fide'] . PHP_EOL;
|
||||||
echo "Fide Elo P2: " . $sws->getTournament()->getPlayerById(1)->getFideElo() . PHP_EOL;
|
echo "Fide Elo P2: " . $sws->getTournament()->getPlayerById(1)->getElos()['fide'] . PHP_EOL;
|
||||||
echo "Fide Elo P3: " . $sws->getTournament()->getPlayerById(2)->getFideElo() . PHP_EOL;
|
echo "Fide Elo P3: " . $sws->getTournament()->getPlayerById(2)->getElos()['fide'] . PHP_EOL;
|
||||||
echo "KBSB Elo P1: " . $sws->getTournament()->getPlayerById(0)->getKbsbElo() . PHP_EOL;
|
echo "KBSB Elo P1: " . $sws->getTournament()->getPlayerById(0)->getElos()['kbsb'] . PHP_EOL;
|
||||||
echo "KBSB Elo P2: " . $sws->getTournament()->getPlayerById(1)->getKbsbElo() . PHP_EOL;
|
echo "KBSB Elo P2: " . $sws->getTournament()->getPlayerById(1)->getElos()['kbsb'] . PHP_EOL;
|
||||||
echo "KBSB Elo P3: " . $sws->getTournament()->getPlayerById(2)->getKbsbElo() . PHP_EOL;
|
echo "KBSB Elo P3: " . $sws->getTournament()->getPlayerById(2)->getElos()['kbsb'] . PHP_EOL;
|
||||||
echo "Name P1: " . $sws->getTournament()->getPlayerById(0)->getName() . PHP_EOL;
|
echo "Name P1: " . $sws->getTournament()->getPlayerById(0)->getName() . PHP_EOL;
|
||||||
echo "Name P2: " . $sws->getTournament()->getPlayerById(1)->getName() . PHP_EOL;
|
echo "Name P2: " . $sws->getTournament()->getPlayerById(1)->getName() . PHP_EOL;
|
||||||
echo "Name P3: " . $sws->getTournament()->getPlayerById(2)->getName() . PHP_EOL;
|
echo "Name P3: " . $sws->getTournament()->getPlayerById(2)->getName() . PHP_EOL;
|
||||||
echo "Gender P1: " . $sws->getTournament()->getPlayerById(0)->getGender()->getKey() . PHP_EOL;
|
echo "Gender P1: " . $sws->getTournament()->getPlayerById(0)->getGender()->getKey() . PHP_EOL;
|
||||||
echo "Gender P2: " . $sws->getTournament()->getPlayerById(1)->getGender()->getKey() . PHP_EOL;
|
echo "Gender P2: " . $sws->getTournament()->getPlayerById(1)->getGender()->getKey() . PHP_EOL;
|
||||||
echo "Gender P3: " . $sws->getTournament()->getPlayerById(2)->getGender()->getKey() . PHP_EOL;
|
echo "Gender P3: " . $sws->getTournament()->getPlayerById(2)->getGender()->getKey() . PHP_EOL;
|
||||||
echo "Absent P1: " . $sws->getTournament()->getPlayerById(0)->isAbsent() . PHP_EOL;
|
echo "Absent P1: " . $sws->getTournament()->getPlayerById(0)->getBinaryData("absent") . PHP_EOL;
|
||||||
echo "Absent P2: " . $sws->getTournament()->getPlayerById(1)->isAbsent() . PHP_EOL;
|
echo "Absent P2: " . $sws->getTournament()->getPlayerById(1)->getBinaryData("absent") . PHP_EOL;
|
||||||
echo "Absent P3: " . $sws->getTournament()->getPlayerById(2)->isAbsent() . PHP_EOL;
|
echo "Absent P3: " . $sws->getTournament()->getPlayerById(2)->getBinaryData("absent") . PHP_EOL;
|
||||||
echo "Date Round 1: " . $sws->getTournament()->getRoundByNo(0)->getDate()->format('d/m/Y') . PHP_EOL;
|
echo "Date Round 1: " . $sws->getTournament()->getRoundByNo(0)->getDate()->format('d/m/Y') . PHP_EOL;
|
||||||
echo "Date Round 2: " . $sws->getTournament()->getRoundByNo(1)->getDate()->format('d/m/Y') . PHP_EOL;
|
echo "Date Round 2: " . $sws->getTournament()->getRoundByNo(1)->getDate()->format('d/m/Y') . PHP_EOL;
|
||||||
echo "Date Round 3: " . $sws->getTournament()->getRoundByNo(2)->getDate()->format('d/m/Y') . PHP_EOL;
|
echo "Date Round 3: " . $sws->getTournament()->getRoundByNo(2)->getDate()->format('d/m/Y') . PHP_EOL;
|
||||||
@ -73,3 +73,6 @@ echo "Player Pairing 3: " . $sws->getTournament()->getPairings()[2]->getPlayer()
|
|||||||
echo "Tiebreak 1: " . $sws->getTournament()->getTiebreaks()[0]->getValue() . PHP_EOL;
|
echo "Tiebreak 1: " . $sws->getTournament()->getTiebreaks()[0]->getValue() . PHP_EOL;
|
||||||
echo "Tiebreak 2: " . $sws->getTournament()->getTiebreaks()[1]->getValue() . PHP_EOL;
|
echo "Tiebreak 2: " . $sws->getTournament()->getTiebreaks()[1]->getValue() . PHP_EOL;
|
||||||
echo "Tiebreak 3: " . $sws->getTournament()->getTiebreaks()[2]->getValue() . PHP_EOL;
|
echo "Tiebreak 3: " . $sws->getTournament()->getTiebreaks()[2]->getValue() . PHP_EOL;
|
||||||
|
foreach ($sws->getTournament()->getRanking() as $player) {
|
||||||
|
echo $player->getName() . ' ' . implode(' ', $player->getTiebreaks()) . PHP_EOL;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user