2012-09-11 15:32:25 +10:00
|
|
|
// TODO: should the baseScore be stored, and updated at vote time?
|
|
|
|
|
|
|
|
// This interface should change and become more OO, this'll do for now
|
|
|
|
var Scoring = {
|
|
|
|
// re-run the scoring algorithm on a single object
|
|
|
|
updateObject: function(object) {
|
2012-09-17 12:51:35 +09:00
|
|
|
if(isNaN(object.score)){
|
|
|
|
object.score=0;
|
|
|
|
}
|
|
|
|
|
2012-09-11 15:32:25 +10:00
|
|
|
// just count the number of votes for now
|
2012-09-11 16:55:36 +10:00
|
|
|
var baseScore = object.votes;
|
2012-09-12 08:53:13 +09:00
|
|
|
|
2012-09-11 15:32:25 +10:00
|
|
|
// now multiply by 'age' exponentiated
|
|
|
|
// FIXME: timezones <-- set by server or is getTime() ok?
|
|
|
|
var ageInHours = (new Date().getTime() - object.submitted) / (60 * 60 * 1000);
|
|
|
|
|
2012-09-12 08:53:13 +09:00
|
|
|
// object.score = baseScore * Math.pow(ageInHours + 2, -0.1375);
|
|
|
|
|
|
|
|
// debug: just add 1 to the score for each new vote
|
2012-09-17 12:51:35 +09:00
|
|
|
object.score += 1;
|
|
|
|
|
2012-09-11 15:32:25 +10:00
|
|
|
},
|
|
|
|
|
|
|
|
// rerun all the scoring
|
|
|
|
updateScores: function() {
|
|
|
|
Posts.find().forEach(function(post) {
|
|
|
|
Scoring.updateObject(post);
|
|
|
|
Posts.update(post._id, {$set: {score: post.score}});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|