Coder Social home page Coder Social logo

Comments (5)

rennokki avatar rennokki commented on May 30, 2024

Does this mean that your model rated twice the same rateable model? This seems a flaw.

from rating.

Dennis-Mwea avatar Dennis-Mwea commented on May 30, 2024

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

from rating.

rennokki avatar rennokki commented on May 30, 2024

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); 

from rating.

Dennis-Mwea avatar Dennis-Mwea commented on May 30, 2024

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

from rating.

stale avatar stale commented on May 30, 2024

This issue has been automatically closed because it has not had any recent activity. 😨

from rating.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.