Answer the question
In order to leave comments, you need to log in
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")
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question