将权重纳入 5 星投票系统?

发布于 2024-12-13 13:11:29 字数 237 浏览 4 评论 0原文

我已经有了一个 5 星级评级系统(用户投票 1-5...并显示平均分数 - 我有一个他们投票的页面,并将其插入数据库中的用户名和投票),但是我现在想要改进它通过整合某种权重来增加您的投票对内容平均得分的影响。它使您的投票比其他情况更“有分量”。

我目前有一个 $level (这是每个用户拥有的 1-10 之间的数字...其中 10 是最高的,因此效果最大),我想将其用于考虑。

我只是不确定如何去做。

I already have a 5 star rating system in place (user votes 1-5...and average score is displayed - i have a page where they vote and it inserts into the DB there username and vote), however I now want to improve it by integrating some sort of weight which functions solely to increase the impact your vote has on the average score of the content. It makes your vote "weigh" more than it would otherwise.

I currently have a $level (which is a number between 1-10 each user has...where 10 is the highest therefore having the most effect) which I'd like to use for consideration.

I'm just not sure on how to go by doing this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烟雨扶苏 2024-12-20 13:11:29

最简单的方法是为每个级别在数据库中插入一票。

for($i = 0; $i < $level; $i++) {
    store_vote($user, $item);
}

The easiest way to do this is to just insert one vote into the DB for every level.

for($i = 0; $i < $level; $i++) {
    store_vote($user, $item);
}
叹梦 2024-12-20 13:11:29

如果用户的级别为 X,您可以让他/她的投票权重为 X 级 1 票。您可以在表格中添加另一个字段“权重”,并显示投票*权重的平均值:(

SELECT AVG(weight * vote)
FROM rating
WHERE item = ? 

其中?是您需要的id)

如果您认为这对于您的需求来说太复杂(并且您已经存储进行投票的用户),您可以使用以下查询:

SELECT AVG(r.weight * u.level)
FROM rating
JOIN user ON r.user_id = u.id
WHERE r.item = ?

If a user has level X, you can make his/her vote weigh X level 1 votes. You can add another field "weight" to the table, and show an average of vote*weight:

SELECT AVG(weight * vote)
FROM rating
WHERE item = ? 

(where ? is you needed id)

If you think this is too complicated for your needs (and you already store the user that made the vote), you can use this query:

SELECT AVG(r.weight * u.level)
FROM rating
JOIN user ON r.user_id = u.id
WHERE r.item = ?
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文