Some fixes for getPerformance

This commit is contained in:
Jeroen De Meerleer 2019-06-01 13:37:50 +02:00
parent 2e80157cbd
commit b2cd821ad8
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6
4 changed files with 14 additions and 13 deletions

View File

@ -131,24 +131,24 @@ class Player extends PlayerModel
/**
* @return int
*/
public function getPerformance(string $type) : int
public function getPerformance(string $type, int $unratedElo) : float
{
$total = 0;
$opponents = 0;
foreach ($this->getPairings() as $pairing) {
if (array_search($pairing->getResult(), Constants::Notplayed)) {
if (array_search($pairing->getResult(), Constants::NotPlayed) === false) {
$opponentElo = $pairing->getOpponent()->getElo($type);
$opponentElo = $opponentElo != 0 ? $opponentElo : $this->getUnratedElo();
if (array_search(self::Won, $pairing->getResult())) {
$opponentElo = $opponentElo != 0 ? $opponentElo : $unratedElo;
if (array_search($pairing->getResult(), Constants::Won) !== false) {
$total += $opponentElo + 400;
} elseif (array_search(self::Lost, $pairing->getResult())) {
} elseif (array_search($pairing->getResult(), Constants::Lost) !== false) {
$total += $opponentElo - 400;
} elseif (array_search(self::Draw, $pairing->getResult())) {
} elseif (array_search($pairing->getResult(), Constants::Draw) !== false) {
$total += $opponentElo;
}
$opponents++;
}
}
return round($total / $opponents);
}
}
}

View File

@ -157,7 +157,7 @@ abstract class Tiebreaks extends Tournament
$allratings = [];
foreach ($pairings as $pairing) {
if (array_search($pairing->getResult(), Constants::NotPlayed) === false) {
$toadd = $pairing->getOpponent()->getPerformance($type);
$toadd = $pairing->getOpponent()->getPerformance($type, $this->getNonRatedElo());
if ($toadd != 0) {
$allratings[] = $toadd;
}
@ -217,7 +217,8 @@ abstract class Tiebreaks extends Tournament
foreach ($intpairings as $intkey => $intpairing) {
if (!is_null($intpairing->getOpponent())) {
$tiebreak += $intpairing->getOpponent()->getPoints();
}}
}
}
return $tiebreak;
}

View File

@ -321,7 +321,7 @@ class Tournament extends Tiebreaks
return $this->calculateAveragePerformance($player, $this->getPriorityElo());
break;
case Tiebreak::Performance:
return $player->getPerformance($this->getPriorityElo());
return $player->getPerformance($this->getPriorityElo(), $this->getNonRatedElo());
break;
default:
return null;