calculate score based on createdAt if submitted not available (i.e. post is pending)

This commit is contained in:
Sacha Greif 2013-01-13 12:34:29 +09:00
parent c934a3ecff
commit f7fff10572
2 changed files with 5 additions and 2 deletions

View file

@ -98,7 +98,7 @@ Template.post_edit.events = {
if(post.submitted == ''){
// this is the first time we are approving the post
Meteor.call('post_approve', selectedPostId);
}else{
}else if($('#submitted_date').exists()){
properties.submitted = parseInt(moment($('#submitted_date').val()+$('#submitted_time').val(), "MM/DD/YYYY HH:mm").valueOf());
}
}

View file

@ -14,6 +14,9 @@ var updateScore = function (collection, id, forceUpdate) {
var x = 1/Math.pow(n*24+2,1.3);
var object = collection.findOne(id);
// use submitted timestamp if available, else (for pending posts) calculate score using createdAt
var age = object.submitted || object.createdAt;
// use baseScore if defined, if not just use the number of votes
// note: for transition period, also use votes if there are more votes than baseScore
// var baseScore = Math.max(object.votes || 0, object.baseScore || 0);
@ -21,7 +24,7 @@ var updateScore = function (collection, id, forceUpdate) {
// now multiply by 'age' exponentiated
// FIXME: timezones <-- set by server or is getTime() ok?
var ageInHours = (new Date().getTime() - object.submitted) / (60 * 60 * 1000);
var ageInHours = (new Date().getTime() - object.age) / (60 * 60 * 1000);
// HN algorithm
var newScore = baseScore / Math.pow(ageInHours + 2, 1.3);