Simple popularity algorithm (using date submitted and # of votes)
I run a digg-like website that promotes content to the front page when it reaches a certain number of votes. Right now it doesn't take date submitted into consideration.
I'd like to use a simple algorithm that just uses the number of votes and the date submitted to determine whether something should be promoted. I don't want the algorithm to do anything more complex then that (such as iterating over all the vote dates).
EDIT:
Shouldn't the formula be something like this:
30 / (days between post date and now) * (vote count) = weighted vote
Here are some scenarios which seem reasonable for my site, which indicates that the algorithm needs to be more lenient for older items (since older items 开发者_JS百科are less discoverable on the site)
30 / 30 * 30 = 30 (30 days old, promoted with 30 votes)
30 / 5 * 15 = 90 (5 days old, promoted with 15 votes) 30 / 1 * 10 = 300 (1 day old, promoted with 10 votes)How can the formula be modified so the above 3 give close to the same min weighted vote required for promotion?
You can use the difference between the current date and the submission date to weight the votes.
(threshold - (days between post date and now))/threshold * (vote count) = weighted vote
in code
$weightedVote = ($threshold - $daysOld) / $threshold * $voteCount;
This would have the effect of eliminating posts older than the threshold from consideration. For example, a post 10 days old would have its votes multiplied by 20/30.
Is there a reason why you are assigning an arbitrary number to content when the condition is vote based? I mean - it seems you'd be better off weighing the users and their votes rather than giving a piece of content more or less votes based on the date. I wrote some pretty mean voting software for a company that had $10,000 + contests and our algorithm considered the user and their history of behavior, which ended up filtering out a lot of spam votes.
This sounds complex but it is not really.
As for your balancing code - You want 1 day old content to be promoted at 10 votes, where a 30 day item requires 30 votes? Or do you mean 1 day content with 10 votes is promoted, while a 30 day item with, say, 6 votes could be promoted because it is older and less likely to be seen, so the vote tolerance is reduced?
function daysDifference($endDate, $beginDate)
{
$date_parts1=explode("-", $beginDate);
$date_parts2=explode("-", $endDate);
$start_date=gregoriantojd($date_parts1[1], $date_parts1[2], $date_parts1[0]);
$end_date=gregoriantojd($date_parts2[1], $date_parts2[2], $date_parts2[0]);
return $end_date - $start_date;
}
$diff = 30 - daysDifference(date("Y-m-d"), $postdate);
if($diff > 0)
$weight = 30 / $diff + $votes;
else
$weight = $votes;
So, suppose the daysDifference function returned 26 and there were 4 votes originally. This would read 30 / (30 - 26 = 4) = 7.4 + 4 So 11.4 votes total. For a one day old item with 10 votes, it would read 30 / (30 - 1 = 29) = 1.03 + 10. So 11.03 total. Roughly the same for this sample, but will vary for others. The if means that any content over 30 days is just not considered and their votes are equal to actual value.
I could have just misunderstood your needs though.
精彩评论