声誉公式 - 最佳方法

时间:2011-03-14 20:02:12

标签: oracle view formula

我在Oracle中有一个表来记录用户的事件。该用户可能有许多事件。从这些事件中,我正在用公式计算声誉。我的问题是,在计算和返回数据时,这是最好的方法。使用视图并使用SQL,通过抓取所有事件并计算它来在代码中执行它(问题是当你有一个用户列表并需要计算所有人的声誉时)或其他事情。喜欢听你的想法。

Comments * (.1) + 
Blog Posts * (.3) + 
Blog Posts Ratings * (.1) + 
Followers * (.1) + 
Following * (.1) + 
Badges * (.2) + 
Connections * (.1) 
= 100%

一个例子

Comments:

This parameter is based on the average comments per post.

•   Max: 20
•   Formula: AVE(#) / max * 100 = 100%
•   Example: 5 /10 * 100 = 50%

Max是获得所有百分比的最大数量。希望这是有道理的。

我们正在计算访问量,因此所有独特访问/会员日期都是另一个。该表包含一个事件名称,一些元数据,并且与该用户绑定。声誉仅使用这些事件来制定基于100%作为最高声誉的声誉。

85% reputation - Joe AuthorUser been a member for 3 years. He has:
•   written 18 blog posts 
o   2 in the past month
•   commented an average of 115 times per month
•   3,000 followers
•   following 2,000 people
•   received an average like rating of 325 per post 
•   he's earned, over the past 3 years: 
o   100 level 1 badges
o   50 level 2 badges
•   he's connected his: 
o   FB account
o   Twitter account

2 个答案:

答案 0 :(得分:1)

作为一种通用方法,我将使用PL / SQL。一个包含多个get_rep函数的包。

function calc_rep (i_comments in number, i_posts in number, i_ratings in number,
                  i_followers in number, i_following in number, i_badges in number,
                  i_connections in number) return number deterministic is
...
end calc_rep;

function get_rep_for_user (i_user_id in number) is
  v_comments ....
begin
  select .....
  calc_rep (v_comments...)
end get_rep_for_user;

如果你必须在很多时候重新计算很多用户的代表,我会研究并行流水线功能(这应该是一个单独的问题)。 CALC_REP是确定性的,因为具有相同数字集的任何人都将获得相同的结果。

如果评论数量等存储在单个记录中,则调用起来很简单。如果需要总结细节,则使用物化视图进行摘要。如果需要从多个位置收集它们,则可以使用视图来封装连接。

答案 1 :(得分:1)

你是否能够快速计算以满足要求是数据量,数据库设计,最终计算复杂性的一个因素......想象一下,我们可以给你一个切割干燥的方法是不合理的。

通过存储用于某些计算值的摘要,可能会有所帮助。例如,查看导致DML的内容。如果您有user_reputation表,那么blog_post表上的触发器可以在插入或删除帖子时递增/递减user_reputation上的计数器。评论,喜欢,跟随等等。

如果您以这种方式更新所有摘要,那么DML的增量成本将会很小,计算也会变得简单。

不是说这是解决方案。只是说它可能值得探索。