我试图在.std()库中同时使用.custom()函数和reductio函数。
对于还原部分,我的代码如下:
dims.theme1 = myCrossfilter.dimension(function(d) {return(d.theme1);});
groups.theme1 = dims.theme1.group();
var reducer = reductio()
.custom({initial:reduceInit,add:reduceAdd,remove:reduceRemove})
.std("pl");
reducer(groups.theme1);我的自定义函数代码是:
reduceAdd = function(p,v) {
if (!p.fundsData.hasOwnProperty(v.AdyneAccount)) {
p.fundsData[v.AdyneAccount]=0;
}
if (!p.stratsData.hasOwnProperty(v.Strategy)) {
p.stratsData[v.Strategy]=0;
}
p.fundsData[v.AdyneAccount]+=+v.plfund;
p.stratsData[v.Strategy]+=+v.plstrat;
p.value+=+v.pl;
return(p);
};
reduceRemove = function(p,v) {
p.fundsData[v.AdyneAccount]-=+v.plfund;
p.stratsData[v.Strategy]-=+v.plstrat;
p.value-=+v.pl;
return(p);
};
reduceInit = function(p,v) {
return({
value:0,
fundsData:{},
stratsData:{}
});
};我希望我的结果(通过执行groups.theme1.all()[0])如下所示(对于这个例子,我输入的值是随机的):
{
"key": "theTheme",
"value": {
"value": 10,
"fundsData": {
"a": 10,
"b": 5,
"c": 4
},
"stratsData": {
"somename": 8
},
"count": null,
"sum": null,
"sumOfSq": null,
"std": 0
}
}它确实是这样,但它没有为count、sum和sumOfSq生成值(当然,对于std也是如此)。
当我在完全相同的记录集上不使用我的自定义函数而单独运行.std("pl")时,它就像预期的那样工作。我不明白为什么添加自定义函数会阻止.std("pl")部件的正确计算。
大家都来帮忙欢迎!
发布于 2018-04-09 21:04:20
在我看来,这是还原术中的一个错误。测试名称表明这不应该干扰还原剂的其他方面,但是测试的内容表明它确实消除了它们。
我创建了这方面的一个问题。不过,我不知道什么时候能找到它。您可能只想为这个实现一个普通的Crossfilter自定义还原程序,直到我能够修复它或者有人发送了一个拉请求。
https://stackoverflow.com/questions/49728636
复制相似问题