-1
我嘗試這個趨勢算法,以MySQL查詢蟒蛇MySQL查詢
# Rewritten code from /r2/r2/lib/db/_sorts.pyx
from datetime import datetime, timedelta
from math import log
epoch = datetime(1970, 1, 1)
def epoch_seconds(date):
td = date - epoch
return td.days * 86400 + td.seconds + (float(td.microseconds)/1000000)
def score(ups, downs):
return ups - downs
def hot(ups, downs, date):
s = score(ups, downs)
order = log(max(abs(s), 1), 10)
sign = 1 if s > 0 else -1 if s < 0 else 0
seconds = epoch_seconds(date) - 1134028003
return round(sign * order + seconds/45000, 7)
MySQL表有 up_count down_count CREATED_DATE 這可能轉換?
我發現這一點,但這有一個bug,如果down_vode越大,那麼你必須LOG10(零),這將崩潰
ORDER BY
LOG10(ABS(thumbs_up - thumbs_down) + 1) * SIGN(thumbs_up - thumbs_down)
+ (UNIX_TIMESTAMP(created)/300000) DESC
LIMIT 100