-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Possibly replace aliasProp with 'final' calculations that populate properties at query-time #25
Comments
Alright, so the new |
Also, I agree, the aliasProp is the baby version of what we're talking about here. A whole new way to do post-aggregation that is transparent to the user and to the output. I'm not sure how the API will look but in my in-house solution it is similar to the way value works. This was a quick brainstorm, but the results of the reduction could look something like this: var reducer = reductio()
.count(true)
.min('something')
.post('custom', function(d, ds){
return 'hello world';
})
.value('change', {
count: function(d, ds){
return ds[0].count - d.count;
},
min: function(d, ds){
return ds[0].min - d.min;
}
}) could be something like this: var results = [{
key: 1,
value: {
count: 20,
min: 3,
custom: 'hello world',
change: {
count: 0,
min: 0,
}
}
}, {
key: 2,
value: {
count: 14,
min: 7,
custom: 'hello world',
change: {
count: -6,
min: 4,
}
}
}, {
key: 3,
value: {
count: 3,
min: 0,
custom: 'hello world',
change: {
count: -17,
min: -3,
}
}
}] |
We need to cut another alpha Crossfilter release (just a new tag, update package.json, and 'npm publish') so that we can pull it into Reductio as a dependency and use the new functionality. Then we would define the new Reductio API. My suggestion: var reducer = reductio()
.count(true)
.min('something')
.final({
'custom': function(d, ds) { return 'hello world'; },
'countChange': function(d, ds) { return ds[0].count - d.count; },
'minChange': function(d, ds){ return ds[0].min - d.min; }
}); Resulting in: var results = [{
key: 1,
value: {
count: 20,
min: 3,
custom: 'hello world',
countChange: 0,
minChange: 0
}
}, {
key: 2,
value: {
count: 14,
min: 7,
custom: 'hello world',
countChange: -6,
minChange: 4
}
}, {
key: 3,
value: {
count: 3,
min: 0,
custom: 'hello world',
countChange: -17,
minChange: -3
}
}] If you want the value behavior, you could define: var reducer = reductio()
.count(true)
.min('something');
reducer.value('change')
.final({
'count': function(d, ds) { return ds[0].count - d.count; },
'min': function(d, ds){ return ds[0].min - d.min; }
}); I would't recommend re-using properties that Reductio uses internally (count, min), but it will work, and in fact overwrite any of these properties created by Reductio. |
Awesome. Looks great.
|
Basically, aliasProp as it currently stands is a bit of a disaster. Would be nice to be able to define "final" processing on a reducer that only runs after filters have resolved, not once for each record, to populate arbitrary properties. May also want to give it access to the entire group array and override all(). Or plug into a new Crossfilter lifecycle event??
Per discussion w/ @tannerlinsley
The text was updated successfully, but these errors were encountered: