The average rating returned not correct.
Dennis-Mwea opened this issue Β· comments
Am thinking the average rating should be a waited average. Not the average rating of total columns in the database. Something like:
βππ=1π€πβ
ππ
----------
βππ=1π€π
1β
5+2β
3+3β
1+4β
17+5β
2. 92 - (Weighted sum)
-------------------------- = ----
5+3+1+17+2 28 - (Total sum)
Does this mean that your model rated twice the same rateable model? This seems a flaw.
Not really. I have 3 models, User, Order and Courier (Courier delivery DB structure). A User can rate a Courier based on the Order he delivered. Assuming the 5 users rate the courier with a rating of 5 for 2 users, 3 for 2 users and 1 for one user, the courier rating can't be 5/5 but rather (total weighted sum/total weights)
(5*2) + (3*2) + (1*1)/(2+2+1)=3.4
https://math.stackexchange.com/questions/1909716/average-in-a-rating-between-1-and-5
Based on your example, it seems like the table with ratings looks like:
- 5
- 5
- 3
- 3
- 1
The sum is 17
, with total rows of 5
. The expected average is 17/5
which is equivalent to 3.4
.
This seems a bit odd. Pulling the ratings are expected to be working with the ->avg()
call.
Did you calculate the rating from the user's side? Did you call the average rating call like this?
$user->averageRating();
$user->averageRating(Courier::class);
No I pulled the changes from Courier side. $courier->averageRating(User::class) but the value I get is the average rating from db average not the weighted average
This issue has been automatically closed because it has not had any recent activity. π¨