mirror of
https://github.com/JeroenED/libpairtwo.git
synced 2024-11-21 14:07:42 +01:00
Removed calculated getters
This commit is contained in:
parent
9859984a2a
commit
cded84ce03
@ -81,7 +81,7 @@ class Player
|
||||
* @param Tournament $tournament
|
||||
* @return Player[]
|
||||
*/
|
||||
public static function getPlayersByName(string $search, Tournament $tournament): array
|
||||
public static function PlayersByName(string $search, Tournament $tournament): array
|
||||
{
|
||||
/** @var Player[] */
|
||||
$players = $tournament->Players;
|
||||
@ -154,7 +154,7 @@ class Player
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getNoOfWins(): int
|
||||
private function noOfWins(): int
|
||||
{
|
||||
$wins = 0;
|
||||
foreach ($this->Pairings as $pairing) {
|
||||
@ -195,7 +195,7 @@ class Player
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getPointsForBuchholz(): float
|
||||
private function pointsForBuchholz(): float
|
||||
{
|
||||
$points = 0;
|
||||
foreach ($this->Pairings as $pairing) {
|
||||
@ -216,7 +216,7 @@ class Player
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getPerformance(string $type, int $unratedElo): float
|
||||
public function Performance(string $type, int $unratedElo): float
|
||||
{
|
||||
$total = 0;
|
||||
$opponents = 0;
|
||||
@ -243,7 +243,7 @@ class Player
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getPlayedGames(): int
|
||||
private function playedGames(): int
|
||||
{
|
||||
$total = 0;
|
||||
foreach ($this->Pairings as $pairing) {
|
||||
@ -255,14 +255,20 @@ class Player
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns binary data that was read out the pairing file but was not needed immediately
|
||||
* Magic method to read out several fields. If field was not found it is being searched in the binary data fields
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool|DateTime|int|string|null
|
||||
*/
|
||||
public function __get(string $key)
|
||||
{
|
||||
if (isset($this->BinaryData[$key])) {
|
||||
if($key == 'PlayedGames') {
|
||||
return $this->playedGames();
|
||||
} elseif ($key == 'NoOfWins') {
|
||||
return $this->noOfWins();
|
||||
} elseif ($key == 'PointsForBuchholz') {
|
||||
return $this->pointsForBuchholz();
|
||||
} elseif (isset($this->BinaryData[$key])) {
|
||||
return $this->BinaryData[$key];
|
||||
}
|
||||
return null;
|
||||
|
@ -492,7 +492,7 @@ class Pairtwo6 implements ReaderInterface
|
||||
$offset += $length;
|
||||
|
||||
for ($i = 0; $i < $this->NewPlayer; $i++) {
|
||||
$player = $this->Tournament->getPlayerById($i);
|
||||
$player = $this->Tournament->PlayerById($i);
|
||||
$namelength = $player->NameLength;
|
||||
$nameoffset = $player->NamePos;
|
||||
$player->Name = $this->readData("String", substr($this->PlayerNames, $nameoffset, $namelength));
|
||||
@ -640,12 +640,12 @@ class Pairtwo6 implements ReaderInterface
|
||||
for ($x = 0; $x < $this->CreatedRounds; $x++) {
|
||||
$pairing = new Pairing();
|
||||
|
||||
$pairing->Player = $this->Tournament->getPlayerById($i);
|
||||
$pairing->Player = $this->Tournament->PlayerById($i);
|
||||
|
||||
$length = 4;
|
||||
$opponent = $this->readData('Int', substr($swscontents, $offset, $length));
|
||||
if ($opponent != 4294967295) {
|
||||
$pairing->Opponent = $this->Tournament->getPlayerById($opponent);
|
||||
$pairing->Opponent = $this->Tournament->PlayerById($opponent);
|
||||
}
|
||||
$offset += $length;
|
||||
|
||||
|
@ -432,10 +432,10 @@ class Swar4 implements ReaderInterface
|
||||
while (null !== $this->Tournament->Pairing[$ptn]['round']) {
|
||||
$pairing = new Pairing();
|
||||
|
||||
$pairing->Player = $this->Tournament->getPlayerById($this->Tournament->Pairing[$ptn]['player']);
|
||||
$pairing->Player = $this->Tournament->PlayerById($this->Tournament->Pairing[$ptn]['player']);
|
||||
$pairing->Round = $this->Tournament->Pairing[$ptn]['round'];
|
||||
if ($this->Tournament->Pairing[$ptn]['opponent'] != 4294967295) {
|
||||
$pairing->Opponent = $this->Tournament->getPlayerById($inscriptionNos[$this->Tournament->Pairing[$ptn]['opponent']]);
|
||||
$pairing->Opponent = $this->Tournament->PlayerById($inscriptionNos[$this->Tournament->Pairing[$ptn]['opponent']]);
|
||||
}
|
||||
switch ($this->Tournament->Pairing[$ptn]['result']) {
|
||||
case '1000':
|
||||
|
@ -84,7 +84,7 @@ class Round
|
||||
*
|
||||
* @return Pairing[]
|
||||
*/
|
||||
public function getBye(): array
|
||||
private function bye(): array
|
||||
{
|
||||
$allPairings = $this->Pairings;
|
||||
$byePairings = [];
|
||||
@ -101,7 +101,7 @@ class Round
|
||||
*
|
||||
* @return Pairing[]
|
||||
*/
|
||||
public function getAbsent(): array
|
||||
private function absent(): array
|
||||
{
|
||||
$allPairings = $this->Pairings;
|
||||
$absentPairings = [];
|
||||
@ -118,7 +118,7 @@ class Round
|
||||
*
|
||||
* @return Game[]
|
||||
*/
|
||||
public function getGamesByBoard(): array
|
||||
private function gamesByBoard(): array
|
||||
{
|
||||
$allGames = $this->Games;
|
||||
usort($allGames, array($this, 'sortByBoard'));
|
||||
@ -139,4 +139,27 @@ class Round
|
||||
}
|
||||
return ($a->Board > $b->Board) ? +1 : -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic method to read out several fields. If field was not found it is being searched in the binary data fields
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool|DateTime|int|string|null
|
||||
*/
|
||||
public function __get(string $key)
|
||||
{
|
||||
if ($key == 'Bye') {
|
||||
return $this->bye();
|
||||
}
|
||||
elseif ($key == 'Absent') {
|
||||
return $this->absent();
|
||||
}
|
||||
elseif ($key == 'GamesByBoard') {
|
||||
return $this->gamesByBoard();
|
||||
}
|
||||
elseif (isset($this->BinaryData[$key])) {
|
||||
return $this->BinaryData[$key];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ class Tournament
|
||||
* @param integer $id
|
||||
* @return Player
|
||||
*/
|
||||
public function getPlayerById(int $id): Player
|
||||
public function PlayerById(int $id): Player
|
||||
{
|
||||
return $this->Players[$id];
|
||||
}
|
||||
@ -175,7 +175,7 @@ class Tournament
|
||||
* @param int $roundNo
|
||||
* @return Round
|
||||
*/
|
||||
public function getRoundByNo(int $roundNo): Round
|
||||
public function RoundByNo(int $roundNo): Round
|
||||
{
|
||||
return $this->Rounds[$roundNo];
|
||||
}
|
||||
@ -230,7 +230,7 @@ class Tournament
|
||||
$round = $pairing->Round;
|
||||
$color = $pairing->Color;
|
||||
|
||||
$this->getRoundByNo($round)->addPairing($pairing);
|
||||
$this->RoundByNo($round)->addPairing($pairing);
|
||||
$opponent = null;
|
||||
|
||||
/**
|
||||
@ -328,7 +328,7 @@ class Tournament
|
||||
$this->addRound($roundObj);
|
||||
}
|
||||
|
||||
$this->getRoundByNo($round)->addGame($game);
|
||||
$this->RoundByNo($round)->addGame($game);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -336,7 +336,7 @@ class Tournament
|
||||
*
|
||||
* @return Player[]
|
||||
*/
|
||||
public function getRanking(): array
|
||||
private function ranking(): array
|
||||
{
|
||||
$players = $this->Players;
|
||||
foreach ($this->Tiebreaks as $tbkey=>$tiebreak) {
|
||||
@ -465,7 +465,7 @@ class Tournament
|
||||
return $this->calculateAveragePerformance($player, $this->PriorityElo);
|
||||
break;
|
||||
case Tiebreak::Performance:
|
||||
return $player->getPerformance($this->PriorityElo, $this->NonRatedElo);
|
||||
return $player->Performance($this->PriorityElo, $this->NonRatedElo);
|
||||
break;
|
||||
default:
|
||||
return null;
|
||||
@ -477,7 +477,7 @@ class Tournament
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getAverageElo(): int
|
||||
private function averageElo(): int
|
||||
{
|
||||
$totalrating = 0;
|
||||
$players = 0;
|
||||
@ -498,7 +498,7 @@ class Tournament
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getParticipants(): int
|
||||
private function participants(): int
|
||||
{
|
||||
return count($this->Players);
|
||||
}
|
||||
@ -665,7 +665,7 @@ class Tournament
|
||||
$allratings = [];
|
||||
foreach ($pairings as $pairing) {
|
||||
if (array_search($pairing->Result, Constants::NotPlayed) === false) {
|
||||
$toadd = $pairing->Opponent->getPerformance($type, $this->NonRatedElo);
|
||||
$toadd = $pairing->Opponent->Performance($type, $this->NonRatedElo);
|
||||
if ($toadd != 0) {
|
||||
$allratings[] = $toadd;
|
||||
}
|
||||
@ -820,14 +820,23 @@ class Tournament
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns binary data that was read out the pairing file but was not needed immediately
|
||||
* Magic method to read out several fields. If field was not found it is being searched in the binary data fields
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool|DateTime|int|string|null
|
||||
*/
|
||||
public function __get(string $key)
|
||||
{
|
||||
if (isset($this->BinaryData[$key])) {
|
||||
if ($key == 'Participants') {
|
||||
return $this->participants();
|
||||
}
|
||||
elseif ($key == 'AverageElo') {
|
||||
return $this->averageElo();
|
||||
}
|
||||
elseif ($key == 'Ranking') {
|
||||
return $this->ranking();
|
||||
}
|
||||
elseif (isset($this->BinaryData[$key])) {
|
||||
return $this->BinaryData[$key];
|
||||
}
|
||||
return null;
|
||||
|
Loading…
Reference in New Issue
Block a user