Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Oracle 声誉公式-最佳方法_Oracle_View_Formula - Fatal编程技术网

Oracle 声誉公式-最佳方法

Oracle 声誉公式-最佳方法,oracle,view,formula,Oracle,View,Formula,我在Oracle中有一个记录用户事件的表。此用户可能有许多事件。从这些事件中,我用一个公式来计算声誉。我的问题是,在计算和返回数据时,最好的方法是什么。使用视图和SQL,通过获取所有事件并进行计算(问题是当您有一个用户列表并且需要计算所有用户的信誉)或其他方式在代码中执行此操作。我想听听你的想法 Comments * (.1) + Blog Posts * (.3) + Blog Posts Ratings * (.1) + Followers * (.1) + Following *

我在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

作为一种通用方法,我将使用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;
如果您需要为许多用户重新计算rep,我会研究并行流水线函数(这应该是一个单独的问题)。CALC_REP是确定性的,因为任何拥有相同数字集的人都会得到相同的结果


如果注释等的数量存储在单个记录中,那么调用就很简单。如果需要对细节进行总结,则使用物化视图进行总结。如果需要从多个位置收集数据,则可以使用视图来封装连接。

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

存储用于某些计算值的摘要可能会对它有所帮助。例如,看看导致DML的因素。如果你有一个用户声誉表,那么博客帖子表上的触发器可以在插入或删除帖子时增加/减少用户声誉计数器。评论、喜欢、关注等也一样

如果您以这种方式使所有摘要保持最新,那么DML的增量成本将很小,计算将变得简单


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

尝试给出更多规范,如数据模型、声誉计算的复杂性……有趣的方法。如果这不是一个动态的网站,声誉可能会改变,参数可能会增加或删除,这可能是一个很好的解决方案。也可以选择仅包含带有触发器的数据摘要的单行。我们跟踪事件,因此即使我们删除了数据,我们也可以根据参数的变化轻松地重新计算总数。