ENHANCEMENT: The template provides a more usable starting implementation

This commit is contained in:
Jeroen De Meerleer 2019-09-28 00:41:40 +02:00
parent b445f2f301
commit 25c91c5242
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6
3 changed files with 100 additions and 91 deletions

View File

@ -4,6 +4,8 @@
* NEW READER: `Reader::swar-4` for reading out files created with Swar version 4.
* NEW FEATURE: `Tournament::getArbiters()` for multiple arbiters in 1 tournament
* ENHANCEMENT: `Class::getBinaryData()` methods return null if field is non-existent
* ENHANCEMENT: The template in distributions provides a more usable starting implementation
* ENHANCEMENT: The template in distributions is renamed to template.php
* CHANGE: `Tournament::getArbiter()` accepts a `int` parameter representing the order of the arbiters
* BUGFIX: `Player:getId()` returned elo instead of id
* BUGFIX: `Tournament::calculateBuchholz()` did not return the correct score when player had unplayed rounds

91
dist/boilerplate.php vendored
View File

@ -1,91 +0,0 @@
<?php
use JeroenED\Libpairtwo\IOFactory;
require_once 'vendor/autoload.php';
// EDIT ME!
$pairingfile = 'your pairing-file.sws';
$fileformat = 'Pairtwo-6'; // Possible values: Pairtwo-5, Pairtwo-6, Swar-4
if (!file_exists($pairingfile)) {
trigger_error('Your file is not set or doesn\'t exist! Edit the file: ' . __FILE__ . ' and try again', E_USER_ERROR);
}
$reader = IOFactory::createReader($fileformat);
$reader->read($pairingfile);
// From here on you can start. Please use the examples on https://github.com/jeroened/libpairtwo/wiki
// You can also use the doc/api folder to get all possible methods and fields
// Below is an example of what can be used. Feel free to modify this.
echo "<pre>";
echo "Name: " . $reader->getTournament()->getName() . PHP_EOL;
echo "Organiser: " . $reader->getTournament()->getOrganiser(). PHP_EOL;
echo "Tempo: " . $reader->getTournament()->getTempo() . PHP_EOL;
echo "Country: " . $reader->getTournament()->getOrganiserCountry() . PHP_EOL;
echo "Arbiter 1: " . $reader->getTournament()->getArbiter(0) . PHP_EOL;
echo "Arbiter 2: " . $reader->getTournament()->getArbiter(1) . PHP_EOL;
echo "Rounds: " . $reader->getTournament()->getNoOfRounds() . PHP_EOL;
echo "Participants: " . $reader->getTournament()->getParticipants() . PHP_EOL;
echo "Fidehomol: " . $reader->getTournament()->getFideHomol() . PHP_EOL;
echo "Start-Date: " . $reader->getTournament()->getStartDate()->format('d/m/Y') . PHP_EOL;
echo "End-Date: " . $reader->getTournament()->getEndDate()->format('d/m/Y') . PHP_EOL;
echo "System: " . $reader->getTournament()->getSystem()->getKey() . PHP_EOL;
echo "Place: " . $reader->getTournament()->getOrganiserPlace() . PHP_EOL;
echo "Unrated-Elo: " . $reader->getTournament()->getNonRatedElo() . PHP_EOL;
echo "Federation: " . $reader->getTournament()->getFederation() . PHP_EOL;
echo "Organiser: " . $reader->getTournament()->getOrganiserClubNo() . PHP_EOL;
echo "Fide Elo P1: " . $reader->getTournament()->getPlayerById(0)->getElo('Fide') . PHP_EOL;
echo "Fide Elo P2: " . $reader->getTournament()->getPlayerById(1)->getElo('Fide') . PHP_EOL;
echo "Fide Elo P3: " . $reader->getTournament()->getPlayerById(2)->getElo('Fide') . PHP_EOL;
echo "KBSB Elo P1: " . $reader->getTournament()->getPlayerById(0)->getElo('Nation') . PHP_EOL;
echo "KBSB Elo P2: " . $reader->getTournament()->getPlayerById(1)->getElo('Nation') . PHP_EOL;
echo "KBSB Elo P3: " . $reader->getTournament()->getPlayerById(2)->getElo('Nation') . PHP_EOL;
echo "Name P1: " . $reader->getTournament()->getPlayerById(0)->getName() . PHP_EOL;
echo "Name P2: " . $reader->getTournament()->getPlayerById(1)->getName() . PHP_EOL;
echo "Name P3: " . $reader->getTournament()->getPlayerById(2)->getName() . PHP_EOL;
echo "Gender P1: " . $reader->getTournament()->getPlayerById(0)->getGender()->getKey() . PHP_EOL;
echo "Gender P2: " . $reader->getTournament()->getPlayerById(1)->getGender()->getKey() . PHP_EOL;
echo "Gender P3: " . $reader->getTournament()->getPlayerById(2)->getGender()->getKey() . PHP_EOL;
echo "Absent P1: " . $reader->getTournament()->getPlayerById(0)->getBinaryData("Absent") . PHP_EOL;
echo "Absent P2: " . $reader->getTournament()->getPlayerById(1)->getBinaryData("Absent") . PHP_EOL;
echo "Absent P3: " . $reader->getTournament()->getPlayerById(2)->getBinaryData("Absent") . PHP_EOL;
echo "Date Round 1: " . $reader->getTournament()->getRoundByNo(0)->getDate()->format('d/m/Y') . PHP_EOL;
echo "Date Round 2: " . $reader->getTournament()->getRoundByNo(1)->getDate()->format('d/m/Y') . PHP_EOL;
echo "Date Round 3: " . $reader->getTournament()->getRoundByNo(2)->getDate()->format('d/m/Y') . PHP_EOL;
echo "Game Round 1: " . $sws->getTournament()->getRoundByNo(0)->getGames()[0]->getResult()->getValue() . PHP_EOL;
echo "Game Round 2: " . $sws->getTournament()->getRoundByNo(1)->getGames()[0]->getResult()->getValue() . PHP_EOL;
echo "Game Round 3: " . $sws->getTournament()->getRoundByNo(2)->getGames()[0]->getResult()->getValue() . PHP_EOL;
echo "Color Pairing 1: " . $reader->getTournament()->getPairings()[1]->getColor()->getKey() . PHP_EOL;
echo "Color Pairing 2: " . $reader->getTournament()->getPairings()[2]->getColor()->getKey() . PHP_EOL;
echo "Color Pairing 3: " . $reader->getTournament()->getPairings()[3]->getColor()->getKey() . PHP_EOL;
echo "Player Pairing 1: " . $reader->getTournament()->getPairings()[0]->getPlayer()->getName() . PHP_EOL;
echo "Player Pairing 2: " . $reader->getTournament()->getPairings()[1]->getPlayer()->getName() . PHP_EOL;
echo "Player Pairing 3: " . $reader->getTournament()->getPairings()[2]->getPlayer()->getName() . PHP_EOL;
echo "Bye Round 1: " . $reader->getTournament()->getRoundByNo(2)->getBye()[0]->getPlayer()->getName() . PHP_EOL;
echo "Absent Round 1: " . $reader->getTournament()->getRoundByNo(2)->getAbsent()[0]->getPlayer()->getName() . PHP_EOL;
echo "Tiebreak 1: " . $reader->getTournament()->getTiebreaks()[0]->getValue() . PHP_EOL;
echo "Tiebreak 2: " . $reader->getTournament()->getTiebreaks()[1]->getValue() . PHP_EOL;
echo "Tiebreak 3: " . $reader->getTournament()->getTiebreaks()[2]->getValue() . PHP_EOL;
echo "Tiebreak 4: " . $reader->getTournament()->getTiebreaks()[3]->getValue() . PHP_EOL;
echo "Tiebreak 5: " . $reader->getTournament()->getTiebreaks()[4]->getValue() . PHP_EOL;
echo "Tiebreak 6: " . $reader->getTournament()->getTiebreaks()[5]->getValue() . PHP_EOL;
echo "Average Elo: " . $reader->getTournament()->getAverageElo() . PHP_EOL;
foreach ($reader->getTournament()->getRanking() as $player) {
echo str_pad($player->getName() . '(' . $player->getElo($reader->getTournament()->getPriorityElo()) . ') ', 35) . implode_pad(' ', $player->getTiebreaks(), 5, ' ') . PHP_EOL;
}
echo "</pre>";
function implode_pad($glue, $collection, $padlength, $padstring): string
{
$newarray = [];
foreach ($collection as $elem) {
$newarray[] = str_pad($elem, $padlength, $padstring);
}
return implode($glue, $newarray);
}

98
dist/template.php vendored Normal file
View File

@ -0,0 +1,98 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>The HTML5 Herald</title>
<meta name="description" content="Libpairtwo">
<meta name="author" content="The clubclub">
<link rel="stylesheet" href="css/styles.css">
</head>
<body>
<?php
use JeroenED\Libpairtwo\IOFactory;
require_once 'vendor/autoload.php';
// EDIT ME!
$pairingfile = 'your pairing-file.sws';
$fileformat = 'Pairtwo-6'; // Possible values: Pairtwo-5, Pairtwo-6, Swar-4
if (!file_exists($pairingfile)) {
trigger_error('Your file is not set or doesn\'t exist! Edit the file: ' . __FILE__ . ' and try again', E_USER_ERROR);
}
$reader = IOFactory::createReader($fileformat);
$reader->read($pairingfile);
// From here on you can start. Please use the examples on https://github.com/jeroened/libpairtwo/wiki
// You can also use the doc/api folder to get all possible methods and fields
// Below is an example of what can be used. Feel free to modify this.
echo '<h1>' . $reader->getTournament()->getName() . '</h1>' . PHP_EOL;
foreach($reader->getTournament()->getRounds() as $round) {
echo '<h2>Ronde ' . ($round->getRoundNo() + 1) . ': ' . $round->getDate()->format('d/m/Y') . '</h2>' . PHP_EOL;
echo '<table>' . PHP_EOL;
echo '<thead>' . PHP_EOL;
echo '<tr><th>Wit</th><th>Zwart</th><th>Resultaat</th></tr>' . PHP_EOL;
echo '</thead>' . PHP_EOL;
echo '<tbody>' . PHP_EOL;
foreach($round->getGames() as $game) {
echo '<tr>' . PHP_EOL;
echo '<td>' . $game->getWhite()->getPlayer()->getName() . '</td>' . PHP_EOL;
echo '<td>' . $game->getBlack()->getPlayer()->getName() . '</td>' . PHP_EOL;
echo '<td>' . $game->getResult()->getValue() . '</td>' . PHP_EOL;
echo '</tr>' . PHP_EOL;
}
echo '</tbody>' . PHP_EOL;
echo '</table>' . PHP_EOL;
echo '<p><strong>Bye:</strong> ';
$bye = [];
foreach ($round->getBye() as $pairing) {
$bye[] = $pairing->getPlayer()->getName();
}
echo implode(', ', $bye);
echo '</p>' . PHP_EOL;
echo '<p><strong>Afwezig:</strong> ';
$bye = [];
foreach ($round->getAbsent() as $pairing) {
$bye[] = $pairing->getPlayer()->getName();
}
echo implode('; ', $bye);
echo '</p>' . PHP_EOL;
}
echo '<h2>Klassement</h2>' . PHP_EOL;
echo '<table>' . PHP_EOL;
echo '<thead>' . PHP_EOL;
echo '<tr><th> </th><th>Naam (elo)</th>' . PHP_EOL;
foreach ($reader->getTournament()->getTieBreaks() as $tiebreak) {
echo '<th>' . $tiebreak->getValue() . '</th>' . PHP_EOL;
}
echo '</tr>' . PHP_EOL;
echo '</thead>' . PHP_EOL;
echo '<tbody>' . PHP_EOL;
$rank = 1;
foreach ($reader->getTournament()->getRanking() as $player) {
echo '<tr>' . PHP_EOL;
echo '<td>' . $rank . '</td>' . PHP_EOL;
echo '<td>' . $player->getName() . '(' . $player->getElo($reader->getTournament()->getPriorityElo()) . ')</td>' . PHP_EOL;
echo '<td>' . implode('</td><td>', $player->getTiebreaks()) . '</td>' . PHP_EOL;
echo '</tr>' . PHP_EOL;
$rank++;
}
echo '</tbody>' . PHP_EOL;
echo '</table>' . PHP_EOL;
?>
<script src="js/scripts.js"></script>
</body>
</html>