Reader TRN16 finished
This commit is contained in:
parent
99c27eb48a
commit
2003701710
@ -10,7 +10,6 @@
|
|||||||
102 Jeroen De Meerleer
|
102 Jeroen De Meerleer
|
||||||
112 Jerry The Blackbird
|
112 Jerry The Blackbird
|
||||||
122 120 min/10 moves + 30 min. avec incr. 30" starting from 40th move
|
122 120 min/10 moves + 30 min. avec incr. 30" starting from 40th move
|
||||||
132 23/01/14 23/01/14 23/01/14 23/01/14 23/01/14 23/01/14 23/01/14
|
|
||||||
001 1 m Player 3 1850 BEL 0 1900/01/01 7.0 3 8 w 1 3 b 1 2 w 1 6 b 1 5 w 1 7 w 1 4 b 1
|
001 1 m Player 3 1850 BEL 0 1900/01/01 7.0 3 8 w 1 3 b 1 2 w 1 6 b 1 5 w 1 7 w 1 4 b 1
|
||||||
001 2 wWIM Player 1 1900 BEL 0 1900/01/01 5.5 2 5 w 1 6 w 1 1 b 0 7 w 1 4 b 1 8 w = 3 b 1
|
001 2 wWIM Player 1 1900 BEL 0 1900/01/01 5.5 2 5 w 1 6 w 1 1 b 0 7 w 1 4 b 1 8 w = 3 b 1
|
||||||
001 3 w Player 7 1650 BEL 0 1900/01/01 4.0 7 6 b 1 1 w 0 7 b 1 4 w 1 8 b 1 5 b 0 2 w 0
|
001 3 w Player 7 1650 BEL 0 1900/01/01 4.0 7 6 b 1 1 w 0 7 b 1 4 w 1 8 b 1 5 b 0 2 w 0
|
||||||
@ -19,3 +18,4 @@
|
|||||||
001 6 m CM Player 2 1950 BEL 0 1900/01/01 2.0 1 3 w 0 2 b 0 5 w = 1 w 0 7 b 1 4 w 0 8 b =
|
001 6 m CM Player 2 1950 BEL 0 1900/01/01 2.0 1 3 w 0 2 b 0 5 w = 1 w 0 7 b 1 4 w 0 8 b =
|
||||||
001 7 w Player 4 1800 BEL 0 1900/01/01 1.5 4 4 w 0 8 b 1 3 w 0 2 b 0 6 w 0 1 b 0 5 w =
|
001 7 w Player 4 1800 BEL 0 1900/01/01 1.5 4 4 w 0 8 b 1 3 w 0 2 b 0 6 w 0 1 b 0 5 w =
|
||||||
001 8 m Player 6 1700 BEL 0 1900/01/01 1.5 6 1 b 0 7 w 0 4 b 0 5 b = 3 w 0 2 b = 6 w =
|
001 8 m Player 6 1700 BEL 0 1900/01/01 1.5 6 1 b 0 7 w 0 4 b 0 5 b = 3 w 0 2 b = 6 w =
|
||||||
|
132 23/01/14 23/01/14 23/01/14 23/01/14 23/01/14 23/01/14 23/01/14
|
8
src/Exceptions/InvalidFileException.php
Normal file
8
src/Exceptions/InvalidFileException.php
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Blackbirdchess\Service\Import\Exceptions;
|
||||||
|
|
||||||
|
class InvalidFileException extends \Blackbirdchess\Service\Results\Exceptions\LibpairtwoException
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace Blackbirdchess\Service\Import\Readers;
|
namespace Blackbirdchess\Service\Import\Readers;
|
||||||
|
|
||||||
|
use Blackbirdchess\Service\Import\Exceptions\InvalidFileException;
|
||||||
|
use Blackbirdchess\Service\Import\Interfaces\ReaderInterface;
|
||||||
use Blackbirdchess\Service\Results\Enums\Color;
|
use Blackbirdchess\Service\Results\Enums\Color;
|
||||||
use Blackbirdchess\Service\Results\Enums\Gender;
|
use Blackbirdchess\Service\Results\Enums\Gender;
|
||||||
use Blackbirdchess\Service\Results\Enums\Result;
|
use Blackbirdchess\Service\Results\Enums\Result;
|
||||||
@ -10,8 +12,9 @@ use Blackbirdchess\Service\Results\Pairing;
|
|||||||
use Blackbirdchess\Service\Results\Player;
|
use Blackbirdchess\Service\Results\Player;
|
||||||
use Blackbirdchess\Service\Results\Round;
|
use Blackbirdchess\Service\Results\Round;
|
||||||
use Blackbirdchess\Service\Results\Tournament;
|
use Blackbirdchess\Service\Results\Tournament;
|
||||||
|
use DateTime;
|
||||||
|
|
||||||
class Trf16 implements \Blackbirdchess\Service\Import\Interfaces\ReaderInterface
|
class Trf16 implements ReaderInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -32,7 +35,9 @@ class Trf16 implements \Blackbirdchess\Service\Import\Interfaces\ReaderInterface
|
|||||||
$this->Tournament = new Tournament();
|
$this->Tournament = new Tournament();
|
||||||
$this->playerIndexes['0000'] = NULL;
|
$this->playerIndexes['0000'] = NULL;
|
||||||
$this->playerIndexes[' '] = NULL;
|
$this->playerIndexes[' '] = NULL;
|
||||||
foreach ($file as $line) {
|
$linecount = count($file);
|
||||||
|
for ($lineno = 0; $lineno < count($file); $lineno++) {
|
||||||
|
$line = $file[$lineno];
|
||||||
$datatype = substr($line, 0, 3);
|
$datatype = substr($line, 0, 3);
|
||||||
|
|
||||||
switch($datatype) {
|
switch($datatype) {
|
||||||
@ -55,8 +60,17 @@ class Trf16 implements \Blackbirdchess\Service\Import\Interfaces\ReaderInterface
|
|||||||
case '112':
|
case '112':
|
||||||
$this->Tournament->addArbiter(substr($line, 4));
|
$this->Tournament->addArbiter(substr($line, 4));
|
||||||
break;
|
break;
|
||||||
|
case '132':
|
||||||
|
$this->readRoundData($line);
|
||||||
|
break;
|
||||||
case '001':
|
case '001':
|
||||||
|
if(!empty($this->Tournament->Rounds)) {
|
||||||
$this->readPlayerData($line);
|
$this->readPlayerData($line);
|
||||||
|
} elseif($lineno < $linecount) {
|
||||||
|
$file[] = $line;
|
||||||
|
} else {
|
||||||
|
throw new InvalidFileException();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -119,21 +133,20 @@ class Trf16 implements \Blackbirdchess\Service\Import\Interfaces\ReaderInterface
|
|||||||
$player->setId('Fide', (int)trim(substr($line, 57, 10)));
|
$player->setId('Fide', (int)trim(substr($line, 57, 10)));
|
||||||
$player->DateOfBirth = \DateTime::createFromFormat("Y/m/d", substr($line, 69, 10));
|
$player->DateOfBirth = \DateTime::createFromFormat("Y/m/d", substr($line, 69, 10));
|
||||||
$player->Points = (float)trim(substr($line, 80, 4));
|
$player->Points = (float)trim(substr($line, 80, 4));
|
||||||
$player->Rank = (float)trim(substr($line, 85, 3));
|
$player->Rank = (int)trim(substr($line, 85, 4));
|
||||||
|
|
||||||
$pairingData = substr($line, 91);
|
|
||||||
|
|
||||||
//read pairing round 1
|
//read pairing round 1
|
||||||
|
$position = 91;
|
||||||
|
$length = strlen($line);
|
||||||
|
$roundnum = 1;
|
||||||
|
do {
|
||||||
$pairing = new Pairing();
|
$pairing = new Pairing();
|
||||||
$round = new Round();
|
$pairing->Round = $roundnum;
|
||||||
$round->RoundNo = 1;
|
|
||||||
$round->Date = \DateTime::createFromFormat("y/m/d", '23/01/14');
|
|
||||||
$this->Tournament->addRound($round);
|
|
||||||
$pairing->Round = 1;
|
|
||||||
$pairing->Player = $player;
|
$pairing->Player = $player;
|
||||||
$pairing->OpponentIndex = substr($line, 91, 4);
|
$pairing->OpponentIndex = substr($line, $position, 4);
|
||||||
|
|
||||||
switch (trim(substr($line, 96, 1)))
|
switch (trim(substr($line, $position + 6, 1)))
|
||||||
{
|
{
|
||||||
case 'w':
|
case 'w':
|
||||||
$pairing->Color = Color::WHITE;
|
$pairing->Color = Color::WHITE;
|
||||||
@ -147,7 +160,7 @@ class Trf16 implements \Blackbirdchess\Service\Import\Interfaces\ReaderInterface
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (strtoupper(trim(substr($line, 98, 1))))
|
switch (strtoupper(trim(substr($line, $position + 8, 1))))
|
||||||
{
|
{
|
||||||
case '-':
|
case '-':
|
||||||
case 'Z':
|
case 'Z':
|
||||||
@ -177,7 +190,10 @@ class Trf16 implements \Blackbirdchess\Service\Import\Interfaces\ReaderInterface
|
|||||||
$pairing->Color = Result::NONE;
|
$pairing->Color = Result::NONE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
$position += 10;
|
||||||
|
$roundnum ++;
|
||||||
$this->Tournament->addPairing($pairing);
|
$this->Tournament->addPairing($pairing);
|
||||||
|
} while ($length > $position);
|
||||||
$this->playerIndexes[$player->InitialRank] = $player;
|
$this->playerIndexes[$player->InitialRank] = $player;
|
||||||
$this->Tournament->addPlayer($player);
|
$this->Tournament->addPlayer($player);
|
||||||
}
|
}
|
||||||
@ -188,4 +204,19 @@ class Trf16 implements \Blackbirdchess\Service\Import\Interfaces\ReaderInterface
|
|||||||
$pairing->Opponent = $this->playerIndexes[$pairing->OpponentIndex];
|
$pairing->Opponent = $this->playerIndexes[$pairing->OpponentIndex];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function readRoundData(string $line)
|
||||||
|
{
|
||||||
|
$position = 91;
|
||||||
|
$length = strlen($line);
|
||||||
|
$roundnum = 1;
|
||||||
|
do {
|
||||||
|
$round = new Round();
|
||||||
|
$round->Date = DateTime::createFromFormat('y/m/d', substr($line, $position, 8));
|
||||||
|
$round->RoundNo = $roundnum;
|
||||||
|
$this->Tournament->addRound($round);
|
||||||
|
$position += 10;
|
||||||
|
$roundnum ++;
|
||||||
|
} while ($length > $position);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -102,8 +102,22 @@ class Trf16Test extends TestCase
|
|||||||
{
|
{
|
||||||
$this->assertEquals(3, $this->testobject->Tournament->Players[0]->Rank);
|
$this->assertEquals(3, $this->testobject->Tournament->Players[0]->Rank);
|
||||||
}
|
}
|
||||||
|
public function testReadTournamentRound1Date(): void
|
||||||
|
{
|
||||||
|
$expected = DateTime::createFromFormat("Y/m/d", "2023/01/14");
|
||||||
|
$this->assertEquals($expected, $this->testobject->Tournament->roundByNo(1)->Date);
|
||||||
|
}
|
||||||
|
public function testReadTournamentRound3Date(): void
|
||||||
|
{
|
||||||
|
$expected = DateTime::createFromFormat("Y/m/d", "2023/01/14");
|
||||||
|
$this->assertEquals($expected, $this->testobject->Tournament->roundByNo(3)->Date);
|
||||||
|
}
|
||||||
public function testReadPlayerPairing1Opponent(): void
|
public function testReadPlayerPairing1Opponent(): void
|
||||||
{
|
{
|
||||||
$this->assertEquals($this->testobject->Tournament->Players[7], $this->testobject->Tournament->Players[0]->Pairings[0]->Opponent);
|
$this->assertEquals($this->testobject->Tournament->Players[7], $this->testobject->Tournament->Players[0]->Pairings[0]->Opponent);
|
||||||
}
|
}
|
||||||
|
public function testReadPlayerPairing3Opponent(): void
|
||||||
|
{
|
||||||
|
$this->assertEquals($this->testobject->Tournament->Players[1], $this->testobject->Tournament->Players[0]->Pairings[2]->Opponent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user