3

我试图弄清楚如何开始在 MYSQL 中设置贝叶斯评级系统。我没有使用 5 星评级,而是类似的东西。我的将是一个 5 卷的酒吧。

这是我的专辑页面。用户不会对专辑进行评分,而是对歌曲进行评分,这些歌曲将被平均成为专辑评分。

  • $songsum
  • $songavg
  • $numofrated
  • $totalsongs
  • $albumrating
  1. $songsum / $numofrated = $songavg
  2. $songavg * ($numofrated / $totalsongs) = $albumrating

另一个页面(艺术家页面)也将被评分。

$avg_num_votes  = 18;  // Average number of votes in all products
$avg_rating     = 3.7; // Average rating for all products
$this_num_votes = 6;   // Number of votes for this product
$this_rating    = 4;   // Rating for this product

$bayesian_rating =
    ( ($avg_num_votes * $avg_rating) + ($this_num_votes * this_rating) )
  / ($avg_num_votes + $this_num_votes);

我应该如何开始设置?应该$this_rating和专辑在同一张桌子吗?


附加信息

  • MYSQL 中的表:专辑、歌曲、流派、独奏、组
  • 已经有外键链接
4

1 回答 1

1

您对评级方案的最初想法可能会改变(尤其是对于专辑),因此您最好存储交易信息,这样您就可以随时重新计算所有内容。

create a new table called "Ratings" that fkeys on "Songs" and "Users":

  • id
  • song_id
  • (album_id)
  • user_id
  • rating

album_id isn't necessary since you have the song_id, but it'll save some time and disk-space is cheap

add the following fields to the database:

  • song.summary_votes
  • song.summary_average
  • album.summary_votes
  • album.summary_average

periodically run a script that updates the summary_ fields to whatever you want them to be.

于 2012-05-24T22:25:02.443 回答