Compare commits
3 Commits
754e070cd7
...
3532386aef
Author | SHA1 | Date | |
---|---|---|---|
3532386aef | |||
2d7788dcc0 | |||
510e5baac3 |
9
.gitignore
vendored
9
.gitignore
vendored
@ -1,2 +1,9 @@
|
||||
/vendor/
|
||||
# Jetbrains
|
||||
.idea/
|
||||
|
||||
# Composer
|
||||
/vendor/
|
||||
|
||||
# PHPUnit
|
||||
/.phpunit.cache
|
||||
.phpunit.result.cache
|
||||
|
@ -22,6 +22,7 @@
|
||||
"blackbirdchess/blackbirdchess-service-results": "dev-main"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^9"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
@ -30,8 +31,12 @@
|
||||
},
|
||||
"config": {
|
||||
"platform": {
|
||||
"php": "7.1"
|
||||
"php": "8.1"
|
||||
},
|
||||
"sort-packages": true
|
||||
}
|
||||
},
|
||||
"repositories": [{
|
||||
"type": "composer",
|
||||
"url": "https://repo.blackbirdchess.app"
|
||||
}]
|
||||
}
|
||||
|
1796
composer.lock
generated
Normal file
1796
composer.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
BIN
res/Blackbird Chess Unit Test Tournament.ods
Normal file
BIN
res/Blackbird Chess Unit Test Tournament.ods
Normal file
Binary file not shown.
BIN
res/Pairtwo5-testfile.sws
Normal file
BIN
res/Pairtwo5-testfile.sws
Normal file
Binary file not shown.
BIN
res/Pairtwo6-testfile.sws
Normal file
BIN
res/Pairtwo6-testfile.sws
Normal file
Binary file not shown.
BIN
res/Swar5-testfile.swar
Normal file
BIN
res/Swar5-testfile.swar
Normal file
Binary file not shown.
@ -1,16 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Reader Pairtwo6
|
||||
*
|
||||
* Reads out Pairtwo-6 and Pairtwo-5 files
|
||||
*
|
||||
* @author Jeroen De Meerleer <schaak@jeroened.be>
|
||||
* @category Main
|
||||
* @package Libpairtwo
|
||||
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
|
||||
*/
|
||||
|
||||
namespace Blackbirdchess\Service\Import\Readers;
|
||||
|
||||
use DateTime;
|
||||
@ -21,8 +10,8 @@ use Blackbirdchess\Service\Results\Enums\Result;
|
||||
use Blackbirdchess\Service\Results\Enums\Tiebreak;
|
||||
use Blackbirdchess\Service\Results\Enums\Title;
|
||||
use Blackbirdchess\Service\Results\Enums\TournamentSystem;
|
||||
use Blackbirdchess\Service\Results\Exceptions\IncompatibleReaderException;
|
||||
use Blackbirdchess\Service\Results\Interfaces\ReaderInterface;
|
||||
use Blackbirdchess\Service\Import\Exceptions\IncompatibleReaderException;
|
||||
use Blackbirdchess\Service\Import\Interfaces\ReaderInterface;
|
||||
use Blackbirdchess\Service\Results\Pairing;
|
||||
use Blackbirdchess\Service\Results\Player;
|
||||
use Blackbirdchess\Service\Results\Round;
|
||||
|
@ -43,7 +43,7 @@ class Swar5 implements ReaderInterface
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public const COMPATIBLE_VERSIONS = ['v5.'];
|
||||
public const COMPATIBLE_VERSIONS = '(v5\.[0-9]{2}|v6.00)';
|
||||
|
||||
public const TEMPOS = [
|
||||
[
|
||||
@ -208,7 +208,7 @@ class Swar5 implements ReaderInterface
|
||||
if($compatversion != '') {
|
||||
$this->Release == $compatversion;
|
||||
}
|
||||
if (array_search(substr($this->Release, 0, 3), self::COMPATIBLE_VERSIONS) === false) {
|
||||
if (preg_match(self::COMPATIBLE_VERSIONS, $this->Release) === false) {
|
||||
throw new IncompatibleReaderException("This file was not created with Swar 5");
|
||||
}
|
||||
|
||||
|
@ -1,105 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* The MIT License
|
||||
*
|
||||
* Copyright 2019 Jeroen De Meerleer <schaak@jeroened.be>.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
use Blackbirdchess\Service\Import\IOFactory;
|
||||
|
||||
require_once '../vendor/autoload.php';
|
||||
|
||||
$sws = IOFactory::createReader('Swar-4');
|
||||
$sws->read('../res/testswar.swar');
|
||||
|
||||
echo "Release: " . $sws->Release . PHP_EOL;
|
||||
echo "Name: " . $sws->Tournament->Name . PHP_EOL;
|
||||
echo "Organiser: " . $sws->Tournament->Organiser . PHP_EOL;
|
||||
echo "TempoIndex: " . $sws->Tournament->TempoIndex . PHP_EOL;
|
||||
echo "TempoType: " . $sws->Tournament->TournoiStd . PHP_EOL;
|
||||
echo "Tempo: " . $sws->Tournament->Tempo . PHP_EOL;
|
||||
echo "Place: " . $sws->Tournament->OrganiserPlace . PHP_EOL;
|
||||
echo "Arbiter 1: " . $sws->Tournament->Arbiters[ 0 ] . PHP_EOL;
|
||||
echo "Arbiter 2: " . $sws->Tournament->Arbiters[ 1 ] . PHP_EOL;
|
||||
echo "Rounds: " . $sws->Tournament->NoOfRounds . PHP_EOL;
|
||||
echo "Fidehomol: " . $sws->Tournament->FideHomol . PHP_EOL;
|
||||
echo "Start-Date: " . $sws->Tournament->StartDate->format('d/m/Y') . PHP_EOL;
|
||||
echo "End-Date: " . $sws->Tournament->EndDate->format('d/m/Y') . PHP_EOL;
|
||||
echo "System: " . $sws->Tournament->System->getKey() . PHP_EOL;
|
||||
echo "Place: " . $sws->Tournament->OrganiserPlace . PHP_EOL;
|
||||
echo "Unrated-Elo: " . $sws->Tournament->NonRatedElo . PHP_EOL;
|
||||
echo "Federation: " . $sws->Tournament->Federation . PHP_EOL;
|
||||
echo "Organiser: " . $sws->Tournament->OrganiserClubNo . PHP_EOL;
|
||||
echo "Fide Elo P1: " . $sws->Tournament->PlayerById(0)->getElo('Fide') . PHP_EOL;
|
||||
echo "Fide Elo P2: " . $sws->Tournament->PlayerById(1)->getElo('Fide') . PHP_EOL;
|
||||
echo "Fide Elo P3: " . $sws->Tournament->PlayerById(2)->getElo('Fide') . PHP_EOL;
|
||||
echo "KBSB Elo P1: " . $sws->Tournament->PlayerById(0)->getElo('Nation') . PHP_EOL;
|
||||
echo "KBSB Elo P2: " . $sws->Tournament->PlayerById(1)->getElo('Nation') . PHP_EOL;
|
||||
echo "KBSB Elo P3: " . $sws->Tournament->PlayerById(2)->getElo('Nation') . PHP_EOL;
|
||||
echo "Name P1: " . $sws->Tournament->PlayerById(0)->Name . PHP_EOL;
|
||||
echo "Name P2: " . $sws->Tournament->PlayerById(1)->Name . PHP_EOL;
|
||||
echo "Name P3: " . $sws->Tournament->PlayerById(2)->Name . PHP_EOL;
|
||||
echo "Gender P1: " . $sws->Tournament->PlayerById(0)->Gender->getKey() . PHP_EOL;
|
||||
echo "Gender P2: " . $sws->Tournament->PlayerById(1)->Gender->getKey() . PHP_EOL;
|
||||
echo "Gender P3: " . $sws->Tournament->PlayerById(2)->Gender->getKey() . PHP_EOL;
|
||||
echo "Absent P1: " . $sws->Tournament->PlayerById(0)->Absent . PHP_EOL;
|
||||
echo "Absent P2: " . $sws->Tournament->PlayerById(1)->Absent . PHP_EOL;
|
||||
echo "Absent P3: " . $sws->Tournament->PlayerById(2)->Absent . PHP_EOL;
|
||||
echo "Category P1: " . $sws->Tournament->PlayerById(0)->Category . PHP_EOL;
|
||||
echo "Category P2: " . $sws->Tournament->PlayerById(1)->Category . PHP_EOL;
|
||||
echo "Category P3: " . $sws->Tournament->PlayerById(2)->Category . PHP_EOL;
|
||||
echo "Date Round 1: " . $sws->Tournament->RoundByNo(0)->Date->format('d/m/Y') . PHP_EOL;
|
||||
echo "Date Round 2: " . $sws->Tournament->RoundByNo(1)->Date->format('d/m/Y') . PHP_EOL;
|
||||
echo "Date Round 3: " . $sws->Tournament->RoundByNo(2)->Date->format('d/m/Y') . PHP_EOL;
|
||||
echo "Game Round 1: " . $sws->Tournament->RoundByNo(0)->Games[ 0 ]->Result->getValue() . PHP_EOL;
|
||||
echo "Game Round 2: " . $sws->Tournament->RoundByNo(1)->Games[ 0 ]->Result->getValue() . PHP_EOL;
|
||||
echo "Game Round 3: " . $sws->Tournament->RoundByNo(2)->Games[ 0 ]->Result->getValue() . PHP_EOL;
|
||||
echo "Color Pairing 1: " . $sws->Tournament->Pairings[ 1 ]->Color->getKey() . PHP_EOL;
|
||||
echo "Color Pairing 2: " . $sws->Tournament->Pairings[ 2 ]->Color->getKey() . PHP_EOL;
|
||||
echo "Color Pairing 3: " . $sws->Tournament->Pairings[ 3 ]->Color->getKey() . PHP_EOL;
|
||||
echo "Player Pairing 1: " . $sws->Tournament->Pairings[ 0 ]->Player->Name . PHP_EOL;
|
||||
echo "Player Pairing 2: " . $sws->Tournament->Pairings[ 1 ]->Player->Name . PHP_EOL;
|
||||
echo "Player Pairing 3: " . $sws->Tournament->Pairings[ 2 ]->Player->Name . PHP_EOL;
|
||||
echo "Bye Round 1: " . $sws->Tournament->RoundByNo(2)->Bye[ 0 ]->Player->Name . PHP_EOL;
|
||||
echo "Absent Round 1: " . $sws->Tournament->RoundByNo(2)->Absent[ 0 ]->Player->Name . PHP_EOL;
|
||||
echo "Tiebreak 1: " . $sws->Tournament->Tiebreaks[ 0 ]->getValue() . PHP_EOL;
|
||||
echo "Tiebreak 2: " . $sws->Tournament->Tiebreaks[ 1 ]->getValue() . PHP_EOL;
|
||||
echo "Tiebreak 3: " . $sws->Tournament->Tiebreaks[ 2 ]->getValue() . PHP_EOL;
|
||||
echo "Tiebreak 4: " . $sws->Tournament->Tiebreaks[ 3 ]->getValue() . PHP_EOL;
|
||||
echo "Tiebreak 5: " . $sws->Tournament->Tiebreaks[ 4 ]->getValue() . PHP_EOL;
|
||||
echo "Tiebreak 6: " . $sws->Tournament->Tiebreaks[ 5 ]->getValue() . PHP_EOL;
|
||||
echo "Average Elo: " . $sws->Tournament->AverageElo . PHP_EOL;
|
||||
foreach ($sws->Tournament->RankingForCategory('+2500') as $player) {
|
||||
echo str_pad($player->Name . '(' . $player->getElo($sws->Tournament->PriorityElo) . ') ', 35) .
|
||||
implode_pad(' ', $player->Tiebreaks, 5, ' ') .
|
||||
PHP_EOL;
|
||||
}
|
||||
|
||||
function implode_pad($glue, $collection, $padlength, $padstring): string
|
||||
{
|
||||
$newarray = [];
|
||||
foreach ($collection as $elem) {
|
||||
$newarray[] = str_pad($elem, $padlength, $padstring);
|
||||
}
|
||||
|
||||
return implode($glue, $newarray);
|
||||
}
|
44
tests/Readers/Pairtwo6Test.php
Normal file
44
tests/Readers/Pairtwo6Test.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Blackbirdchess\Tests\Service\Import\Readers;
|
||||
|
||||
use Blackbirdchess\Service\Import\Readers\Pairtwo6;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class Pairtwo6Test extends TestCase
|
||||
{
|
||||
private string $testfile = '/res/Pairtwo6-testfile.sws';
|
||||
private Pairtwo6 $testobject;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->testfile = getcwd() . $this->testfile;
|
||||
$this->testobject = new Pairtwo6();
|
||||
$this->testobject->read($this->testfile);
|
||||
}
|
||||
|
||||
public function testReadTournamentName(): void
|
||||
{
|
||||
$this->assertEquals('Blackbird Chess Unit Test Tournament', $this->testobject->Tournament->Name);
|
||||
}
|
||||
|
||||
public function testReadTournamentOrganiser(): void
|
||||
{
|
||||
$this->assertEquals('Blackbird Chess Developers', $this->testobject->Tournament->Organiser);
|
||||
}
|
||||
|
||||
public function testReadTournamentLocation(): void
|
||||
{
|
||||
$this->assertEquals('Waregem', $this->testobject->Tournament->OrganiserPlace);
|
||||
}
|
||||
|
||||
public function testHas8Players(): void
|
||||
{
|
||||
$this->assertCount(8, $this->testobject->Tournament->Players);
|
||||
}
|
||||
|
||||
public function testHas7Rounds(): void
|
||||
{
|
||||
$this->assertCount(7, $this->testobject->Tournament->Rounds);
|
||||
}
|
||||
}
|
44
tests/Readers/Swar5Test.php
Normal file
44
tests/Readers/Swar5Test.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Blackbirdchess\Tests\Service\Import\Readers;
|
||||
|
||||
use Blackbirdchess\Service\Import\Readers\Swar5;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class Swar5Test extends TestCase
|
||||
{
|
||||
private string $swarfile = '/res/Swar5-testfile.swar';
|
||||
private Swar5 $testobject;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->swarfile = getcwd() . $this->swarfile;
|
||||
$this->testobject = new Swar5();
|
||||
$this->testobject->read($this->swarfile);
|
||||
}
|
||||
|
||||
public function testReadTournamentName(): void
|
||||
{
|
||||
$this->assertEquals('Blackbird Chess Unit Test Tournament', $this->testobject->Tournament->Name);
|
||||
}
|
||||
|
||||
public function testReadTournamentOrganiser(): void
|
||||
{
|
||||
$this->assertEquals('Blackbird Chess Developers', $this->testobject->Tournament->Organiser);
|
||||
}
|
||||
|
||||
public function testReadTournamentLocation(): void
|
||||
{
|
||||
$this->assertEquals('Waregem', $this->testobject->Tournament->OrganiserPlace);
|
||||
}
|
||||
|
||||
public function testHas8Players(): void
|
||||
{
|
||||
$this->assertCount(8, $this->testobject->Tournament->Players);
|
||||
}
|
||||
|
||||
public function testHas7Rounds(): void
|
||||
{
|
||||
$this->assertCount(7, $this->testobject->Tournament->Rounds);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user