/** * Given a team ('A'/'B'), determines new team rating. * * @param string $team * @return float */ protected function getNewTeamRating($team) { $inputRatingFunction = 'getTeam' . $team . 'Rating'; if ($this->matchResult->getHigherTeam() == MatchResult::TEAMS_EQUAL) { // team's ranking points equal before game if ($this->matchResult->getResult() == MatchResult::DRAW) { // no change return $this->ratingsInput->{$inputRatingFunction}(); } if ($this->matchResult->getResult() == $team) { // this team wins and gets points increase return $this->ratingsInput->{$inputRatingFunction}() + $this->exchange->getExchangeAmount(); } // team lost return $this->ratingsInput->{$inputRatingFunction}() - $this->exchange->getExchangeAmount(); } if ($this->matchResult->getHigherTeam() == $team) { // team in question is higher ranked before game if ($this->matchResult->getResult() == $team) { // team won return $this->ratingsInput->{$inputRatingFunction}() + $this->exchange->getExchangeAmount(); } // team lost or drew, as they're higher ranked they lose points return $this->ratingsInput->{$inputRatingFunction}() - $this->exchange->getExchangeAmount(); } // if we get here we're dealing with lower-ranked team before game if ($this->matchResult->getResult() == $team || $this->matchResult->getResult() == MatchResult::DRAW) { // lower ranked team gains points from win or draw return $this->ratingsInput->{$inputRatingFunction}() + $this->exchange->getExchangeAmount(); } // lower ranked team lost return $this->ratingsInput->{$inputRatingFunction}() - $this->exchange->getExchangeAmount(); }
/** * Calculates rating points exchange between teams and returns it. * * @return float the points exchange * @throws InvalidMatchResultException if cannot determine match result */ public function calculate() { $base = $this->ratingsGap / Calculate::MAX_RATINGS_GAP; if ($this->matchResult->isUnderdogWin() || $this->matchResult->equalsWin()) { $this->exchangeAmount = 1 + $base; $this->applyWeightings(); return $this->exchangeAmount; } if ($this->matchResult->isHigherTeamWin()) { $this->exchangeAmount = 1 - $base; $this->applyWeightings(); return $this->exchangeAmount; } if ($this->matchResult->getResult() == MatchResult::DRAW) { $this->exchangeAmount = $base; $this->applyWeightings(); return $this->exchangeAmount; } throw new InvalidMatchResultException('Cannot calculate exchange: Invalid MatchResult Type'); }