Merge pull request #514 from CartoDB/dataview-aggregation-operations
Add support for min, max, and avg operations in aggregation dataview
This commit is contained in:
commit
726e153ad5
3
NEWS.md
3
NEWS.md
@ -4,6 +4,9 @@
|
|||||||
|
|
||||||
Released 2016-mm-dd
|
Released 2016-mm-dd
|
||||||
|
|
||||||
|
New features:
|
||||||
|
- Add support for min, max, and avg operations in aggregation dataview #513.
|
||||||
|
|
||||||
|
|
||||||
## 2.49.1
|
## 2.49.1
|
||||||
|
|
||||||
|
@ -54,7 +54,10 @@ var CATEGORIES_LIMIT = 6;
|
|||||||
|
|
||||||
var VALID_OPERATIONS = {
|
var VALID_OPERATIONS = {
|
||||||
count: [],
|
count: [],
|
||||||
sum: ['aggregationColumn']
|
sum: ['aggregationColumn'],
|
||||||
|
avg: ['aggregationColumn'],
|
||||||
|
min: ['aggregationColumn'],
|
||||||
|
max: ['aggregationColumn']
|
||||||
};
|
};
|
||||||
|
|
||||||
var TYPE = 'aggregation';
|
var TYPE = 'aggregation';
|
||||||
@ -198,6 +201,7 @@ Aggregation.prototype.format = function(result) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
aggregation: this.aggregation,
|
||||||
count: count,
|
count: count,
|
||||||
nulls: nulls,
|
nulls: nulls,
|
||||||
min: minValue,
|
min: minValue,
|
||||||
|
59
test/acceptance/dataviews/aggregation.js
Normal file
59
test/acceptance/dataviews/aggregation.js
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
require('../../support/test_helper');
|
||||||
|
|
||||||
|
var assert = require('../../support/assert');
|
||||||
|
var TestClient = require('../../support/test-client');
|
||||||
|
|
||||||
|
describe('aggregations', function() {
|
||||||
|
|
||||||
|
afterEach(function(done) {
|
||||||
|
if (this.testClient) {
|
||||||
|
this.testClient.drain(done);
|
||||||
|
} else {
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function aggregationOperationMapConfig(operation) {
|
||||||
|
return {
|
||||||
|
version: '1.5.0',
|
||||||
|
layers: [
|
||||||
|
{
|
||||||
|
type: 'mapnik',
|
||||||
|
options: {
|
||||||
|
sql: 'select * from populated_places_simple_reduced',
|
||||||
|
cartocss: '#layer0 { marker-fill: red; marker-width: 10; }',
|
||||||
|
cartocss_version: '2.0.1',
|
||||||
|
widgets: {
|
||||||
|
adm0name: {
|
||||||
|
type: 'aggregation',
|
||||||
|
options: {
|
||||||
|
column: 'adm0name',
|
||||||
|
aggregation: operation,
|
||||||
|
aggregationColumn: 'pop_max'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
var operations = ['count', 'sum', 'avg', 'max', 'min'];
|
||||||
|
|
||||||
|
operations.forEach(function(operation) {
|
||||||
|
it('should be able to use "' + operation + '" as aggregation operation', function(done) {
|
||||||
|
|
||||||
|
this.testClient = new TestClient(aggregationOperationMapConfig(operation));
|
||||||
|
this.testClient.getDataview('adm0name', { own_filter: 0 }, function (err, aggregation) {
|
||||||
|
assert.ok(!err, err);
|
||||||
|
assert.ok(aggregation);
|
||||||
|
|
||||||
|
assert.equal(aggregation.type, 'aggregation');
|
||||||
|
assert.equal(aggregation.aggregation, operation);
|
||||||
|
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user