开发者

PHP voting intensity/force?

Well I'm thinking of adding a rating feature to my application where members can vote between 1-5 (this is the $rating) , and I display the average score like $score = $number_of_voters / $rating. Where $number_of_voters is the total count of members voted on that specific item, and $rating is the total rating for 开发者_如何学Cthat specific item.

That way the $score can't be higher then 5 (which its out of).

However I'm thinking of integrating a voting intensity/force according to the users RPG level (which is a number between 1-8 which gradually can increase - which each member has assigned), so if for example they voted and their RPG level was 1 the average score would'nt be too different from the previous (wouldnt effect it too much) however if it was something like 8 then it would effect it more? (too summarise their RPG level would be considered internally when voting).

But not sure how to proceed (how to integrate/implement) without effecting the intial specification (ie. I don't want the score going higher then 5 (want it to be $score <= 5)).


To address your immediate question, you can multiply by a fractional weight 0-1. If you have various levels, you can get this weight by dividing the user's level by the maximum level.

But before you get started coding, you should read How Not To Sort By Average Rating so that you avoid some of the common pitfalls with this kind of voting system.


Each user contributes (weight)*(rating) to the overall rating, so the numerator is the sum of this over all users.

The denominator is the maximum possible score, for each user this is (weight)*5. Thus the denominator is the sum of this over all users.

Then compute the score as:

sum{ (user i's weight) * (user i's rating) } / sum{ (user i's weight) * 5 }

Notice however, this gives you a score in the range of 0-1, if you want the score in the range 0-5 you can normalize by 5, this removes the factor 5 in the denominator.

Supposing you had two arrays, one of ratings (the i-th item corresponds to the i-th user's rating) $ratings and one of weights (the i-th item corresponds to the i-th user's RPG level) $weights you can compute this as:

$numer = 0;
$denom = 0;
for($i = 0; $i < count($ratings); $i++){
    $numer = $weights[$i]*$ratings[$i];
    $denom = $weights[$i];
}
$avg = $numer / $denom;


Try doing something like this... A level 1 users vote counts as 1 vote, while a level 8 users vote counts as 8 votes:

$thisvote = $level * $vote; 
//a user with a level 5, and a vote of 5...this is 25
$total = ($total + $thisvote) / $level + 1;
//if total was 4, 25+4 = 29, 29 / 6 = 4.83

This is easier than using arrays if you are not actually storing every user who voted and what their vote was.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜