Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

More changes to the ranking algorithm.

  • Loading branch information...
commit c88948279e56d58cb9462863c84a00042c81deb7 1 parent b7d7d86
@antirez authored
Showing with 10 additions and 5 deletions.
  1. +7 −3 app.rb
  2. +3 −2 app_config.rb
View
10 app.rb
@@ -1236,7 +1236,8 @@ def compute_news_score(news)
# The general forumla is RANK = SCORE / (AGE ^ AGING_FACTOR)
def compute_news_rank(news)
age = (Time.now.to_i - news["ctime"].to_i)+NewsAgePadding
- return (news["score"].to_f)/((age+3600)**RankAgingFactor)
+ return 0 if (age > TopNewsAgeLimit)
+ return ((news["score"].to_f-1)*1000000)/((age+NewsAgePadding)**RankAgingFactor)
end
# Add a news with the specified url or text.
@@ -1436,8 +1437,10 @@ def news_to_html(news)
}
}+
if params and params[:debug] and $user and user_is_admin?($user)
+ "id: "+news["id"].to_s+" "+
"score: "+news["score"].to_s+" "+
- "rank: "+compute_news_rank(news).to_s
+ "rank: "+compute_news_rank(news).to_s+" "+
+ "zset_rank: "+$r.zscore("news.top",news["id"]).to_s
else "" end
}+"\n"
end
@@ -1476,7 +1479,8 @@ def news_list_to_html(news)
# Note: this function can be called in the context of redis.pipelined {...}
def update_news_rank_if_needed(n)
real_rank = compute_news_rank(n)
- if (real_rank-n["rank"].to_f).abs > 0.001
+ delta_rank = (real_rank-n["rank"].to_f).abs
+ if delta_rank > 0.000001
$r.hmset("news:#{n["id"]}","rank",real_rank)
$r.zadd("news.top",real_rank,n["id"])
n["rank"] = real_rank.to_s
View
5 app_config.rb
@@ -36,16 +36,17 @@
DeletedUser = {"username" => "deleted_user", "email" => "", "id" => -1}
# News and ranking
-NewsAgePadding = 60*60*8
+NewsAgePadding = 3600*8
TopNewsPerPage = 30
LatestNewsPerPage = 100
NewsEditTime = 60*15
NewsScoreLogStart = 10
NewsScoreLogBooster = 2
-RankAgingFactor = 1.1
+RankAgingFactor = 1.5
PreventRepostTime = 3600*48
NewsSubmissionBreak = 60*15
SavedNewsPerPage = 10
+TopNewsAgeLimit = 3600*48
# Footer links
FooterTwitterLink = false
Please sign in to comment.
Something went wrong with that request. Please try again.