如何删除crossfilter中的重复数据?

我有以下问题,我想为每个服务(A,B,C,D)创建一个boxplot(使用dc.js)来表示(q1,q2,q3,q4和异常值)每个服务的延迟时间。

我的数据包含一个id,类别,所花费的时间和其他数据,问题在于我拥有重复的行,这是因为其他附加数据对其他图形很重要。

例如,

ID /类别/时间/其他数据

1 / B / 2 / ...

155 / A / 51 / ..

155 / A / 51 / ..

156 / A /“NaN”/ ..

157 / C / 10 / ..

等等

在添加附加数据之前,我对重复的数据没有任何问题,并使用下面的代码。

var categorydim=ndx.dimension(function(d){return d["category"]});
var categorydim.group().reduce(
     function(p,v){
         if (v["time"]>0.){
         p.push(v["time"])};
         return p;
     },
     function(p,v){
         if (v["time"]>0.){
         p.splice(p.indexOf(v["time"]),1)};
         return p;
     },
     function(){
         return[];
     }
 )

但是现在我必须保留一个单一的id值155.你有什么想法在crossfilter中做到这一点吗? 或与reductio.js?

如何排除重复数据?


假设我已经理解了这个问题,你需要跟踪你已经看到的唯一ID。 我相信,Reductio会对总数和总数进行异常汇总,但不适用于您的场景。 这或类似的东西应该工作。 如果你可以把一个工作的例子放在一起,我很乐意验证这个代码:

var categorydim=ndx.dimension(function(d){return d["category"]});
var categorydim.group().reduce(
     function(p,v){
         // Ignore record if time is invalid or key has already been added.
         if (v["time"]>0. && !p.keys[v['Id']]){
           p.values.push(v["time"])
           p.keys[v['Id']] = 1
         } else if(v["time"]>0.) {
           // Time is valid and key has shown up 1 or more times already
           p.keys[v['Id']]++
         }
         return p;
     },
     function(p,v){
         // Ignore record if time is invalid or key is the "last" of this key.
         if (v["time"]>0. && p.keys[v['Id']] === 1){
           p.values.splice(p.values.indexOf(v["time"]), 1)
           p.keys[v['Id']] = 0
         } else if(v["time"]>0.) {
           // Key is greater than 1, so decrement
           p.keys[v['Id']]--
         }
         return p;
     },
     function(){
         return {
           keys: {},
           values: []
         };
     }
 )
链接地址: http://www.djcxy.com/p/32819.html

上一篇: How to delete the repeated data in crossfilter?

下一篇: Crossfilter barchart does not render