Reading out several tournament fields

This commit is contained in:
Jeroen De Meerleer 2019-01-18 18:11:53 +01:00
parent 6341b7740b
commit 584492f5f4
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6
2 changed files with 75 additions and 5 deletions

View File

@ -36,6 +36,13 @@ use JeroenED\Libpairtwo\Models\Sws as MyModel;
*/ */
class Sws class Sws
{ {
private const PT_DAYFACTOR = 32;
private const PT_MONTHFACTOR = 16;
private const PT_YEARFACTOR = 512;
private const PT_SYSTEMYEAR = 1900;
private const PT_PASTOFFSET = 117;
/** /**
* @param string $swsfile * @param string $swsfile
* @return MyModel * @return MyModel
@ -251,13 +258,70 @@ class Sws
$sws->getTournament()->setArbiter(substr($swscontents, $offset, $length)); $sws->getTournament()->setArbiter(substr($swscontents, $offset, $length));
$offset += $length; $offset += $length;
// Rounds
$length = 4;
$sws->getTournament()->setRounds(hexdec(substr($swscontents, $offset, $length)));
$offset += $length;
// Participants
$length = 4;
$sws->getTournament()->setParticipants(hexdec(substr($swscontents, $offset, $length)));
$offset += $length;
// Fidehomol
$length = 4;
$sws->getTournament()->setFideHomol(hexdec(substr($swscontents, $offset, $length)));
$offset += $length;
// StartDate
$length = 4;
//echo self::readhexdata(substr($swscontents, $offset, $length));
$sws->getTournament()->setStartDate(self::UIntToTimestamp(hexdec(self::readhexdata(substr($swscontents, $offset, $length)))));
$offset += $length;
// EndDate
$length = 4;
$sws->getTournament()->setEndDate(self::UIntToTimestamp(hexdec(self::readhexdata(substr($swscontents, $offset, $length)))));
$offset += $length;
return $sws; return $sws;
} }
private static function ReadHexData(String $data) private static function ReadHexData(String $data)
{ {
$hex = implode(unpack("H*", $data)); $hex = implode(unpack("H*", $data));
$hex = implode(array_reverse(str_split($hex, 2)));
$hex = str_replace("00", "", $hex); $hex = str_replace("00", "", $hex);
return $hex; return $hex;
} }
private static function UIntToTimestamp($date)
{
//echo $date;
$curyear = date('Y');
$yearoffset = $curyear - self::PT_PASTOFFSET;
//$yearoffset = 100;
// Day
$day = $date % self::PT_DAYFACTOR;
if ($day < 1) {
$day = 1;
}
// Month
$month = ($date / self::PT_DAYFACTOR) % self::PT_MONTHFACTOR;
if ($month < 1) {
$month = 1;
}
// Year
$year = ($date / self::PT_YEARFACTOR) + $yearoffset;
$concat = $month . '/' . $day . '/' . intval($year);
$format = 'm/d/Y';
echo $concat;
return \DateTime::createFromFormat($format, $concat);
}
} }

View File

@ -28,10 +28,16 @@ Use JeroenED\Libpairtwo\Sws;
require_once '../vendor/autoload.php'; require_once '../vendor/autoload.php';
$sws = Sws::readSws('../res/testsws.sws'); $sws = Sws::readSws('../res/testsws.sws');
echo "Name: " . $sws->getTournament()->getName() . "\n"; echo "Name: " . $sws->getTournament()->getName() . "\n";
echo "Organiser: " . $sws->getTournament()->getOrganiser(). "\n"; echo "Organiser: " . $sws->getTournament()->getOrganiser(). "\n";
echo "Tempo: " . $sws->getTournament()->getTempo() . "\n"; echo "Tempo: " . $sws->getTournament()->getTempo() . "\n";
echo "Country: " . $sws->getTournament()->getOrganiserCountry() . "\n"; echo "Country: " . $sws->getTournament()->getOrganiserCountry() . "\n";
echo "Arbiter: " . $sws->getTournament()->getArbiter() . "\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 $sws->getBinaryData("Tournament"); //echo $sws->getBinaryData("Tournament");
//echo $sws->getBinaryData("Players"); //echo $sws->getBinaryData("Players");