Implemented Aro Cut 1

This commit is contained in:
Jeroen De Meerleer 2019-05-30 08:33:52 +02:00
parent 34a5696ff3
commit 08f42adc26
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6
2 changed files with 9 additions and 4 deletions

View File

@ -141,20 +141,22 @@ abstract class Tiebreaks extends Tournament
* @param Player $player
* @return float
*/
protected function calculateAverageRating(Player $player)
protected function calculateAverageRating(Player $player, int $cut = 0)
{
$pairings = $player->getPairings();
$totalrating = 0;
$totalopponents = 0;
$allratings = [];
foreach ($pairings as $pairing) {
if (array_search($pairing->getResult(), self::NotPlayed) === false) {
$toadd = $pairing->getOpponent()->getElos()['home'];
if ($toadd != 0) {
$totalrating += $toadd;
$totalopponents++;
$allratings[] = $toadd;
}
}
}
return round($totalrating / $totalopponents);
sort($allratings);
$allratings = array_slice($allratings, $cut);
return round(array_sum($allratings) / count($allratings));
}
}

View File

@ -293,6 +293,9 @@ class Tournament extends Tiebreaks
case Tiebreak::Aro:
return $this->calculateAverageRating($player);
break;
case Tiebreak::AroCut:
return $this->calculateAverageRating($player, 1);
break;
default:
return null;
}