Reputation: 1306
I'm developing a web application similar to Digg and I need an algorithm which would be used to order the posts by popularity. For instance: on first page I want to have today's most popular posts and few from days before which have reached enough votes. My db looks like this at the moment:
Table | fields
Posts | id | ... | time
Feedback | id | userid | time | upvote
The upvote field is bool. If positive it means user clicked the up-vote button.
My tables can be modified, since they are empty.
Any help will be appreciated
Upvotes: 2
Views: 777
Reputation: 18843
Personally I like taking a more sophisticated approach. The general idea is that a cron processor runs every 5 minutes to calculate the popularity of each entity based on the criteria you mentioned as well as a user based standard deviation to eliminate the obvious rally of gang votes to boost content within their own social circle.
Take a look at Lawson's answer for a good idea for factoring the age of a vote. But consider that it may be useful to apply a user's own weight based on reputation, seniority, etc.
The unfortunate part of this is that it is not simple. Though I find it more fun than most web programming, factoring in all basic psychologies for gaming the system can be a very time consuming process and may not be what you have in mind unless you happen to work for Digg itself, or be a part of a serious start up.
Here's the php.net standard deviation: http://php.net/manual/en/function.stats-standard-deviation.php
Although I think this SO answer is more to the point: z-Scores(standard deviation and mean) in PHP
Code samples may be nice, but we would need some of your data to do so and even then, this could get quite complex. But it is definitely fun. Especially when your code finds people trying to game the system.
Upvotes: 2
Reputation: 636
If I understand you correctly, you want a vote's value to be inversely proportional to it's age. (The older a vote is, the less it counts towards your popularity index.)
A simple way to achieve this is to convert votes to popularity units (PUs), and sum not just simple votes, but PUs instead. The construction of a PU could be as simple as making it equal to 1/(the vote's age in days or hours). A one-day old vote would be worth 1 PU, while a 2 day old vote would be worth half that.
Upvotes: 5