View Full Version : Math for a php code :)

dsylebee

05-27-2009, 04:43 AM

Ok well this is what i came up with and I wanted to know if its a good way to make a rating average to do top 100 ranks etc..

so every different stuff that were voted all have a final average of x on 10 ( x/10 )

so to make a top 10 of those i would need to make a general rating variable and store in my database :) to use the order by and desc etc..

so what I came up with is

(overallAvg * votes) / (10 * votes) = x / 1000

TheShaner

05-27-2009, 02:57 PM

Ok well this is what i came up with and I wanted to know if its a good way to make a rating average to do top 100 ranks etc..

so every different stuff that were voted all have a final average of x on 10 ( x/10 )

so to make a top 10 of those i would need to make a general rating variable and store in my database :) to use the order by and desc etc..

so what I came up with is

(overallAvg * votes) / (10 * votes) = x / 1000

Your formula simplifies to:

overallAvg * votes / 10 * votes = x / 1000

overallAvg / 10 = x / 1000

overallAvg = x / 100

Which doesn't really do anything for you.

To find an average score, you do:

(score1 + score2 + ... + scoren) / n = avgScore

Where n equals total number of votes

To store it, you would want to either store every vote with the score they gave it, or you would store the total score and total votes. You could then calculate the overall average as you pulled it out of the DB, especially with the 2nd option:

SELECT (totalScore / totalVotes) AS overallAvg

FROM table

ORDER BY overallAvg DESC

LIMIT 100;

-Shane

Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.