- Fixes #84.
- Fixing unit tests.
## My Algorithm
```
-Rank = ScaleFactor * sign(Score) * log(1 + abs(Score)) / (Time + 2)^Gravity
+Rank = ScaleFactor * sign(3 + Score) * log(abs(3 + Score)) / (Time + 2)^Gravity
Score = Upvotes - Downvotes
Time = time since submission (in hours)
Gravity = Decay gravity, 1.8 is default
```
-- Add 1 to the score, so that the standard new comment score of +1 will be affected by time decay. Otherwise all new comments would stay at zero, near the bottom.
+- Add 3 to the score, so that even minimally downvoted comments will be affected by time decay. Otherwise all new comments would stay at zero, near the bottom.
- The sign and abs of the score are necessary for dealing with the log of negative scores.
- A scale factor of 10k gets the rank in integer form.
returns integer as $$
begin
-- hours_diff:=EXTRACT(EPOCH FROM (timezone('utc',now()) - published))/3600
- return floor(10000*sign(score)*log(1 + abs(score)) / power(((EXTRACT(EPOCH FROM (timezone('utc',now()) - published))/3600) + 2), 1.8))::integer;
+ return floor(10000*sign(3+score)*log(abs(3+score)) / power(((EXTRACT(EPOCH FROM (timezone('utc',now()) - published))/3600) + 2), 1.8))::integer;
end; $$
LANGUAGE plpgsql;
post_id: inserted_post.id,
parent_id: None,
removed: None,
+ read: None,
updated: None
};
creator_id: inserted_user.id,
post_id: inserted_post.id,
removed: None,
+ read: None,
parent_id: None,
updated: None
};
score: 1,
upvotes: 1,
downvotes: 0,
- hot_rank: 864,
+ hot_rank: 1728,
published: inserted_post.published,
updated: None,
subscribed: None,
score: 1,
upvotes: 1,
downvotes: 0,
- hot_rank: 864,
+ hot_rank: 1728,
published: inserted_post.published,
updated: None,
subscribed: None,
let now: Date = new Date();
let hoursElapsed: number = (now.getTime() - date.getTime()) / 36e5;
- let rank = (10000 * Math.sign(comment.score) * Math.log10(1 + Math.abs(comment.score))) / Math.pow(hoursElapsed + 2, 1.8);
+ let rank = (10000 * Math.sign(3+comment.score) * Math.log10(Math.abs(3+comment.score))) / Math.pow(hoursElapsed + 2, 1.8);
// console.log(`Comment: ${comment.content}\nRank: ${rank}\nScore: ${comment.score}\nHours: ${hoursElapsed}`);