From: Dessalines Date: Sat, 20 Apr 2019 23:47:23 +0000 (-0700) Subject: Adding negative score fix X-Git-Url: http://these/git/%7B%60/feeds/%7B%60%24%7BwebArchiveUrl%7D/save/static/git-favicon.png?a=commitdiff_plain;h=a05f53dae97335431d767015f00735fbc3d6fc12;p=lemmy.git Adding negative score fix - Fixes #84. - Fixing unit tests. --- diff --git a/docs/ranking.md b/docs/ranking.md index f55a1284..34348c30 100644 --- a/docs/ranking.md +++ b/docs/ranking.md @@ -12,14 +12,14 @@ The [Hacker New's ranking algorithm](https://medium.com/hacking-and-gonzo/how-ha ## 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. diff --git a/server/migrations/2019-03-30-212058_create_post_view/up.sql b/server/migrations/2019-03-30-212058_create_post_view/up.sql index 2f71b6fb..3a509e29 100644 --- a/server/migrations/2019-03-30-212058_create_post_view/up.sql +++ b/server/migrations/2019-03-30-212058_create_post_view/up.sql @@ -5,7 +5,7 @@ create or replace function hot_rank( 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; diff --git a/server/src/actions/comment_view.rs b/server/src/actions/comment_view.rs index e8b96e3a..2e3ae058 100644 --- a/server/src/actions/comment_view.rs +++ b/server/src/actions/comment_view.rs @@ -294,6 +294,7 @@ mod tests { post_id: inserted_post.id, parent_id: None, removed: None, + read: None, updated: None }; diff --git a/server/src/actions/moderator.rs b/server/src/actions/moderator.rs index a97b2120..a0d7db6c 100644 --- a/server/src/actions/moderator.rs +++ b/server/src/actions/moderator.rs @@ -465,6 +465,7 @@ mod tests { creator_id: inserted_user.id, post_id: inserted_post.id, removed: None, + read: None, parent_id: None, updated: None }; diff --git a/server/src/actions/post_view.rs b/server/src/actions/post_view.rs index 28e5fb98..ba42fe27 100644 --- a/server/src/actions/post_view.rs +++ b/server/src/actions/post_view.rs @@ -259,7 +259,7 @@ mod tests { score: 1, upvotes: 1, downvotes: 0, - hot_rank: 864, + hot_rank: 1728, published: inserted_post.published, updated: None, subscribed: None, @@ -284,7 +284,7 @@ mod tests { score: 1, upvotes: 1, downvotes: 0, - hot_rank: 864, + hot_rank: 1728, published: inserted_post.published, updated: None, subscribed: None, diff --git a/ui/src/utils.ts b/ui/src/utils.ts index 61744e90..70b6e846 100644 --- a/ui/src/utils.ts +++ b/ui/src/utils.ts @@ -21,7 +21,7 @@ export function hotRank(comment: Comment): number { 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}`);