hot sort - more spicy pls (experiment)

This commit is contained in:
rimu 2024-04-14 07:59:24 +12:00
parent 2c99d5eea0
commit 75c3f7c8be
5 changed files with 30 additions and 7 deletions

View file

@ -1037,7 +1037,13 @@ def downvote_post(post, user):
if not existing_vote:
effect = -1.0
post.down_votes += 1
post.score -= 1.0
# Make 'hot' sort more spicy by amplifying the effect of early downvotes
if post.up_votes + post.down_votes <= 30:
post.score -= 5.0
elif post.up_votes + post.down_votes <= 60:
post.score -= 2.0
else:
post.score -= 1.0
vote = PostVote(user_id=user.id, post_id=post.id, author_id=post.author.id,
effect=effect)
post.author.reputation += effect
@ -1139,10 +1145,18 @@ def upvote_post(post, user):
user.last_seen = utcnow()
user.recalculate_attitude()
effect = instance_weight(user.ap_domain)
# Make 'hot' sort more spicy by amplifying the effect of early upvotes
spicy_effect = effect
if post.up_votes + post.down_votes <= 10:
spicy_effect = effect * 10
elif post.up_votes + post.down_votes <= 30:
spicy_effect = effect * 5
elif post.up_votes + post.down_votes <= 60:
spicy_effect = effect * 2
existing_vote = PostVote.query.filter_by(user_id=user.id, post_id=post.id).first()
if not existing_vote:
post.up_votes += 1
post.score += effect
post.score += spicy_effect
vote = PostVote(user_id=user.id, post_id=post.id, author_id=post.author.id,
effect=effect)
if post.community.low_quality and effect > 0:

View file

@ -184,7 +184,7 @@ def show_community(community: Community):
if sort == '' or sort == 'hot':
posts = posts.order_by(desc(Post.sticky)).order_by(desc(Post.ranking)).order_by(desc(Post.posted_at))
elif sort == 'top':
posts = posts.filter(Post.posted_at > utcnow() - timedelta(days=7)).order_by(desc(Post.sticky)).order_by(desc(Post.score))
posts = posts.filter(Post.posted_at > utcnow() - timedelta(days=7)).order_by(desc(Post.sticky)).order_by(desc(Post.up_votes - Post.down_votes))
elif sort == 'new':
posts = posts.order_by(desc(Post.posted_at))
elif sort == 'active':

View file

@ -114,7 +114,7 @@ def home_page(type, sort):
if sort == 'hot':
posts = posts.order_by(desc(Post.ranking)).order_by(desc(Post.posted_at))
elif sort == 'top':
posts = posts.filter(Post.posted_at > utcnow() - timedelta(days=1)).order_by(desc(Post.score))
posts = posts.filter(Post.posted_at > utcnow() - timedelta(days=1)).order_by(desc(Post.up_votes - Post.down_votes))
elif sort == 'new':
posts = posts.order_by(desc(Post.posted_at))
elif sort == 'active':

View file

@ -303,11 +303,20 @@ def post_vote(post_id: int, vote_direction):
if vote_direction == 'upvote':
effect = 1
post.up_votes += 1
post.score += 1
# Make 'hot' sort more spicy by amplifying the effect of early upvotes
if post.up_votes + post.down_votes <= 10:
post.score += 5
elif post.up_votes + post.down_votes <= 100:
post.score += 2
else:
post.score += 1
else:
effect = -1
post.down_votes += 1
post.score -= 1
if post.up_votes + post.down_votes <= 100:
post.score -= 2
else:
post.score -= 1
vote = PostVote(user_id=current_user.id, post_id=post.id, author_id=post.author.id,
effect=effect)
# upvotes do not increase reputation in low quality communities

View file

@ -77,7 +77,7 @@ def show_topic(topic_path):
if sort == '' or sort == 'hot':
posts = posts.order_by(desc(Post.ranking)).order_by(desc(Post.posted_at))
elif sort == 'top':
posts = posts.filter(Post.posted_at > utcnow() - timedelta(days=7)).order_by(desc(Post.score))
posts = posts.filter(Post.posted_at > utcnow() - timedelta(days=7)).order_by(desc(Post.up_votes - Post.down_votes))
elif sort == 'new':
posts = posts.order_by(desc(Post.posted_at))
elif sort == 'active':