Skip to content
This repository has been archived by the owner on Jun 9, 2020. It is now read-only.

Commit

Permalink
Now supports reductio.valueList and reductio.dataList
Browse files Browse the repository at this point in the history
  • Loading branch information
tannerlinsley committed Mar 11, 2016
1 parent a569c43 commit 45c9fe1
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "universe",
"version": "0.4.2",
"version": "0.5.0",
"description": "The fastest way to query and explore multivariate datasets",
"main": "src/universe.js",
"directories": {
Expand Down
10 changes: 10 additions & 0 deletions src/reductioAggregators.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ module.exports = {
$med: $med,
$sumSq: $sumSq,
$std: $std,
$valueList: $valueList,
$dataList: $dataList,
}
}

Expand Down Expand Up @@ -59,5 +61,13 @@ function $std(reducer, value) {
return reducer.std(value)
}

function $valueList(reducer, value) {
return reducer.valueList(value)
}

function $dataList(reducer, value) {
return reducer.dataList(value)
}

// TODO histograms
// TODO exceptions
65 changes: 65 additions & 0 deletions test/query.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,71 @@ describe('universe query', function() {
})
})

it('can query using the valueList aggregation', function() {
var res
return u.then(function(u){
return u.query({
groupBy: 'type',
select: {
$valueList: 'total',
}
})
})
.then(function(r){
res = r
expect(res.data).to.deep.equal([
{ key: 'cash', value: { valueList: [100, 200] } },
{ key: 'tab', value: { valueList: [90, 90, 90, 90, 90, 90, 190, 190] } },
{ key: 'visa', value: { valueList: [200, 300, 50000] } } ])
})
})

it('can query using the dataList aggregation', function() {
var res
return u.then(function(u){
return u.query({
groupBy: 'type',
select: {
$dataList: 'total',
}
})
})
.then(function(r){
res = r
expect(res.data).to.deep.equal([{
"key": "cash",
"value": {
"dataList": [
{"date": "2011-11-14T16:54:06Z","quantity": 1,"total": 100, "tip": 0,"type": "cash","productIDs": ["001", "002", "003", "004", "005"]},
{"date": "2011-11-14T17:25:45Z","quantity": 2,"total": 200, "tip": 0,"type": "cash","productIDs": ["002"]}
]
}
}, {
"key": "tab",
"value": {
"dataList": [
{"date": "2011-11-14T16:17:54Z","quantity": 2,"total": 190, "tip": 100,"type": "tab","productIDs": ["001"]},
{"date": "2011-11-14T16:20:19Z","quantity": 2,"total": 190, "tip": 100,"type": "tab","productIDs": ["001", "005"]},
{"date": "2011-11-14T16:30:43Z","quantity": 2,"total": 90, "tip": 0,"type": "tab","productIDs": ["001", "002"]},
{"date": "2011-11-14T16:48:46Z","quantity": 2,"total": 90, "tip": 0,"type": "tab","productIDs": ["005"]},
{"date": "2011-11-14T16:53:41Z","quantity": 2,"total": 90, "tip": 0,"type": "tab","productIDs": ["001", "004", "005"]},
{"date": "2011-11-14T16:58:03Z","quantity": 2,"total": 90, "tip": 0,"type": "tab","productIDs": ["001"]},
{"date": "2011-11-14T17:07:21Z","quantity": 2,"total": 90, "tip": 0,"type": "tab","productIDs": ["004", "005"]},
{"date": "2011-11-14T17:22:59Z","quantity": 2,"total": 90, "tip": 0,"type": "tab","productIDs": ["001", "002", "004", "005"]}
]
}
}, {
"key": "visa",
"value": {
"dataList": [
{"date": "2011-11-14T16:28:54Z","quantity": 1,"total": 300, "tip": 200,"type": "visa","productIDs": ["004", "005"]},
{"date": "2011-11-14T17:29:52Z","quantity": 1,"total": 200, "tip": 100,"type": "visa","productIDs": ["004"]},
{"date": "2012-11-14T17:29:52Z","quantity": 100,"total": 50000, "tip": 999,"type": "visa","productIDs": ["004"]}
]}
}])
})
})

// TODO: This isn't completely possible yet, reductio will need to support aliases for all aggregations first. As of this commit, it is only available on `count`
// it('supports nested aliases', function(){
// return u.then(function(u){
Expand Down
12 changes: 11 additions & 1 deletion universe.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions universe.min.js

Large diffs are not rendered by default.

0 comments on commit 45c9fe1

Please sign in to comment.