Working ARO tiebreak

This commit is contained in:
Jeroen De Meerleer 2019-05-29 17:56:30 +02:00
parent d49c8d673c
commit 04f864416d
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6
2 changed files with 19 additions and 4 deletions

View File

@ -9,10 +9,10 @@ use JeroenED\Libpairtwo\Enums\Result;
abstract class Tiebreaks extends Tournament abstract class Tiebreaks extends Tournament
{ {
private const Won = [ Result::won, Result::wonforfait, Result::wonbye, Result::wonadjourned ]; private const Won = [ Result::won, Result::wonforfait, Result::wonbye, Result::wonadjourned ];
private const Draw = [ Result::draw, Result::drawadjourned]; private const Draw = [ Result::draw, Result::drawadjourned];
private const Lost = [ Result::absent, Result::bye, Result::lost, Result::adjourned ]; private const Lost = [ Result::absent, Result::bye, Result::lost, Result::adjourned ];
private const NotPlayed = [ Result::bye, Result::wonbye, Result::absent ];
private const Black = [ Color::black ]; private const Black = [ Color::black ];
private const White = [ Color::white ]; private const White = [ Color::white ];
@ -137,12 +137,24 @@ abstract class Tiebreaks extends Tournament
return $points; return $points;
} }
protected function calculateAverageRating(Player $player) { /**
* @param Player $player
* @return float
*/
protected function calculateAverageRating(Player $player)
{
$pairings = $player->getPairings(); $pairings = $player->getPairings();
$totalrating = 0; $totalrating = 0;
$opponents; $totalopponents = 0;
foreach ($pairings as $pairing) { foreach ($pairings as $pairing) {
if ($pairing->getOpponent()->getElos['national']) if (array_search($pairing->getResult(), self::NotPlayed) === false) {
$toadd = $pairing->getOpponent()->getElos()['home'];
if ($toadd != 0) {
$totalrating += $toadd;
$totalopponents++;
} }
} }
}
return round($totalrating / $totalopponents);
}
} }

View File

@ -290,6 +290,9 @@ class Tournament extends Tiebreaks
case Tiebreak::Between: case Tiebreak::Between:
return $this->calculateMutualResult($player, $this->getPlayers(), $tbkey); return $this->calculateMutualResult($player, $this->getPlayers(), $tbkey);
break; break;
case Tiebreak::Aro:
return $this->calculateAverageRating($player);
break;
default: default:
return null; return null;
} }