Added priorityElo to getPerformance and tiebreaks

This commit is contained in:
Jeroen De Meerleer 2019-05-31 22:45:26 +02:00
parent 3da584aebc
commit 0d83e86edb
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6
3 changed files with 9 additions and 11 deletions

View File

@ -131,13 +131,13 @@ class Player extends PlayerModel
/** /**
* @return int * @return int
*/ */
public function getPerformance(): int public function getPerformance(string $type) : int
{ {
$total = 0; $total = 0;
$opponents = 0; $opponents = 0;
foreach ($this->getPairings() as $pairing) { foreach ($this->getPairings() as $pairing) {
if (array_search($pairing->getResult(), Constants::Notplayed)) { if (array_search($pairing->getResult(), Constants::Notplayed)) {
$opponentElo = $pairing->getOpponent()->getElo('Nation'); $opponentElo = $pairing->getOpponent()->getElo($type);
$opponentElo = $opponentElo != 0 ? $opponentElo : $this->getUnratedElo(); $opponentElo = $opponentElo != 0 ? $opponentElo : $this->getUnratedElo();
if (array_search(self::Won, $pairing->getResult())) { if (array_search(self::Won, $pairing->getResult())) {
$total += $opponentElo + 400; $total += $opponentElo + 400;

View File

@ -128,15 +128,13 @@ abstract class Tiebreaks extends Tournament
* @param int $cut * @param int $cut
* @return float * @return float
*/ */
protected function calculateAverageRating(Player $player, int $cut = 0): ?float protected function calculateAverageRating(Player $player, string $type, int $cut = 0): ?float
{ {
$pairings = $player->getPairings(); $pairings = $player->getPairings();
$totalrating = 0;
$totalopponents = 0;
$allratings = []; $allratings = [];
foreach ($pairings as $pairing) { foreach ($pairings as $pairing) {
if (array_search($pairing->getResult(), Constants::NotPlayed) === false) { if (array_search($pairing->getResult(), Constants::NotPlayed) === false) {
$toadd = $pairing->getOpponent()->getElo('Nation'); $toadd = $pairing->getOpponent()->getElo($type);
if ($toadd != 0) { if ($toadd != 0) {
$allratings[] = $toadd; $allratings[] = $toadd;
} }
@ -153,13 +151,13 @@ abstract class Tiebreaks extends Tournament
* @param int $cut * @param int $cut
* @return float|null * @return float|null
*/ */
protected function calculateAveragePerformance(Player $player, int $cut = 0): ?float protected function calculateAveragePerformance(Player $player, string $type, int $cut = 0): ?float
{ {
$pairings = $player->getPairings(); $pairings = $player->getPairings();
$allratings = []; $allratings = [];
foreach ($pairings as $pairing) { foreach ($pairings as $pairing) {
if (array_search($pairing->getResult(), Constants::NotPlayed) === false) { if (array_search($pairing->getResult(), Constants::NotPlayed) === false) {
$toadd = $pairing->getOpponent()->getPerformance('Nation'); $toadd = $pairing->getOpponent()->getPerformance($type);
if ($toadd != 0) { if ($toadd != 0) {
$allratings[] = $toadd; $allratings[] = $toadd;
} }

View File

@ -291,10 +291,10 @@ class Tournament extends Tiebreaks
return $this->calculateMutualResult($player, $this->getPlayers(), $tbkey); return $this->calculateMutualResult($player, $this->getPlayers(), $tbkey);
break; break;
case Tiebreak::Aro: case Tiebreak::Aro:
return $this->calculateAverageRating($player); return $this->calculateAverageRating($player, $this->getPriorityElo());
break; break;
case Tiebreak::AroCut: case Tiebreak::AroCut:
return $this->calculateAverageRating($player, 1); return $this->calculateAverageRating($player, $this->getPriorityElo(), 1);
break; break;
case Tiebreak::Koya: case Tiebreak::Koya:
return $this->calculateKoya($player); return $this->calculateKoya($player);
@ -318,7 +318,7 @@ class Tournament extends Tiebreaks
return $this->calculateCumulative($player); return $this->calculateCumulative($player);
break; break;
case Tiebreak::Performance: case Tiebreak::Performance:
return $this->calculateAveragePerformance($player); return $this->calculateAveragePerformance($player, $this->getPriorityElo());
break; break;
default: default:
return null; return null;