0

I'm working on an eCommerce and the idea is that the clients will leave a "grade" for the specific seller and this values is going to be used to calculate the seller's overall grade in the platform. The seller's table has a column grade that stores the average(mean) according to the clients.

For example: if the first client gives a 8/10, the current grade will be 8 and then the second gives 6.45 the grade will now be 7.225

  • 2
    That does not sound like the proper way to calculate it. For example, what happens if 99 people rate the seller with a 10 and one person rates the seller with a 1? In your example, the grade in this case would be 5, but really the grade should be 9.9. Instead of only storing the median value, you really need to store more information. – Moshe Katz May 30 '22 at 23:48
  • 1
    Yes, please add a 3rd data point to your question so we can know for sure if you want the median or the mean. – BenFenner May 30 '22 at 23:51
  • Hmm how so? basically what would happen is the sum of all grades divided by the number of people that voted. Using your example: (10+10+10....+1)/100 = 991/100=9.9 – Leandro Landim May 30 '22 at 23:54
  • What else can I store to get an accurate value? I have been trying to figure it out for so long! Thanks guys for answering btw – Leandro Landim May 30 '22 at 23:55
  • 1
    Median and average are two very different concepts which are calculated differently. It sounds like you want the average (also known as the mean), so I recommend editing your question to remove the word median, which is just causing confusion. – David Grayson May 31 '22 at 00:04

1 Answers1

1

Assuming you're comfortable getting all of the grades into an array, here's how to get the average/mean:
How do I create an average from a Ruby array?

I particularly like this answer: https://stackoverflow.com/a/3654560/14837782

BenFenner
  • 982
  • 1
  • 6
  • 12