Implemented Player::getPerformance()

This commit is contained in:
Jeroen De Meerleer 2019-05-30 21:10:31 +02:00
parent 6d4eeff234
commit 587a7a2e08
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6

View File

@ -127,4 +127,27 @@ class Player extends PlayerModel
} }
return $points; return $points;
} }
/**
* @return float
*/
public function getPerformance()
{
$total = 0;
$opponents = 0;
foreach ($this->getPairings() as $pairing) {
if (array_search($pairing->getResult(), Constants::Notplayed)) {
if (array_search(self::Won, $pairing->getResult())) {
$total += $pairing->getOpponent()->getElo('home') + 400;
} elseif (array_search(self::Lost, $pairing->getResult())) {
$total += $pairing->getOpponent()->getElo('home') - 400;
} elseif (array_search(self::Draw, $pairing->getResult())) {
$total += $pairing->getOpponent()->getElo('home');
}
$opponents++;
}
return round($total / $opponents);
}
}
} }