Implemented Player::getPerformance()

This commit is contained in:
Jeroen De Meerleer 2019-05-30 21:10:31 +02:00
parent 56e831b372
commit aef6b688e9

View File

@ -127,4 +127,27 @@ class Player extends PlayerModel
}
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);
}
}
}