How to delete the repeated data in crossfilter?

I have the following problem, I want to make a boxplot (with dc.js) per service (A, B, C, D) to represent (q1, q2, q3, q4 and outliers) the time each is delayed.

My data contains an id, category, the time it takes and other data, the problem is that I have is that I have repeated rows due to the other additional data that are important to have for other graphics.

For example,

Id / category / time / other data

1 / B / 2 / ...

155 / A / 51 / ..

155 / A / 51 / ..

156 / A / "NaN" / ..

157 / C / 10 / ..

etc

Before adding the additional data, I had no problem with the repeated data and used the following code.

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[];
     }
 )

But now I must for example stay with a single value of id 155. Do you have any idea to do it in crossfilter? Or with reductio.js?

How to exclude repeated data?


Assuming I've understood the problem, you need to track the unique IDs you've already seen. Reductio does this for exception aggregation with sum and count, but not for your scenario, I believe. This or something like it should work. If you can put together a working example, I'll be happy to verify this code:

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/32820.html

上一篇: 使用交叉过滤器/还原计算平均值

下一篇: 如何删除crossfilter中的重复数据?