mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-16 17:34:00 +00:00
parent
8a4b2324a1
commit
a05f53dae9
6 changed files with 8 additions and 6 deletions
|
@ -12,14 +12,14 @@ The [Hacker New's ranking algorithm](https://medium.com/hacking-and-gonzo/how-ha
|
||||||
|
|
||||||
## My Algorithm
|
## 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
|
Score = Upvotes - Downvotes
|
||||||
Time = time since submission (in hours)
|
Time = time since submission (in hours)
|
||||||
Gravity = Decay gravity, 1.8 is default
|
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.
|
- 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.
|
- A scale factor of 10k gets the rank in integer form.
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ create or replace function hot_rank(
|
||||||
returns integer as $$
|
returns integer as $$
|
||||||
begin
|
begin
|
||||||
-- hours_diff:=EXTRACT(EPOCH FROM (timezone('utc',now()) - published))/3600
|
-- 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; $$
|
end; $$
|
||||||
LANGUAGE plpgsql;
|
LANGUAGE plpgsql;
|
||||||
|
|
||||||
|
|
|
@ -294,6 +294,7 @@ mod tests {
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
parent_id: None,
|
parent_id: None,
|
||||||
removed: None,
|
removed: None,
|
||||||
|
read: None,
|
||||||
updated: None
|
updated: None
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -465,6 +465,7 @@ mod tests {
|
||||||
creator_id: inserted_user.id,
|
creator_id: inserted_user.id,
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
removed: None,
|
removed: None,
|
||||||
|
read: None,
|
||||||
parent_id: None,
|
parent_id: None,
|
||||||
updated: None
|
updated: None
|
||||||
};
|
};
|
||||||
|
|
|
@ -259,7 +259,7 @@ mod tests {
|
||||||
score: 1,
|
score: 1,
|
||||||
upvotes: 1,
|
upvotes: 1,
|
||||||
downvotes: 0,
|
downvotes: 0,
|
||||||
hot_rank: 864,
|
hot_rank: 1728,
|
||||||
published: inserted_post.published,
|
published: inserted_post.published,
|
||||||
updated: None,
|
updated: None,
|
||||||
subscribed: None,
|
subscribed: None,
|
||||||
|
@ -284,7 +284,7 @@ mod tests {
|
||||||
score: 1,
|
score: 1,
|
||||||
upvotes: 1,
|
upvotes: 1,
|
||||||
downvotes: 0,
|
downvotes: 0,
|
||||||
hot_rank: 864,
|
hot_rank: 1728,
|
||||||
published: inserted_post.published,
|
published: inserted_post.published,
|
||||||
updated: None,
|
updated: None,
|
||||||
subscribed: None,
|
subscribed: None,
|
||||||
|
|
|
@ -21,7 +21,7 @@ export function hotRank(comment: Comment): number {
|
||||||
let now: Date = new Date();
|
let now: Date = new Date();
|
||||||
let hoursElapsed: number = (now.getTime() - date.getTime()) / 36e5;
|
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}`);
|
// console.log(`Comment: ${comment.content}\nRank: ${rank}\nScore: ${comment.score}\nHours: ${hoursElapsed}`);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue