M
M
memba2015-06-04 15:36:09
Programming
memba, 2015-06-04 15:36:09

A tricky algorithm for sorting hot posts?

Hey!
I am thinking about a non-standard algorithm for sorting posts in the feed. Now I use the algorithm on the example of Reddit:

package main

import (
  "fmt"
  "math"
)

/**
 * Округление числа "x" точностью "precision"
 */ 
func Round(x float64, precision int) float64 {
  shift := math.Pow(10, float64(precision))
  return math.Floor((x * shift) + 0.5) / shift;	
}

/**
 * Расчет "жары" по голосам и времени публикации
 */
func Hotness(upvoices int, downvoices int, timestamp int) float64 {
  score := upvoices - downvoices
  order := math.Log10(math.Max(math.Abs(float64(score)), 1.0))
  sign := 0.0
  
  if score > 0 {
    sign = 1.0
  } else if score < 0 {
    sign = -1.0
  }
  
  damping := float64(60 * 60 * 48)
  seconds := float64(timestamp - 1433102400)
  
  return Round((order * sign) + (seconds / damping), 7)
}

func main() {
  fmt.Println("1)  0: ", Hotness(0,0, 1433416040), "time start")
  fmt.Println("2) -5: ", Hotness(0,5, 1433412440), "+1 hour")
  fmt.Println("3) +5: ", Hotness(5,0, 1433408840), "+2 hour")
  fmt.Println("4) +10:", Hotness(10,0, 1433405240), "+3 hour")
  fmt.Println("5)  0: ", Hotness(0,0, 1433401640), "+4 hour")
}

It works well if your feed only consists of hot posts, say posts that get a certain rating.
I would like to have a more versatile feed where new posts are kept at the top and if no one votes for them, they slowly slide down to make room for higher rated posts.
In other words, for example, a new post stays at the top of the feed for 15 minutes, if no one is interested in it, then it goes down and slowly goes into the depth of the feed.
Do you have any thoughts on this subject?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2015-06-04
@begemot_sun

use some function from the time the post was added and from the number of votes for the current assessment of the position of the post in the feed. For example:
F(t, n) = a * n + b/(Tt)
T is the current time.
Choose your own coefficients.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question