mirror of
https://github.com/vale981/Vulcan
synced 2025-03-06 10:01:40 -05:00
calculate score based on createdAt if submitted not available (i.e. post is pending)
This commit is contained in:
parent
c934a3ecff
commit
f7fff10572
2 changed files with 5 additions and 2 deletions
|
@ -98,7 +98,7 @@ Template.post_edit.events = {
|
||||||
if(post.submitted == ''){
|
if(post.submitted == ''){
|
||||||
// this is the first time we are approving the post
|
// this is the first time we are approving the post
|
||||||
Meteor.call('post_approve', selectedPostId);
|
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());
|
properties.submitted = parseInt(moment($('#submitted_date').val()+$('#submitted_time').val(), "MM/DD/YYYY HH:mm").valueOf());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,9 @@ var updateScore = function (collection, id, forceUpdate) {
|
||||||
var x = 1/Math.pow(n*24+2,1.3);
|
var x = 1/Math.pow(n*24+2,1.3);
|
||||||
var object = collection.findOne(id);
|
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
|
// 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
|
// note: for transition period, also use votes if there are more votes than baseScore
|
||||||
// var baseScore = Math.max(object.votes || 0, object.baseScore || 0);
|
// 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
|
// now multiply by 'age' exponentiated
|
||||||
// FIXME: timezones <-- set by server or is getTime() ok?
|
// 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
|
// HN algorithm
|
||||||
var newScore = baseScore / Math.pow(ageInHours + 2, 1.3);
|
var newScore = baseScore / Math.pow(ageInHours + 2, 1.3);
|
||||||
|
|
Loading…
Add table
Reference in a new issue