Merge branch 'task/reader/swar' into develop

This commit is contained in:
Jeroen De Meerleer 2019-09-25 19:47:35 +02:00
commit 52079b60bc
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6
3 changed files with 84 additions and 1 deletions

View File

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

View File

@ -15,6 +15,7 @@ namespace JeroenED\Libpairtwo\Readers;
use DateTime; use DateTime;
use JeroenED\Libpairtwo\Enums\Color; use JeroenED\Libpairtwo\Enums\Color;
use JeroenED\Libpairtwo\Enums\Tiebreak;
use JeroenED\Libpairtwo\Enums\TournamentSystem; use JeroenED\Libpairtwo\Enums\TournamentSystem;
use JeroenED\Libpairtwo\Exceptions\IncompatibleReaderException; use JeroenED\Libpairtwo\Exceptions\IncompatibleReaderException;
use JeroenED\Libpairtwo\Interfaces\ReaderInterface; use JeroenED\Libpairtwo\Interfaces\ReaderInterface;
@ -234,9 +235,62 @@ class Swar4 implements ReaderInterface
$this->getTournament()->setBinaryData('[TIE_BREAK]', $this->readData('String', $swshandle)); $this->getTournament()->setBinaryData('[TIE_BREAK]', $this->readData('String', $swshandle));
$tiebreaks = [];
for ($i = 0; $i < 5; $i++) { 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('[EXCLUSION]', $this->readData('String', $swshandle));
$this->getTournament()->setBinaryData('ExclusionType', $this->readData('Int', $swshandle)); $this->getTournament()->setBinaryData('ExclusionType', $this->readData('Int', $swshandle));
@ -423,6 +477,7 @@ class Swar4 implements ReaderInterface
} }
fclose($swshandle); fclose($swshandle);
$this->getTournament()->pairingsToRounds(); $this->getTournament()->pairingsToRounds();
$this->addTiebreaks();
return $this; return $this;
} }
@ -565,4 +620,24 @@ class Swar4 implements ReaderInterface
return DateTime::createFromFormat('Ymd', $string); 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: case Tiebreak::BuchholzMed:
return $this->calculateBuchholz($player, 1, 1); return $this->calculateBuchholz($player, 1, 1);
break; break;
case Tiebreak::BuchholzCut2:
return $this->calculateBuchholz($player, 2);
break;
case Tiebreak::BuchholzMed2:
return $this->calculateBuchholz($player, 2, 2);
break;
case Tiebreak::Sonneborn: case Tiebreak::Sonneborn:
return $this->calculateSonneborn($player); return $this->calculateSonneborn($player);
break; break;