mirror of
https://github.com/JeroenED/libpairtwo.git
synced 2024-11-22 06:26:57 +01:00
Merge branch 'bugfix/Performance' into develop
This commit is contained in:
commit
5d4f4791cf
@ -131,24 +131,24 @@ class Player extends PlayerModel
|
|||||||
/**
|
/**
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function getPerformance(string $type) : int
|
public function getPerformance(string $type, int $unratedElo) : float
|
||||||
{
|
{
|
||||||
$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) === false) {
|
||||||
$opponentElo = $pairing->getOpponent()->getElo($type);
|
$opponentElo = $pairing->getOpponent()->getElo($type);
|
||||||
$opponentElo = $opponentElo != 0 ? $opponentElo : $this->getUnratedElo();
|
$opponentElo = $opponentElo != 0 ? $opponentElo : $unratedElo;
|
||||||
if (array_search(self::Won, $pairing->getResult())) {
|
if (array_search($pairing->getResult(), Constants::Won) !== false) {
|
||||||
$total += $opponentElo + 400;
|
$total += $opponentElo + 400;
|
||||||
} elseif (array_search(self::Lost, $pairing->getResult())) {
|
} elseif (array_search($pairing->getResult(), Constants::Lost) !== false) {
|
||||||
$total += $opponentElo - 400;
|
$total += $opponentElo - 400;
|
||||||
} elseif (array_search(self::Draw, $pairing->getResult())) {
|
} elseif (array_search($pairing->getResult(), Constants::Draw) !== false) {
|
||||||
$total += $opponentElo;
|
$total += $opponentElo;
|
||||||
}
|
}
|
||||||
$opponents++;
|
$opponents++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return round($total / $opponents);
|
return round($total / $opponents);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@ -157,7 +157,7 @@ abstract class Tiebreaks extends Tournament
|
|||||||
$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($type);
|
$toadd = $pairing->getOpponent()->getPerformance($type, $this->getNonRatedElo());
|
||||||
if ($toadd != 0) {
|
if ($toadd != 0) {
|
||||||
$allratings[] = $toadd;
|
$allratings[] = $toadd;
|
||||||
}
|
}
|
||||||
@ -217,7 +217,8 @@ abstract class Tiebreaks extends Tournament
|
|||||||
foreach ($intpairings as $intkey => $intpairing) {
|
foreach ($intpairings as $intkey => $intpairing) {
|
||||||
if (!is_null($intpairing->getOpponent())) {
|
if (!is_null($intpairing->getOpponent())) {
|
||||||
$tiebreak += $intpairing->getOpponent()->getPoints();
|
$tiebreak += $intpairing->getOpponent()->getPoints();
|
||||||
}}
|
}
|
||||||
|
}
|
||||||
return $tiebreak;
|
return $tiebreak;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -321,7 +321,7 @@ class Tournament extends Tiebreaks
|
|||||||
return $this->calculateAveragePerformance($player, $this->getPriorityElo());
|
return $this->calculateAveragePerformance($player, $this->getPriorityElo());
|
||||||
break;
|
break;
|
||||||
case Tiebreak::Performance:
|
case Tiebreak::Performance:
|
||||||
return $player->getPerformance($this->getPriorityElo());
|
return $player->getPerformance($this->getPriorityElo(), $this->getNonRatedElo());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
|
Loading…
Reference in New Issue
Block a user