Added average rating calculation

This commit is contained in:
Jeroen De Meerleer 2019-05-29 17:57:42 +02:00
parent a0e36ec0be
commit b437a74334
1 changed files with 21 additions and 0 deletions

View File

@ -297,4 +297,25 @@ class Tournament extends Tiebreaks
return null;
}
}
/**
* Return the average rating for tournament
*
* @return int
*/
public function getAverageElo(): int
{
$totalrating = 0;
$players = 0;
foreach ($this->getPlayers() as $player) {
$toadd = $player->getElos()['home'];
if ($toadd == 0) {
$toadd = $this->getNonRatedElo();
}
$totalrating += $toadd;
$players++;
}
return intdiv($totalrating, $players);
}
}