diff --git a/dist/template.php b/dist/template.php index 9cd3e19..345760b 100644 --- a/dist/template.php +++ b/dist/template.php @@ -49,8 +49,8 @@ foreach ($reader->Tournament->Rounds as $round) { foreach ($round->GamesByBoard as $game) { echo '' . PHP_EOL; echo '' . ($game->Board + 1) . '' . PHP_EOL; - echo '' . $game->White->Player->Name . '' . PHP_EOL; - echo '' . $game->Black->Player->Name . '' . PHP_EOL; + echo '' . $game->White->Player->Name . ' (' . $game->White->Player->getElo($reader->Tournament->PriorityElo) . ')' . PHP_EOL; + echo '' . $game->Black->Player->Name . ' (' . $game->Black->Player->getElo($reader->Tournament->PriorityElo) . ')' . PHP_EOL; echo '' . $game->Result->getValue() . '' . PHP_EOL; echo '' . PHP_EOL; } @@ -73,11 +73,11 @@ foreach ($reader->Tournament->Rounds as $round) { echo '

' . PHP_EOL; } -echo '

Rankings

' . PHP_EOL; +echo '

Global Rankings

' . PHP_EOL; echo '' . PHP_EOL; echo '' . PHP_EOL; -echo '' . PHP_EOL; -foreach ($reader->Tournament->TieBreaks as $tiebreak) { +echo '' . PHP_EOL; +foreach ($reader->Tournament->Tiebreaks as $tiebreak) { echo '' . PHP_EOL; } echo '' . PHP_EOL; @@ -88,13 +88,43 @@ $rank = 1; foreach ($reader->Tournament->Ranking as $player) { echo '' . PHP_EOL; echo '' . PHP_EOL; - echo '' . PHP_EOL; + echo '' . PHP_EOL; + echo '' . PHP_EOL; echo '' . PHP_EOL; echo '' . PHP_EOL; $rank++; } echo '' . PHP_EOL; echo '
Name (elo)
Name (elo)Category' . $tiebreak->getValue() . '
' . $rank . '' . $player->Name . '(' . $player->getElo($reader->Tournament->PriorityElo) . ')' . $player->Name . ' (' . $player->getElo($reader->Tournament->PriorityElo) . ')' . $player->Category . '' . implode('', $player->Tiebreaks) . '
' . PHP_EOL; +?> + +Rankings per Category' . PHP_EOL; + +foreach($reader->Tournament->Categories as $category) { + echo '' . PHP_EOL; + echo ''; + echo '' . PHP_EOL; + echo '' . PHP_EOL; + foreach ($reader->Tournament->Tiebreaks as $tiebreak) { + echo '' . PHP_EOL; + } + echo '' . PHP_EOL; + echo '' . PHP_EOL; + echo '' . PHP_EOL; + + $rank = 1; + foreach ($reader->Tournament->RankingForCategory($category) as $player) { + echo '' . PHP_EOL; + echo '' . PHP_EOL; + echo '' . PHP_EOL; + echo '' . PHP_EOL; + echo '' . PHP_EOL; + $rank++; + } + echo '' . PHP_EOL; + echo '
' . $category . '
Name (elo)' . $tiebreak->getValue() . '
' . $rank . '' . $player->Name . ' (' . $player->getElo($reader->Tournament->PriorityElo) . ')' . implode('', $player->Tiebreaks) . '
' . PHP_EOL; +} ?> diff --git a/res/categories_test.sws b/res/categories_test.sws new file mode 100644 index 0000000..0303e98 Binary files /dev/null and b/res/categories_test.sws differ diff --git a/src/Readers/Pairtwo6.php b/src/Readers/Pairtwo6.php index 72e65af..5a71faf 100644 --- a/src/Readers/Pairtwo6.php +++ b/src/Readers/Pairtwo6.php @@ -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; diff --git a/src/Tournament.php b/src/Tournament.php index 5c4a6be..9e79191 100644 --- a/src/Tournament.php +++ b/src/Tournament.php @@ -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 * diff --git a/tests/ReadSws_test.php b/tests/ReadSws_test.php index 11583c1..2a91daa 100644 --- a/tests/ReadSws_test.php +++ b/tests/ReadSws_test.php @@ -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