mirror of
https://github.com/JeroenED/libpairtwo.git
synced 2024-12-22 20:31:21 +01:00
Compare commits
14 Commits
31bd9e8a53
...
5a1187a47a
Author | SHA1 | Date | |
---|---|---|---|
|
5a1187a47a | ||
2ca18a3271 | |||
e113d743ca | |||
6c7249bd3e | |||
9aca75d298 | |||
94b18d3d9b | |||
a2fc7d6589 | |||
7a48b7777d | |||
9c7deea8ca | |||
86244247cf | |||
3108c28725 | |||
c49ea32f08 | |||
c5b17c9512 | |||
0f8721e57e |
@ -234,7 +234,9 @@ class Player
|
||||
foreach ($this->Pairings as $key => $pairing) {
|
||||
if ($key < $round || $round == -1) {
|
||||
if ($pairing->Result == Result::WON_BYE) {
|
||||
$points += (isset($this->CustomPoints[ 'bye' ])) ? $custompoints[ 'bye' ] : 1;
|
||||
$points += (isset($custompoints[ 'bye' ])) ? $custompoints[ 'bye' ] : 1;
|
||||
} else if ($pairing->Result == Result::ABSENT) {
|
||||
$points += (isset($custompoints[ 'absent' ])) ? $custompoints[ 'absent' ] : 0;
|
||||
} elseif (array_search($pairing->Result, Constants::WON) !== false) {
|
||||
$points += (isset($custompoints[ 'win' ])) ? $custompoints[ 'win' ] : 1;
|
||||
} elseif (array_search($pairing->Result, Constants::DRAW) !== false) {
|
||||
@ -299,9 +301,9 @@ class Player
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getElo(string $type): int
|
||||
public function getElo(string $type): ?int
|
||||
{
|
||||
return $this->Elos[ $type ];
|
||||
return isset($this->Elos[ $type ]) ? $this->Elos[ $type ] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -199,13 +199,17 @@ class Swar5 implements ReaderInterface
|
||||
*
|
||||
* @throws IncompatibleReaderException
|
||||
*/
|
||||
public function read(string $filename): void
|
||||
public function read(string $filename, string $compatversion = ''): void
|
||||
{
|
||||
$swshandle = fopen($filename, 'rb');
|
||||
|
||||
$this->Release = $this->readData('String', $swshandle);
|
||||
|
||||
if($compatversion != '') {
|
||||
$this->Release == $compatversion;
|
||||
}
|
||||
if (array_search(substr($this->Release, 0, 3), self::COMPATIBLE_VERSIONS) === false) {
|
||||
throw new IncompatibleReaderException("This file was not created with Swar 4");
|
||||
throw new IncompatibleReaderException("This file was not created with Swar 5");
|
||||
}
|
||||
|
||||
$this->Tournament = new Tournament();
|
||||
@ -242,30 +246,42 @@ class Swar5 implements ReaderInterface
|
||||
|
||||
$this->Tournament->FideHomol = $this->readData('Int', $swshandle);
|
||||
|
||||
$this->Tournament->FideId = $this->readData('String', $swshandle);
|
||||
if (version_compare($this->Release, '5.24', ">=")) {
|
||||
$this->Tournament->FideId = $this->readData('Int', $swshandle);
|
||||
} else {
|
||||
for ($i = 0; $i <= 15; $i++) {
|
||||
// First round
|
||||
$this->readData('Int', $swshandle);
|
||||
//last round
|
||||
$this->readData('Int', $swshandle);
|
||||
//fide ID
|
||||
$this->readData('Int', $swshandle);
|
||||
}
|
||||
}
|
||||
$this->Tournament->FideArbitre1 = $this->readData('String', $swshandle);
|
||||
$this->Tournament->FideArbitre2 = $this->readData('String', $swshandle);
|
||||
$this->Tournament->FideEmail = $this->readData('String', $swshandle);
|
||||
$this->Tournament->FideRemarques = $this->readData('String', $swshandle);
|
||||
|
||||
$applycustompoints = false;
|
||||
switch ($this->readData('Int', $swshandle)) {
|
||||
case 4:
|
||||
case 5:
|
||||
case 6:
|
||||
$system = TournamentSystem::CLOSED;
|
||||
break;
|
||||
case 7:
|
||||
case 8:
|
||||
$system = TournamentSystem::AMERICAN;
|
||||
break;
|
||||
case 3:
|
||||
$applycustompoints = true;
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
default:
|
||||
$system = TournamentSystem::SWISS;
|
||||
break;
|
||||
case 5:
|
||||
case 6:
|
||||
case 7:
|
||||
$system = TournamentSystem::CLOSED;
|
||||
break;
|
||||
case 8:
|
||||
case 9:
|
||||
$system = TournamentSystem::AMERICAN;
|
||||
break;
|
||||
}
|
||||
$this->Tournament->System = new TournamentSystem($system);
|
||||
|
||||
@ -274,11 +290,12 @@ class Swar5 implements ReaderInterface
|
||||
$this->Tournament->SW_AmerPresence = $this->readData('Int', $swshandle);
|
||||
$this->Tournament->Plusieurs = $this->readData('Int', $swshandle);
|
||||
$this->Tournament->FirstTable = $this->readData('Int', $swshandle);
|
||||
$this->Tournament->CustomPoints['win'] = $this->readData('Int', $swshandle) / 4;
|
||||
$this->Tournament->CustomPoints['draw'] = $this->readData('Int', $swshandle) / 4;
|
||||
$this->Tournament->CustomPoints['loss'] = $this->readData('Int', $swshandle) / 4;
|
||||
$this->Tournament->CustomPoints['bye'] = $this->readData('Int', $swshandle) / 4;
|
||||
$this->Tournament->CustomPoints['absent'] = $this->readData('Int', $swshandle) / 4;
|
||||
$custompoints['win'] = $this->readData('Int', $swshandle) / 4;
|
||||
$custompoints['draw'] = $this->readData('Int', $swshandle) / 4;
|
||||
$custompoints['loss'] = $this->readData('Int', $swshandle) / 4;
|
||||
$custompoints['bye'] = $this->readData('Int', $swshandle) / 4;
|
||||
$custompoints['absent'] = $this->readData('Int', $swshandle) / 4;
|
||||
if($applycustompoints) $this->Tournament->CustomPoints = $custompoints;
|
||||
$this->Tournament->EloUsed = $this->readData('Int', $swshandle);
|
||||
$this->Tournament->TournoiStd = $this->readData('Int', $swshandle);
|
||||
$this->Tournament->TbPersonel = $this->readData('Int', $swshandle);
|
||||
@ -424,6 +441,7 @@ class Swar5 implements ReaderInterface
|
||||
$pt = 0;
|
||||
for ($i = 0; $i < $this->Tournament->NumberOfPlayers; $i++) {
|
||||
$player = new Player();
|
||||
|
||||
$player->Classement = $this->readData('Int', $swshandle);
|
||||
$player->Name = $this->readData('String', $swshandle);
|
||||
$inscriptionNos[ $this->readData('Int', $swshandle) ] = $i;
|
||||
@ -498,7 +516,8 @@ class Swar5 implements ReaderInterface
|
||||
$player->Tiebreak = $tiebreaks;
|
||||
$player->Performance = $this->readData('Int', $swshandle); // To Calculate by libpairtwo
|
||||
$player->Absent = $this->readData('Int', $swshandle);
|
||||
$player->AbsentRounds = $this->readData('String', $swshandle);
|
||||
$player->AbsentRounds = $this->readData('Int', $swshandle);
|
||||
if(version_compare($this->Release, '5.53', "<=")) $player->Paid = $this->readData('Int', $swshandle);
|
||||
$player->ExtraPoints = $this->readData('Int', $swshandle);
|
||||
$player->SpecialPoints = $this->readData('Int', $swshandle);
|
||||
$player->AllocatedRounds = $this->readData('Int', $swshandle);
|
||||
@ -518,6 +537,7 @@ class Swar5 implements ReaderInterface
|
||||
|
||||
$pt++;
|
||||
}
|
||||
|
||||
$this->Tournament->Pairing = $pairing;
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@ namespace JeroenED\Libpairtwo;
|
||||
use Closure;
|
||||
use DateTime;
|
||||
use JeroenED\Libpairtwo\Enums\Color;
|
||||
use JeroenED\Libpairtwo\Enums\Result;
|
||||
use JeroenED\Libpairtwo\Enums\Tiebreak;
|
||||
use JeroenED\Libpairtwo\Enums\TournamentSystem;
|
||||
|
||||
@ -728,7 +729,7 @@ class Tournament
|
||||
$tiebreak += $pairing->Opponent->calculatePointsForTiebreaks() / 2;
|
||||
}
|
||||
}
|
||||
if (array_search($pairing->Result, Constants::NOTPLAYED) !== false) {
|
||||
if ($pairing->Result == Result::WON_BYE) {
|
||||
$tiebreak += $player->calculatePointsForVirtualPlayer($key);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user