mirror of
https://github.com/JeroenED/libpairtwo.git
synced 2024-11-22 06:26:57 +01:00
Added average performance tiebreak
This commit is contained in:
parent
0179e52eb2
commit
d57a2d053a
@ -122,8 +122,10 @@ abstract class Tiebreaks extends Tournament
|
|||||||
return $points;
|
return $points;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Player $player
|
* @param Player $player
|
||||||
|
* @param int $cut
|
||||||
* @return float
|
* @return float
|
||||||
*/
|
*/
|
||||||
protected function calculateAverageRating(Player $player, int $cut = 0)
|
protected function calculateAverageRating(Player $player, int $cut = 0)
|
||||||
@ -145,6 +147,29 @@ abstract class Tiebreaks extends Tournament
|
|||||||
return round(array_sum($allratings) / count($allratings));
|
return round(array_sum($allratings) / count($allratings));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Player $player
|
||||||
|
* @param int $cut
|
||||||
|
* @return float
|
||||||
|
*/
|
||||||
|
protected function calculateAveragePerformance(Player $player, int $cut = 0)
|
||||||
|
{
|
||||||
|
$pairings = $player->getPairings();
|
||||||
|
$allratings = [];
|
||||||
|
foreach ($pairings as $pairing) {
|
||||||
|
if (array_search($pairing->getResult(), Constants::NotPlayed) === false) {
|
||||||
|
$toadd = $pairing->getOpponent()->getPerformance();
|
||||||
|
if ($toadd != 0) {
|
||||||
|
$allratings[] = $toadd;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sort($allratings);
|
||||||
|
$allratings = array_slice($allratings, $cut);
|
||||||
|
return round(array_sum($allratings) / count($allratings));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Player $player
|
* @param Player $player
|
||||||
* @param int $cut
|
* @param int $cut
|
||||||
|
@ -317,6 +317,9 @@ class Tournament extends Tiebreaks
|
|||||||
case Tiebreak::Cumulative:
|
case Tiebreak::Cumulative:
|
||||||
return $this->calculateCumulative($player);
|
return $this->calculateCumulative($player);
|
||||||
break;
|
break;
|
||||||
|
case Tiebreak::Performance:
|
||||||
|
return $this->calculateAveragePerformance($player);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user