3 ms·
An idea for how to store ratings
I am putting a "rating" field in one of my tables, and I figured out a good way to store them: DECIMAL(10,9) in MySQL, but more generally, as a fraction that goes from -1 to 1.
Why not 1 to 5 or some other value?
Two main reasons:
A) -1 to 1 is a normalized range that you can scale to anything easily
B) A non-vote counts as a middle-of the range vote. That's really cool.
So that means people who don't vote are the same as people who vote right in the middle, and so you only have to store a total participant count rather than an additional voter_count. This system seems to make for fair ratings that can be compared between items. What do you think?
PS: How about storing DECIMAL(10, 10) so no one has a perfect -1 or perfect 1 rating ever? You'll get 1 more digit of precision that way.
- Travis 16y agoAre you just storing it as a quick way to get the score with tallying votes? A) I can normalize something scaled on 1 to 5 just as easily as -1 to 1. Is it that much harder using 3 as your middle, as opposed to 0? As a bonus, you don't have to account for negative numbers when you display stuff. B) A non-vote could just as easily count as a 3. I'm not suggesting your solution wouldn't work, but I will say that I don't see the reasons listed as very compelling.
- EGreg 16y agoWhen I say a non-vote, though, I mean a real non-vote. Like, the person did not submit a vote. The total number of participants went up, but the rating stayed the same. If a non-vote was anything other than 0, this wouldn't work.