Skip to content

Commit

Permalink
Penalize less for age (#198)
Browse files Browse the repository at this point in the history
And explain why questions aren't ordered by votes
  • Loading branch information
jonhoo authored Dec 28, 2024
1 parent cca8820 commit b87f660
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 6 additions & 0 deletions client/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@
{#if $event}
<main class="mx-auto my-4 max-w-4xl px-4">
<List />
<div class="mt-4 text-center text-slate-400">
Questions are ordered by <a
class="hover:text-black"
href="https://www.evanmiller.org/ranking-news-items-with-upvotes.html">votes over time</a
>.
</div>
<div class="mt-4 text-center text-slate-400">
( made on <a class="hover:text-black" href="https://github.com/jonhoo/wewerewondering"
>github</a
Expand Down
11 changes: 10 additions & 1 deletion server/src/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,19 @@ async fn list_inner(
)
.unwrap_or(Duration::ZERO)
.as_secs()
// in minutes so questions don't jump around quite as much
/ 60;
// +1 so that first minute questions don't get inf scores (for the ln)
let dt = dt_in_minutes_rounded_down + 1;
// +1 again to avoid NaN scores for first-minute questions (for / (1 - e^0)).
let dt = dt + 1;
// ln so that stories get less penalized for age over time
// after all, this is Q&A, not minute-to-minute hot news
let dt = (dt as f64).ln();
let votes = q["votes"].as_u64().expect("votes is a number") as f64;
let exp = (-1. * dt as f64).exp();
// max so that even if vote count somehow got to 0, count it as 1
let votes = votes.max(1.);
let exp = (-1. * dt as f64).exp_m1() + 1.;
Score(exp * votes / (1. - exp))
};
questions.sort_by_cached_key(|q| std::cmp::Reverse(score(q)));
Expand Down

0 comments on commit b87f660

Please sign in to comment.