NEW FEATURE: reading out categories from pairtwo-6

This commit is contained in:
Jeroen De Meerleer 2020-11-22 16:40:10 +01:00
parent f4c526ff41
commit c403c2f5be
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6
5 changed files with 147 additions and 68 deletions

42
dist/template.php vendored
View File

@ -49,8 +49,8 @@ foreach ($reader->Tournament->Rounds as $round) {
foreach ($round->GamesByBoard as $game) {
echo '<tr>' . PHP_EOL;
echo '<td>' . ($game->Board + 1) . '</td>' . PHP_EOL;
echo '<td>' . $game->White->Player->Name . '</td>' . PHP_EOL;
echo '<td>' . $game->Black->Player->Name . '</td>' . PHP_EOL;
echo '<td>' . $game->White->Player->Name . ' (' . $game->White->Player->getElo($reader->Tournament->PriorityElo) . ')</td>' . PHP_EOL;
echo '<td>' . $game->Black->Player->Name . ' (' . $game->Black->Player->getElo($reader->Tournament->PriorityElo) . ')</td>' . PHP_EOL;
echo '<td>' . $game->Result->getValue() . '</td>' . PHP_EOL;
echo '</tr>' . PHP_EOL;
}
@ -73,11 +73,11 @@ foreach ($reader->Tournament->Rounds as $round) {
echo '</p>' . PHP_EOL;
}
echo '<h2>Rankings</h2>' . PHP_EOL;
echo '<h2>Global Rankings</h2>' . PHP_EOL;
echo '<table>' . PHP_EOL;
echo '<thead>' . PHP_EOL;
echo '<tr><th> </th><th>Name (elo)</th>' . PHP_EOL;
foreach ($reader->Tournament->TieBreaks as $tiebreak) {
echo '<tr><th> </th><th>Name (elo)</th><th>Category</th>' . PHP_EOL;
foreach ($reader->Tournament->Tiebreaks as $tiebreak) {
echo '<th>' . $tiebreak->getValue() . '</th>' . PHP_EOL;
}
echo '</tr>' . PHP_EOL;
@ -88,13 +88,43 @@ $rank = 1;
foreach ($reader->Tournament->Ranking as $player) {
echo '<tr>' . PHP_EOL;
echo '<td>' . $rank . '</td>' . PHP_EOL;
echo '<td>' . $player->Name . '(' . $player->getElo($reader->Tournament->PriorityElo) . ')</td>' . PHP_EOL;
echo '<td>' . $player->Name . ' (' . $player->getElo($reader->Tournament->PriorityElo) . ')</td>' . PHP_EOL;
echo '<td>' . $player->Category . '</td>' . PHP_EOL;
echo '<td>' . implode('</td><td>', $player->Tiebreaks) . '</td>' . PHP_EOL;
echo '</tr>' . PHP_EOL;
$rank++;
}
echo '</tbody>' . PHP_EOL;
echo '</table>' . PHP_EOL;
?>
<?php
echo '<h2>Rankings per Category</h2>' . PHP_EOL;
foreach($reader->Tournament->Categories as $category) {
echo '<table>' . PHP_EOL;
echo '<caption>' . $category . '</caption>';
echo '<thead>' . PHP_EOL;
echo '<tr><th> </th><th>Name (elo)</th>' . PHP_EOL;
foreach ($reader->Tournament->Tiebreaks 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->Tournament->RankingForCategory($category) as $player) {
echo '<tr>' . PHP_EOL;
echo '<td>' . $rank . '</td>' . PHP_EOL;
echo '<td>' . $player->Name . ' (' . $player->getElo($reader->Tournament->PriorityElo) . ')</td>' . PHP_EOL;
echo '<td>' . implode('</td><td>', $player->Tiebreaks) . '</td>' . PHP_EOL;
echo '</tr>' . PHP_EOL;
$rank++;
}
echo '</tbody>' . PHP_EOL;
echo '</table>' . PHP_EOL;
}
?>
<script src="js/scripts.js"></script>
</body>

BIN
res/categories_test.sws Normal file

Binary file not shown.

View File

@ -321,9 +321,14 @@ class Pairtwo6 implements ReaderInterface
}
// Categorie
$length = 4 * 10;
$this->Categorie = $this->readData('Int', substr($swscontents, $offset, $length));
$offset += $length;
for($i = 0; $i < 10; $i++) {
$length = 4;
$category = $this->readData('Int', substr($swscontents, $offset, $length));
if($category != 0) {
$this->Tournament->addCategory('+' . $category);
}
$offset += $length;
}
// ExtraPoints
$length = 4 * 20;
@ -401,7 +406,7 @@ class Pairtwo6 implements ReaderInterface
$offset += $length;
$length = 1;
$player->Category = $this->readData('String', substr($swscontents, $offset, $length));
$player->Category = $this->Tournament->Categories[$this->readData('Int', substr($swscontents, $offset, $length)) -1];
$offset += $length;
$length = 1;

View File

@ -113,6 +113,13 @@ class Tournament
*/
public $Rounds = [];
/**
* Round objects of all rounds in the tournament
*
* @var $Categories[]
*/
public $Categories = [];
/**
* The tempo of the tournament (eg. 90 min/40 moves + 30 sec. increment starting from move 1)
*
@ -264,6 +271,19 @@ class Tournament
$this->Rounds = $newArray;
}
/**
* Adds a category with given name object
*
* @param string $name
*/
public function addCategory(string $name): void
{
$newArray = $this->Categories;
$newArray[] = $name;
$this->Categories = $newArray;
}
/**
* Gets a round by its number.
*
@ -308,8 +328,8 @@ class Tournament
$pairings = $this->Pairings;
/**
* @var Pairing[]
*/
* @var Pairing[]
*/
$cache = array();
foreach ($pairings as $pairing) {
@ -415,6 +435,26 @@ class Tournament
$this->roundByNo($round)->addGame($game);
}
/**
* Get the ranking for a specific category
*
* @param string $category
*
* @return array
*/
Public function RankingForCategory(string $category): array
{
$globalRanking = $this->ranking();
$return = [];
foreach($globalRanking as $player) {
if($player->Category == $category) {
$return[] = $player;
}
}
return $return;
}
/**
* Gets the ranking of the tournament
*

View File

@ -30,62 +30,66 @@ 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()->Arbiter[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->Key() . 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)->Elo('Fide') . PHP_EOL;
echo "Fide Elo P2: " . $sws->Tournament()->PlayerById(1)->Elo('Fide') . PHP_EOL;
echo "Fide Elo P3: " . $sws->Tournament()->PlayerById(2)->Elo('Fide') . PHP_EOL;
echo "KBSB Elo P1: " . $sws->Tournament()->PlayerById(0)->Elo('Nation') . PHP_EOL;
echo "KBSB Elo P2: " . $sws->Tournament()->PlayerById(1)->Elo('Nation') . PHP_EOL;
echo "KBSB Elo P3: " . $sws->Tournament()->PlayerById(2)->Elo('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->Key() . PHP_EOL;
echo "Gender P2: " . $sws->Tournament()->PlayerById(1)->Gender->Key() . PHP_EOL;
echo "Gender P3: " . $sws->Tournament()->PlayerById(2)->Gender->Key() . 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 "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]->Value() . PHP_EOL;
echo "Tiebreak 2: " . $sws->Tournament()->Tiebreaks[1]->Value() . PHP_EOL;
echo "Tiebreak 3: " . $sws->Tournament()->Tiebreaks[2]->Value() . PHP_EOL;
echo "Tiebreak 4: " . $sws->Tournament()->Tiebreaks[3]->Value() . PHP_EOL;
echo "Tiebreak 5: " . $sws->Tournament()->Tiebreaks[4]->Value() . PHP_EOL;
echo "Tiebreak 6: " . $sws->Tournament()->Tiebreaks[5]->Value() . PHP_EOL;
echo "Average Elo: " . $sws->Tournament()->AverageElo . PHP_EOL;
foreach ($sws->Tournament()->Ranking as $player) {
echo str_pad($player->Name . '(' . $player->Elo($sws->Tournament()->PriorityElo) . ') ', 35) . implode_pad(' ', $player->Tiebreaks, 5, ' ') . PHP_EOL;
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