Better names for ids and elos

Also fixed some bugs
This commit is contained in:
Jeroen De Meerleer 2019-05-31 10:33:17 +02:00
parent a1c669780e
commit c9a19bbcb2
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6
3 changed files with 23 additions and 14 deletions

View File

@ -137,7 +137,7 @@ class Player extends PlayerModel
$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)) {
$opponentElo = $pairing->getOpponent()->getElo('home'); $opponentElo = $pairing->getOpponent()->getElo('Nation');
$opponentElo = $opponentElo != 0 ? $opponentElo : $this->getUnratedElo(); $opponentElo = $opponentElo != 0 ? $opponentElo : $this->getUnratedElo();
if (array_search(self::Won, $pairing->getResult())) { if (array_search(self::Won, $pairing->getResult())) {
$total += $opponentElo + 400; $total += $opponentElo + 400;

View File

@ -306,7 +306,7 @@ class Pairtwo6 extends Pairtwo6Model implements ReaderInterface
$offset += $length; $offset += $length;
$length = 4; $length = 4;
$player->setId('world', $this->readData('Int', substr($swscontents, $offset, $length) . "")); $player->setId('Fide', $this->readData('Int', substr($swscontents, $offset, $length) . ""));
$offset += $length; $offset += $length;
$length = 4; $length = 4;
@ -314,7 +314,7 @@ class Pairtwo6 extends Pairtwo6Model implements ReaderInterface
$offset += $length; $offset += $length;
$length = 4; $length = 4;
$player->setElo('home', $this->readData('Int', substr($swscontents, $offset, $length))); $player->setElo('Nation', $this->readData('Int', substr($swscontents, $offset, $length)));
$offset += $length; $offset += $length;
$length = 4; $length = 4;
@ -322,7 +322,7 @@ class Pairtwo6 extends Pairtwo6Model implements ReaderInterface
$offset += $length; $offset += $length;
$length = 4; $length = 4;
$player->setId('home', $this->readData('Int', substr($swscontents, $offset, $length))); $player->setId('Nation', $this->readData('Int', substr($swscontents, $offset, $length)));
$offset += $length; $offset += $length;
$length = 4; $length = 4;
@ -330,7 +330,7 @@ class Pairtwo6 extends Pairtwo6Model implements ReaderInterface
$offset += $length; $offset += $length;
$length = 4; $length = 4;
$player->setId('club', $this->readData('Int', substr($swscontents, $offset, $length))); $player->setId('Club', $this->readData('Int', substr($swscontents, $offset, $length)));
$offset += $length; $offset += $length;
$length = 4; $length = 4;
@ -346,7 +346,7 @@ class Pairtwo6 extends Pairtwo6Model implements ReaderInterface
$offset += $length; $offset += $length;
$length = 4; $length = 4;
$player->setElo('world', $this->readData('Int', substr($swscontents, $offset, $length))); $player->setElo('Fide', $this->readData('Int', substr($swscontents, $offset, $length)));
$offset += $length; $offset += $length;
$length = 1; $length = 1;

View File

@ -136,7 +136,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()->getElos()['home']; $toadd = $pairing->getOpponent()->getElo('Nation');
if ($toadd != 0) { if ($toadd != 0) {
$allratings[] = $toadd; $allratings[] = $toadd;
} }
@ -159,7 +159,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(); $toadd = $pairing->getOpponent()->getPerformance('Nation');
if ($toadd != 0) { if ($toadd != 0) {
$allratings[] = $toadd; $allratings[] = $toadd;
} }
@ -200,10 +200,17 @@ abstract class Tiebreaks extends Tournament
$intpairings = $player->getPairings(); $intpairings = $player->getPairings();
usort($intpairings, function ($a, $b) { usort($intpairings, function ($a, $b) {
if ($b->getOpponent()->getElo('home') == $a->getOpponent()->getElo('home')) { if (is_null($a->getOpponent())) {
return -1;
}
if (is_null($b->getOpponent())) {
return 1;
}
if ($b->getOpponent()->getElo('Nation') == $a->getOpponent()->getElo('Nation')) {
return 0; return 0;
} }
return ($b->getOpponent()->getElo('home') > $a->getOpponent()->getElo('home')) ? 1 : -1; return ($b->getOpponent()->getElo('Nation') > $a->getOpponent()->getElo('Nation')) ? 1 : -1;
}); });
array_splice($intpairings, $cutlowest); array_splice($intpairings, $cutlowest);
@ -224,12 +231,14 @@ abstract class Tiebreaks extends Tournament
{ {
$tiebreak = 0; $tiebreak = 0;
foreach ($player->getPairings() as $key => $pairing) { foreach ($player->getPairings() as $key => $pairing) {
if ($pairing->getOpponent()) {
if (array_search($pairing->getResult(), Constants::Won) !== false) { if (array_search($pairing->getResult(), Constants::Won) !== false) {
$tiebreak += $pairing->getOpponent()->getPoints(); $tiebreak += $pairing->getOpponent()->getPoints();
} elseif (array_search($pairing->getResult(), Constants::draw) !== false) { } elseif (array_search($pairing->getResult(), Constants::Draw) !== false) {
$tiebreak += $pairing->getOpponent()->getPoints() / 2; $tiebreak += $pairing->getOpponent()->getPoints() / 2;
} }
} }
}
return $tiebreak; return $tiebreak;
} }