2

I already have a 5 star rating system in place (user votes 1-5...and average score is displayed - i have a page where they vote and it inserts into the DB there username and vote), however I now want to improve it by integrating some sort of weight which functions solely to increase the impact your vote has on the average score of the content. It makes your vote "weigh" more than it would otherwise.

I currently have a $level (which is a number between 1-10 each user has...where 10 is the highest therefore having the most effect) which I'd like to use for consideration.

I'm just not sure on how to go by doing this.

apaderno
  • 28,547
  • 16
  • 75
  • 90
user962026
  • 207
  • 1
  • 5
  • 12

2 Answers2

2

The easiest way to do this is to just insert one vote into the DB for every level.

for($i = 0; $i < $level; $i++) {
    store_vote($user, $item);
}
ceejayoz
  • 176,543
  • 40
  • 303
  • 368
  • 1
    +1 for the simplest possible solution. Only downside I see here is you can't recalculate later - I'd prefer a weighted approach so if the results come out weird, you could just change the weights and recalculate - but this certainly is the simplest way to do it and for some scenarios, it would work well. I'd be more inclined to use this if it was a simple "power users get two votes"; the risks inherent to not being able to revise the weights would make me hesitant to use this for a 10-point scale. – Thaeli Nov 03 '11 at 04:30
1

If a user has level X, you can make his/her vote weigh X level 1 votes. You can add another field "weight" to the table, and show an average of vote*weight:

SELECT AVG(weight * vote)
FROM rating
WHERE item = ? 

(where ? is you needed id)

If you think this is too complicated for your needs (and you already store the user that made the vote), you can use this query:

SELECT AVG(r.weight * u.level)
FROM rating
JOIN user ON r.user_id = u.id
WHERE r.item = ?
Gabi Purcaru
  • 30,940
  • 9
  • 79
  • 95
  • so the weight column in the table would contain the users vote*level? – user962026 Nov 03 '11 at 04:15
  • @user962026 I'm sorry for the last comment (misread something): the weight column would be the user's level (you can name it 'level' if it suits you more). I named it 'weight' because you may change that independently from the 'level', for example on a logarithmic scale. – Gabi Purcaru Nov 03 '11 at 04:17