Finalized reading of tournament data

This commit is contained in:
Jeroen De Meerleer 2019-01-19 14:14:01 +01:00
parent f6025fa557
commit 1b92d4d8d1
6 changed files with 166 additions and 17 deletions

View File

@ -4,7 +4,8 @@
"keywords": ["chess", "frbe-kbsb", "pairtwo"],
"license": "MIT",
"require": {
"php": "^7.1"
"php": "^7.1",
"myclabs/php-enum": "^1.6"
},
"require-dev": {
"phpunit/phpunit": "^7.0",

Binary file not shown.

View File

@ -35,6 +35,7 @@ class Tournament
{
private $Name;
private $Organiser;
private $OrganiserClubNo;
private $OrganiserClub;
private $OrganiserPlace;
private $OrganiserCountry;
@ -47,6 +48,9 @@ class Tournament
private $Tempo;
private $NonRatedElo;
private $System;
private $FirstPeriod;
private $SecondPeriod;
private $Federation;
/**
* @return string
@ -81,7 +85,7 @@ class Tournament
}
/**
* @return integer
* @return String
*/
public function getOrganiserClub()
{
@ -89,13 +93,29 @@ class Tournament
}
/**
* @param integer $OrganiserClub
* @param String $OrganiserClub
*/
public function setOrganiserClub($OrganiserClub): void
{
$this->OrganiserClub = $OrganiserClub;
}
/**
* @return integer
*/
public function getOrganiserClubNo()
{
return $this->OrganiserClubNo;
}
/**
* @param integer $OrganiserClubno
*/
public function setOrganiserClubNo($OrganiserClubNo): void
{
$this->OrganiserClubNo = $OrganiserClubNo;
}
/**
* @return string
*/
@ -257,7 +277,7 @@ class Tournament
}
/**
* @return integer
* @return TournamentSystem
*/
public function getSystem()
{
@ -265,12 +285,60 @@ class Tournament
}
/**
* @param integer $System
* @param TournamentSystem $System
*/
public function setSystem($System): void
{
$this->System = $System;
}
/**
* @return String
*/
public function getFirstPeriod()
{
return $this->FirstPeriod;
}
/**
* @param String $FirstPeriod
*/
public function setFirstPeriod($FirstPeriod): void
{
$this->FirstPeriod = $FirstPeriod;
}
/**
* @return String
*/
public function getSecondPeriod()
{
return $this->SecondPeriod;
}
/**
* @param String $SecondPeriod
*/
public function setSecondPeriod($SecondPeriod): void
{
$this->SecondPeriod = $SecondPeriod;
}
/**
* @return String
*/
public function getFederation()
{
return $this->Federation;
}
/**
* @param String $Federation
*/
public function setFederation($Federation): void
{
$this->Federation = $Federation;
}
}

View File

@ -0,0 +1,19 @@
<?php
/**
* Created by PhpStorm.
* User: jeroen
* Date: 19/01/19
* Time: 12:23
*/
namespace JeroenED\Libpairtwo\Models;
use MyCLabs\Enum\Enum;
class TournamentSystem extends Enum
{
const Swiss = 0;
const Closed = 2;
const American = 4;
const Imperial = 6;
}

View File

@ -28,6 +28,7 @@ namespace JeroenED\Libpairtwo;
use JeroenED\Libpairtwo\Models\Tournament;
use JeroenED\Libpairtwo\Models\Sws as MyModel;
use JeroenED\Libpairtwo\Models\TournamentSystem;
/**
* This class reads a SWS file
@ -275,7 +276,6 @@ class Sws
// StartDate
$length = 4;
//echo self::readhexdata(substr($swscontents, $offset, $length));
$sws->getTournament()->setStartDate(self::UIntToTimestamp(hexdec(self::readhexdata(substr($swscontents, $offset, $length)))));
$offset += $length;
@ -284,6 +284,63 @@ class Sws
$sws->getTournament()->setEndDate(self::UIntToTimestamp(hexdec(self::readhexdata(substr($swscontents, $offset, $length)))));
$offset += $length;
// Place
$length = 36;
$sws->getTournament()->setOrganiserPlace(substr($swscontents, $offset, $length));
$offset += $length;
// First period
$length = 32;
$sws->getTournament()->setFirstPeriod(substr($swscontents, $offset, $length));
$offset += $length;
// Second period
$length = 32;
$sws->getTournament()->setSecondPeriod(substr($swscontents, $offset, $length));
$offset += $length;
// Unrated Elo
$length = 4;
$sws->getTournament()->setNonRatedElo(hexdec(self::readhexdata(substr($swscontents, $offset, $length))));
$offset += $length;
// Type
$length = 4;
$sws->getTournament()->setSystem(new TournamentSystem(hexdec(self::readhexdata(substr($swscontents, $offset, $length)))));
$offset += $length;
// Federation
$length = 12;
$sws->getTournament()->setFederation(substr($swscontents, $offset, $length));
$offset += $length;
// Soustype
/*
* 32 Bits:
* 1 bit = Libre?
* 6 bits = First round sent to FIDE
* 6 bits = First round sent to FRBE-KBSB
* 6 bits = Last round sent to FIDE
* 6 bits = Last round sent to FRBE-KBSB
* 6 bits = Number of the First board
* 1 bit = Double round robin
*/
$length = 4;
$sws->setBinaryData('SousType', self::readhexdata(substr($swscontents, $offset, $length)));
$offset += $length;
// Organising club no
$length = 4;
$sws->getTournament()->setOrganiserClubNo(substr($swscontents, $offset, $length));
echo dechex($offset);
$offset += $length;
// Organising club
$length = 12;
$sws->getTournament()->setOrganiserClub(substr($swscontents, $offset, $length));
$offset += $length;
return $sws;
}

View File

@ -28,16 +28,20 @@ Use JeroenED\Libpairtwo\Sws;
require_once '../vendor/autoload.php';
$sws = Sws::readSws('../res/testsws.sws');
echo "Name: " . $sws->getTournament()->getName() . "\n";
echo "Organiser: " . $sws->getTournament()->getOrganiser(). "\n";
echo "Tempo: " . $sws->getTournament()->getTempo() . "\n";
echo "Country: " . $sws->getTournament()->getOrganiserCountry() . "\n";
echo "Arbiter: " . $sws->getTournament()->getArbiter() . "\n";
echo "Rounds: " . $sws->getTournament()->getRounds() . "\n";
echo "Participants: " . $sws->getTournament()->getRounds() . "\n";
echo "Fidehomol: " . $sws->getTournament()->getFideHomol() . "\n";
echo "Start-Date: " . $sws->getTournament()->getStartDate()->format('d/m/Y') . "\n";
echo "Start-Date: " . $sws->getTournament()->getEndDate()->format('d/m/Y') . "\n";
//echo "Start-Date hex: " . $sws->getBinaryData("startdate") . "\n";
echo "Name: " . $sws->getTournament()->getName() . PHP_EOL;
echo "Organiser: " . $sws->getTournament()->getOrganiser(). PHP_EOL;
echo "Tempo: " . $sws->getTournament()->getTempo() . PHP_EOL;
echo "Country: " . $sws->getTournament()->getOrganiserCountry() . PHP_EOL;
echo "Arbiter: " . $sws->getTournament()->getArbiter() . PHP_EOL;
echo "Rounds: " . $sws->getTournament()->getRounds() . PHP_EOL;
echo "Participants: " . $sws->getTournament()->getRounds() . PHP_EOL;
echo "Fidehomol: " . $sws->getTournament()->getFideHomol() . PHP_EOL;
echo "Start-Date: " . $sws->getTournament()->getStartDate()->format('d/m/Y') . PHP_EOL;
echo "End-Date: " . $sws->getTournament()->getEndDate()->format('d/m/Y') . PHP_EOL;
echo "System: " . $sws->getTournament()->getSystem()->getKey() . PHP_EOL;
echo "Place: " . $sws->getTournament()->getOrganiserPlace() . PHP_EOL;
echo "Unrated-Elo: " . $sws->getTournament()->getNonRatedElo() . PHP_EOL;
echo "Federatiop: " . $sws->getTournament()->getFederation() . PHP_EOL;
echo "Organiser: " . $sws->getTournament()->getOrganiserClubNo() . PHP_EOL;
//echo $sws->getBinaryData("Tournament");
//echo $sws->getBinaryData("Players");