dryl34156 2011-07-26 17:54
浏览 50
已采纳

如何实施一个评级系统,该系统还支持查询评分最高的“今天,周,月”

I've been looking for some good rating system tutorials on the internet and I can't seem to find the one i'm looking for! I've come across this article http://www.expertcore.org/viewtopic.php?f=74&t=1451 which uses the Bayesian Rating algorithm and a like/dislike rating and that one is the rating system I want except that system can only make a "Top rated list of all time", I want to be able to make a "Top rated of today", "Top rated of this week" and "Top rated of this month" aswell. I'm not to sure of how I'll have to approach this problem because I'm not really great at database designs and I don't want to encounter performance issues later on!

Example I have these three tables.

Table "Item" id name

Table "User" id name

Table "Vote" id itemID userID date

The normal algorithm is this: br = ( (avg_num_votes * avg_rating) + (this_num_votes * this_rating) ) / (avg_num_votes + this_num_votes)

So to get a top rated list of all time I'll have to calculate the BR for every item I have. Would it mean if I want the top rated list of this month I just do the same but check if the date of the votes are valid? Please give me tips and hints !

  • 写回答

1条回答 默认 最新

  • doujiepin5547 2011-07-26 18:55
    关注

    Your table looks like it would work, you would just need to select all Vote records that happen in a date range. So, for "this week", for all the values in that equation, you could apply a date filter when selecting to only choose rows in this week.

    For: avg_num_votes, avg_rating, this_num_votes, this_rating; all would need to be created off of records from "this week" otherwise your weights will be way off, and your "top this week" would only show records from all time.

    Same with "top rated this month" and "top rated today" you just want to see votes that have been voted in that time frame, and not take into account all votes from all time.

    For speed, you would want to filter as much as possible at the database level, so that would probably mean joining the Item and Vote tables, then selecting only where the date of the Vote is in the range you want, then working with that data.

    His own code would demonstrate this well, just adding in a filter to his select statements:

    $result = mysql_query(”SELECT AVG(item),AVG(vote) FROM itemvotes WHERE vote>’0’ GROUP BY item AND date BETWEEN '2010-08-20' AND '2010-08-21'”) or die(mysql_error());
    
    // this item votes and ratings
    $result = mysql_query(”SELECT COUNT(item),AVG(vote) FROM itemvotes WHERE item=’$theItem’ AND vote>’0’ AND date BETWEEN '2010-08-20' AND '2010-08-21'”) or die(mysql_error());
    

    This might not be exactly the same (or work at all, that example was a little funky), but it demonstrates what I mean.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单