Closed aminvakil closed 6 years ago
Check this class: Devlabs\SportifyBundle\Entity\Prediction
.
You can change its constants POINTS_OUTCOME and POINTS_EXACT to something you prefer.
Also calculatePoints
method in this class does the points calculation for a prediction. Inside it, you can implement whatever logic you like for points calculation, including goal difference.
I changed the POINTS_OUTCOME and POINTS_EXACT. This is the code written for exact and outcome, can you please add goal_difference to it for me? I just know some linux, I don't know any symphony sadly.
if (($this->homeGoals === $match->getHomeGoals()) && ($this->awayGoals === $match->getAwayGoals())) {
return self::POINTS_EXACT;
} else if ($this->getResultOutcome() === $match->getResultOutcome()) {
return self::POINTS_OUTCOME;
}
As they are not identical I guessed I should use == instead of ===, is this code correct?
if (($this->homeGoals === $match->getHomeGoals()) && ($this->awayGoals === $match->getAwayGoals())) {
return self::POINTS_EXACT;
} else if (($this->homeGoals - $this->awayGoals) == ($match->getHomeGoals - $match->getAwayGoals)) {
return self::POINTS_DIFFERENCE;
} else if ($this->getResultOutcome() === $match->getResultOutcome()) {
return self::POINTS_OUTCOME;
}
Both calculations should yield an integer, so === is actually ok.
You logic is pretty much ok, you've only misused $match->getHomeGoals
and $match->getAwayGoals
, those are methods so you need to have parentheses, i.e call them.
So here's the corrected version of your code:
if (($this->homeGoals === $match->getHomeGoals()) && ($this->awayGoals === $match->getAwayGoals())) {
return self::POINTS_EXACT;
} else if (($this->homeGoals - $this->awayGoals) === ($match->getHomeGoals() - $match->getAwayGoals())) {
return self::POINTS_DIFFERENCE;
} else if ($this->getResultOutcome() === $match->getResultOutcome()) {
return self::POINTS_OUTCOME;
}
return 0;
I want to change scoring system to something I prefer more. How can I do that?
It's basically just this with little differences. For example: 6 points for exact score instead of 3
Also how can I implement scoring for goal difference?