BUGFIX: Tiebreaks were not read in swar-4 reader

This commit is contained in:
Jeroen De Meerleer 2019-09-25 19:52:45 +02:00
parent 3c3b8c8b92
commit fefb089018
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6
4 changed files with 86 additions and 4 deletions

View File

@ -14,7 +14,6 @@ namespace JeroenED\Libpairtwo\Enums;
use MyCLabs\Enum\Enum;
/**
* Enum Gender
*

View File

@ -33,6 +33,8 @@ class Tiebreak extends Enum
const Buchholz = "Buchholz";
const BuchholzMed = "Buchholz Median";
const BuchholzCut = "Buchholz Cut";
const BuchholzMed2 = "Buchholz Median 2";
const BuchholzCut2 = "Buchholz Cut 2";
const Sonneborn = "Sonneborn-Berger";
const Kashdan = "Kashdan";
const SoccerKashdan = "Soccer Kashdan";

View File

@ -15,6 +15,7 @@ namespace JeroenED\Libpairtwo\Readers;
use DateTime;
use JeroenED\Libpairtwo\Enums\Color;
use JeroenED\Libpairtwo\Enums\Tiebreak;
use JeroenED\Libpairtwo\Enums\TournamentSystem;
use JeroenED\Libpairtwo\Exceptions\IncompatibleReaderException;
use JeroenED\Libpairtwo\Interfaces\ReaderInterface;
@ -234,9 +235,62 @@ class Swar4 implements ReaderInterface
$this->getTournament()->setBinaryData('[TIE_BREAK]', $this->readData('String', $swshandle));
$tiebreaks = [];
for ($i = 0; $i < 5; $i++) {
$this->getTournament()->setBinaryData('Tiebreak_' . $i, $this->readData('Int', $swshandle));
switch ($this->readData('Int', $swshandle)) {
case 0:
default:
$tiebreak = Tiebreak::None;
break;
case 1:
$tiebreak = Tiebreak::Buchholz;
break;
case 2:
$tiebreak = Tiebreak::BuchholzMed;
break;
case 3:
$tiebreak = Tiebreak::BuchholzMed2;
break;
case 4:
$tiebreak = Tiebreak::BuchholzCut;
break;
case 5:
$tiebreak = Tiebreak::BuchholzCut2;
break;
case 6:
$tiebreak = Tiebreak::Sonneborn;
break;
case 7:
$tiebreak = Tiebreak::Cumulative;
break;
case 8:
$tiebreak = Tiebreak::Between;
break;
case 9:
$tiebreak = Tiebreak::Koya;
break;
case 10:
$tiebreak = Tiebreak::Baumbach;
break;
case 11:
$tiebreak = Tiebreak::AveragePerformance;
break;
case 12:
$tiebreak = Tiebreak::Aro;
break;
case 13:
$tiebreak = Tiebreak::AroCut;
break;
case 14:
$tiebreak = Tiebreak::BlackPlayed;
break;
case 15:
$tiebreak = Tiebreak::BlackWin;
break;
}
$tiebreaks[] = new Tiebreak($tiebreak);
}
$this->getTournament()->setTiebreaks($tiebreaks);
$this->getTournament()->setBinaryData('[EXCLUSION]', $this->readData('String', $swshandle));
$this->getTournament()->setBinaryData('ExclusionType', $this->readData('Int', $swshandle));
@ -372,7 +426,7 @@ class Swar4 implements ReaderInterface
$pairing->setPlayer($this->getTournament()->getPlayerById($this->getTournament()->getBinaryData('Pairing_' . $ptn . '_player')));
$pairing->setRound($this->getTournament()->getBinaryData('Pairing_' . $ptn . '_round'));
if($this->getTournament()->getBinaryData('Pairing_' . $ptn . '_opponent') != 4294967294) {
if ($this->getTournament()->getBinaryData('Pairing_' . $ptn . '_opponent') != 4294967294) {
$pairing->setOpponent($this->getTournament()->getPlayerById($this->getTournament()->getBinaryData('Pairing_' . $ptn . '_opponent')));
}
//echo $ptn . ' ' . $this->getTournament()->getBinaryData('Pairing_' . $ptn . '_round') . ' ' . $pairing->getPlayer()->getName() . ' - ' . $opponent . ' ' . $this->getTournament()->getBinaryData('Pairing_' . $ptn . '_result') . PHP_EOL;
@ -423,6 +477,7 @@ class Swar4 implements ReaderInterface
}
fclose($swshandle);
$this->getTournament()->pairingsToRounds();
$this->addTiebreaks();
return $this;
}
@ -565,4 +620,24 @@ class Swar4 implements ReaderInterface
return DateTime::createFromFormat('Ymd', $string);
}
}
/**
* @return $this
*/
private function addTiebreaks(): Swar4
{
switch ($this->getTournament()->getSystem()) {
case TournamentSystem::American:
$firstElement = new Tiebreak(Tiebreak::American);
break;
case TournamentSystem::Closed:
case TournamentSystem::Swiss:
default:
$firstElement = new Tiebreak(Tiebreak::Points);
}
$tiebreaks = $this->getTournament()->getTiebreaks();
array_unshift($tiebreaks, $firstElement);
$this->getTournament()->setTiebreaks($tiebreaks);
return $this;
}
}

View File

@ -421,6 +421,12 @@ class Tournament
case Tiebreak::BuchholzMed:
return $this->calculateBuchholz($player, 1, 1);
break;
case Tiebreak::BuchholzCut2:
return $this->calculateBuchholz($player, 2);
break;
case Tiebreak::BuchholzMed2:
return $this->calculateBuchholz($player, 2, 2);
break;
case Tiebreak::Sonneborn:
return $this->calculateSonneborn($player);
break;
@ -428,7 +434,7 @@ class Tournament
return $this->calculateKashdan($player, ["Won" => 4, "Draw" => 2, "Lost" => 1, "NotPlayed" => 0]);
break;
case Tiebreak::SoccerKashdan:
return $this->calculateKashdan($player, ["Won" => 3, "Draw" => 1, "Lost" => 0, "NotPlayed" => -1]);
return $this->calculateKashdan($player, ["Won" => 3, "Draw" => 1, "Lost" => 0, "NotPlayed" => -1]);
break;
case Tiebreak::Cumulative:
return $this->calculateCumulative($player);