With the following data:
const now = new Date
const data = [
{ player: 'bob', color: 'blue', date: new Date(+now + 1000) },
{ player: 'bill', color: 'green', date: new Date(+now + 2000) },
{ player: 'bob', color: 'red', date: new Date(+now + 3000) },
{ player: 'barbara', color: 'blue', date: new Date(+now + 4000) },
{ player: 'barbara', color: 'cyan', date: new Date(+now + 8000) },
{ player: 'barbara', color: 'magenta', date: new Date(+now + 10000) },
{ player: 'barbara', color: 'yellow', date: new Date(+now + 20000) },
]
I want to reduceCount on the color dimension, but only count the first color per-player. (note: first is w.r.t. the date dimension which may be filtered). I have been trying to get this to work with reductio using the exception feature but it did not give the expected results:
reducer = reductio()
reducer.exception('player').exceptionCount(true)
reducer(colorGroup)
The results should look like this:
blue,2 # bob and barbara
cyan,0
green,1 # bill
magenta,0
red,0
yellow,0
Another example, with the date dimension filtered to now+2100
..now+20000
(i.e. the first row is filtered out):
blue,1 # barbara
cyan,0
green,0 # (bill's first color is not counted because it is outside the date range)
magenta,0
red,1 # bob (blue is his first color overall, red is his first in this date range)
yellow,0
Note: I have other groupings which use all of the rows so I can't just pre-filter the list before loading it into crossfilter.
Is there some way to use reductio() for this? Or some example of how to do this "grouping upon grouping" with crossfilter directly?
EDIT
Link to jsfiddle showing unexpected result: https://jsfiddle.net/qt5jxjm1/