如何删除crossfilter中的重复数据?
How to delete the repeated data in crossfilter?
我有以下问题,我想为每个服务(A、B、C、D)制作一个箱线图(dc.js)来表示(q1、q2、q3、q4 和异常值)每个时间都有延迟。
我的数据包含一个 id、类别、花费的时间和其他数据,问题是我有重复的行,因为其他附加数据对其他图形很重要。
例如,
id/类别/时间/其他数据
1 / B / 2 / ...
155/A/51/..
155/A/51/..
156/一个/"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: []
};
}
)
我有以下问题,我想为每个服务(A、B、C、D)制作一个箱线图(dc.js)来表示(q1、q2、q3、q4 和异常值)每个时间都有延迟。
我的数据包含一个 id、类别、花费的时间和其他数据,问题是我有重复的行,因为其他附加数据对其他图形很重要。
例如,
id/类别/时间/其他数据
1 / B / 2 / ...
155/A/51/..
155/A/51/..
156/一个/"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: []
};
}
)