Question

I've been wracking my brains for the past several hours on how I would get a rating between 0-10, see picture, using two values. Positive and Negative votes. I can already grab the votes from the database, and as an example, I'd like to use the following:

    Xn = Negative
    Xp = Positive

    50n / 100p
    24n / 12p
    32n / 0p (Would be 0)

     3n / 0p
     2n / 1p
     1n / 2p
     0n / 3p

Usually, I'd be rather quick at solving a problem like this. But due to my intense workload, I can't seem to figure it out.

I wouldn't usually ask for such an insane amount of assistance, but, for lack of any decent mathematical skill, I'm turning to you guys for help.

NOTE: The ratings within the picture are defined within a PHP Array. Quite literally the ratings you see. $ratings = array(5.4,10,7.4,8.3)

Was it helpful?

Solution

Rating = (Positive / Total Votes) * 10

Not sure how it could get any simpler than that...

$uvote = 10;
$dvote = 15;
$rating = 0 ? 0 : ($uvote / ($uvote + $dvote)) * 10; // 4
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top