Skip to content
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

Open
esjewett opened this issue Oct 21, 2015 · 4 comments

Comments

@esjewett
Copy link
Member

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

@esjewett esjewett changed the title Possibly replace aliasProp 'final' calculations that populate properties at query-time Possibly replace aliasProp with 'final' calculations that populate properties at query-time Oct 21, 2015
@tannerlinsley
Copy link
Contributor

Alright, so the new onChange is now available in crossfilter. Where should we go from there?

@tannerlinsley
Copy link
Contributor

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,
        }
    }
}]

@esjewett
Copy link
Member Author

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.

@tannerlinsley
Copy link
Contributor

Awesome. Looks great.
On Tue, Oct 27, 2015 at 8:37 AM Ethan Jewett notifications@github.com
wrote:

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.


Reply to this email directly or view it on GitHub
#25 (comment).

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants