mirror of
https://github.com/JeroenED/libpairtwo.git
synced 2024-11-24 15:31:00 +01:00
Merge branch 'task/tiebreak-arocut1' into develop
This commit is contained in:
commit
0ddc62c0b7
@ -70,7 +70,7 @@ abstract class Player
|
|||||||
/**
|
/**
|
||||||
* @return string[]
|
* @return string[]
|
||||||
*/
|
*/
|
||||||
public function getIds(): array
|
public function getIds(): ?array
|
||||||
{
|
{
|
||||||
return $this->Ids;
|
return $this->Ids;
|
||||||
}
|
}
|
||||||
@ -88,7 +88,7 @@ abstract class Player
|
|||||||
/**
|
/**
|
||||||
* @return int[]
|
* @return int[]
|
||||||
*/
|
*/
|
||||||
public function getElos(): array
|
public function getElos(): ?array
|
||||||
{
|
{
|
||||||
return $this->Elos;
|
return $this->Elos;
|
||||||
}
|
}
|
||||||
|
@ -458,8 +458,6 @@ class Pairtwo6 extends Pairtwo6Model implements ReaderInterface
|
|||||||
$player->setBinaryData("TieMatch", $this->readData('Int', substr($swscontents, $offset, $length)));
|
$player->setBinaryData("TieMatch", $this->readData('Int', substr($swscontents, $offset, $length)));
|
||||||
$offset += $length;
|
$offset += $length;
|
||||||
|
|
||||||
$player->setElos($elos);
|
|
||||||
$player->setIds($ids);
|
|
||||||
$this->getTournament()->addPlayer($player);
|
$this->getTournament()->addPlayer($player);
|
||||||
}
|
}
|
||||||
// PlayerNames
|
// PlayerNames
|
||||||
|
@ -141,20 +141,22 @@ abstract class Tiebreaks extends Tournament
|
|||||||
* @param Player $player
|
* @param Player $player
|
||||||
* @return float
|
* @return float
|
||||||
*/
|
*/
|
||||||
protected function calculateAverageRating(Player $player)
|
protected function calculateAverageRating(Player $player, int $cut = 0)
|
||||||
{
|
{
|
||||||
$pairings = $player->getPairings();
|
$pairings = $player->getPairings();
|
||||||
$totalrating = 0;
|
$totalrating = 0;
|
||||||
$totalopponents = 0;
|
$totalopponents = 0;
|
||||||
|
$allratings = [];
|
||||||
foreach ($pairings as $pairing) {
|
foreach ($pairings as $pairing) {
|
||||||
if (array_search($pairing->getResult(), self::NotPlayed) === false) {
|
if (array_search($pairing->getResult(), self::NotPlayed) === false) {
|
||||||
$toadd = $pairing->getOpponent()->getElos()['home'];
|
$toadd = $pairing->getOpponent()->getElos()['home'];
|
||||||
if ($toadd != 0) {
|
if ($toadd != 0) {
|
||||||
$totalrating += $toadd;
|
$allratings[] = $toadd;
|
||||||
$totalopponents++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return round($totalrating / $totalopponents);
|
sort($allratings);
|
||||||
|
$allratings = array_slice($allratings, $cut);
|
||||||
|
return round(array_sum($allratings) / count($allratings));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -264,7 +264,7 @@ class Tournament extends Tiebreaks
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return float|bool
|
* @return float|null
|
||||||
*/
|
*/
|
||||||
private function calculateTiebreak(Tiebreak $tiebreak, Player $player, int $tbkey = 0): ?float
|
private function calculateTiebreak(Tiebreak $tiebreak, Player $player, int $tbkey = 0): ?float
|
||||||
{
|
{
|
||||||
@ -293,6 +293,9 @@ class Tournament extends Tiebreaks
|
|||||||
case Tiebreak::Aro:
|
case Tiebreak::Aro:
|
||||||
return $this->calculateAverageRating($player);
|
return $this->calculateAverageRating($player);
|
||||||
break;
|
break;
|
||||||
|
case Tiebreak::AroCut:
|
||||||
|
return $this->calculateAverageRating($player, 1);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user