我正在寻找构建一个利用 Reddit(开源)算法的 Web 应用程序。
我计划随着时间的推移对其进行调整,但现在我认为使用他们的排名系统将是一个好的开始。
我读了一篇关于这个算法的博客文章,这个例子是用 Python 编写的。如何将其转换为在 ColdFusion 中使用?如果更容易,在 CFC 中使用的额外奖励积分?
编码:
#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):
"""Returns the number of seconds from the epoch to 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):
"""The hot formula. Should match the equivalent function in postgres."""
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(order + sign * seconds / 45000, 7)
讨论此代码的博客文章:http: //amix.dk/blog/post/19588
期待听到一些想法和例子。
非常感谢!迈克尔。
另外,作为一个附加问题;在已经收集了数据集之后,通过 SQL 查询或 ColdFusion 中的某种排序是否可以更好地执行此代码?我选择的数据库是 MySQL。
更新: 刚刚在这里发现了另一个与我所问的问题有关的问题......我认为它有帮助。 Reddit 和 Hacker News 排名算法是如何使用的?