Closed aminvakil closed 5 years ago
Please be more specific. Provide an example prediction and match home/away goal values for which is fails.
Last night was a game between Lyon and Barcelona which ended 0:0, one of users predicted 2:2 but he didn't recieve any points. There was another game between bayern and liverpool which ended 0:0 too and another user which predicted 2:2 didn't recieve any points either.
But another games which didn't draw was all good, for example ajax real madrid ended 1:2 and user predicted 0:2 get result well.
I'll try to reproduce it. Meanwhile, could you check in your DB and verify that the results for these two matches were fetched correctly from the API?
Yes I checked. Actually I changed the scoring system which in my system person who guesses the difference correctly but only with one step wrong gets score too.
For example if the match ends 1-1 users who predicted 0-0 and 2-2 will get score but not user who predicted 3-3.
The code that measures this goes as follow:
if (($this->homeGoals === $match->getHomeGoals()) && ($this->awayGoals === $match->getAwayGoals())) {
return self::POINTS_EXACT;
} else if (($this->homeGoals - $this->awayGoals) === ($match->getHomeGoals() - $match->getAwayGoals())) {
if (abs($this->homeGoals - $match->getHomeGoals) === 1)
return self::POINTS_DIFFERENCE;
} else if ($this->getResultOutcome() === $match->getResultOutcome()) {
return self::POINTS_OUTCOME;
}
Last night users who predicted 1-1 got the POINTS_DIFFERENCE
as the game ends 0-0, but users which predicted 2-2 didn't get any points and I had to change database manually.
As I said in my previous comment this only goes for draws and we had matches which users got POINTS_OUTCOME
correctly.
getResultOutcome
function in both src/Devlabs/SportifyBundle/Entity/Prediction.php
& src/Devlabs/SportifyBundle/Entity/Match.php
are like this:
public function getResultOutcome()
{
if ($this->homeGoals > $this->awayGoals) {
return '1';
} else if ($this->homeGoals < $this->awayGoals) {
return '2';
}
return 'X';
}
Does it have to do something with X
and if it is like that why we didn't have this problem with previous api?
I think the logic you've introduced to Prediction->calculatePoints
method is flawed.
I believe what you were trying to achieve should be done with this logic for calculatePoints
:
if (($this->homeGoals === $match->getHomeGoals()) && ($this->awayGoals === $match->getAwayGoals())) {
return self::POINTS_EXACT;
} else if ($this->getResultOutcome() === $match->getResultOutcome()) {
if (($this->homeGoals - $this->awayGoals) === ($match->getHomeGoals() - $match->getAwayGoals()) && $this->getResultOutcome() !== 'X')
return self::POINTS_DIFFERENCE;
return self::POINTS_OUTCOME;
}
return 0;
Note: I believe you should exclude draws from goal difference calc, as then it's always 0. But that's just my common sense assumption. Change this if you like.
Also what's the idea behind this line:
if (abs($this->homeGoals - $match->getHomeGoals) === 1)
If a match ends 2-1, and there are two predictions: 3-2 and 4-3, then you would reward only the 3-2 prediction with POINTS_DIFFERENCE.
Is that your goal?
Edit: Also $match->getHomeGoals
should be $match->getHomeGoals()
If the game ends 1-1 both users predicting 0-0 and 2-2 should get POINTS_DIFFERENCE because they guessed near the actual goal, both if a user predicts 3-3 he/she should only get POINTS_OUTCOME as users predicting 0-0 and 2-2 were more accurate. Also this is my sense. If you don't agree let's agree to disagree:)
If a match ends 2-1, and there are two predictions: 3-2 and 4-3, then you would reward only the 3-2 prediction with POINTS_DIFFERENCE. Is that your goal?
Yes.
I suppose my $match->getHomeGoals instead of $match->getHomeGoals() is disrupting the correct way of calculating points. I will change it and hope a match ends with draw and wait to see if the sportify calculates the score correctly.
If it's ok I will keep this issue open unitl we figure out what caused the problem.
If that's your intended logic for the goal-difference, then I would suggest you build your code like this:
if (($this->homeGoals === $match->getHomeGoals()) && ($this->awayGoals === $match->getAwayGoals())) {
return self::POINTS_EXACT;
} else if ($this->getResultOutcome() === $match->getResultOutcome()) {
if (
($this->homeGoals - $this->awayGoals) === ($match->getHomeGoals() - $match->getAwayGoals())
&& abs($this->homeGoals - $match->getHomeGoals()) == 1
)
return self::POINTS_DIFFERENCE;
return self::POINTS_OUTCOME;
}
return 0;
I didn't want to get into knowing how parentheses go and stuff:)
I think my logic doesn't have any difference with your logic.
Why your return self::POINTS_OUTCOME
doesn't have any condition?
return self::POINTS_OUTCOME
doesn't need a condition because the function logic can gets to this line only in one condition (because we'd have already returned something and exited the function if any of the previous conditions were met).
It's similar to the return 0
at the end.
I noticed now that the condition you comment above is different from the one which it's in the code.
Unfortunately none of the matches tonight ends with draw result:(
Therefore I will wait to be sure that the problem was from $match->getHomeGoals()
and not changing the api to v2.
I pulled the request myself and I know that changing the api doesn't have anything to do with point function, but I have to be sure that the problem is resolved, if it's ok I will keep the issue open.
Okay, let's see what happens. Drop a line when you validate it.
getResultOutcome function is not working properly either for match or the prediction on draw, therefore the system is not giving any point for draw.