Crossfilter reduce :: find number of uniques

后端 未结 1 1898
无人及你
无人及你 2020-12-09 07:23

I am trying to create a custom reduce function for a dataset attribute group that would sum a number of unique values for another attribute.

For example, my dataset

相关标签:
1条回答
  • 2020-12-09 07:41

    UPDATED ANSWER

    Sorry I misunderstood the question... you are actually on the right track. You'll just need to maintain a count of each project so that your subtract function can know when to remove the value.

    teamMemberGroup = teamMemberDimension.group().reduce(
    
            function (p, d) {
                if( d.project in p.projects)
                    p.projects[d.project]++;
                else p.projects[d.project] = 1;
                return p;
            },
    
            function (p, d) {
                p.projects[d.project]--;
                if(p.projects[d.project] === 0)
                    delete p.projects[d.project];
                return p;
            },
    
            function () {
                return {projects: {}};
            });
    

    Here is an updated fiddle: http://jsfiddle.net/djmartin_umich/3LyhL/

    0 讨论(0)
提交回复
热议问题