square / crossfilter

Fast n-dimensional filtering and grouping of records.
https://square.github.com/crossfilter/
Other
6.22k stars 1.31k forks source link

multiple pivot reduce #138

Closed agrass closed 9 years ago

agrass commented 9 years ago

I was working with dc.js and crossfilter.js and I have some problems creating the reduce groups with 1-n relations.

For example this data:

{id: 1, date: "2011-11-14T16:17:54Z", place: 2, person: 1}, {id: 1, date: "2011-11-14T16:17:54Z", place: 2, person: 2}, {id: 1, date: "2011-11-14T16:17:54Z", place: 3, person: 5}, {id: 2, date: "2011-11-14T16:28:54Z", place: 1, person: 3}, {id: 2, date: "2011-11-14T16:28:54Z", place: 2, person: 4}, {id: 3, date: "2011-11-14T16:48:46Z", place: 2, person: 1}

I have one Event model that has many places and also can have many people associated. any know if exists any clean way to reduce by multiple variables?? (id and place, id and person)

I searched in other issues but I didn't found a solution so I created a method in my own fork of crossfilter that help me to do that, and may be would be useful for another person with this problem.

https://github.com/agrass/crossfilter

The method is similar like reduceCount, but is: pivotReduceCount(["key1", "key"]).

For example using the data of above, if I want to get for one event the count of places or people associated:

data.id = data.dimension(function(d) { return d.id; }); var group = data.id.group(); var test = group.pivotReduceCount(["id", "place"]).all();