Question

We have need for a "rating" system in a project we are working on, similar to the one in SO. However, in ours there are multiple entities that need to be "tagged" with a vote up (only up, never down, like an increment). Sometimes we will need to show all of the entities in order of what is rated highest, regardless of entity type, basically mixing the result sets, I guess. What data structures / algorithms do you use to implement this so that is flexible and still scalable?

Was it helpful?

Solution

Since reddit's ranking algorithm rocks, it makes very much sense to have a look at it, if not copy it:


Given the time the entry was posted A and the time of 7:46:43 a.m. December 8, 2005 B we have ts as their difference in seconds:

ts = A - B

and x as the difference between the number of up votes U and the number of down votes D:

x = U - D

Where

y = 1 if x > 0
y = 0 if x = 0
y = -1 if x < 0

and z as the maximal value of the absolute value of x and 1:

z = |x| if |x| >= 1
z = 1 if |x| < 1

we have the rating as a function ƒ(ts, y, z):

ƒ(ts, y, z) = log10 z + (y • ts)/45000


Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top