2018-10-24 00:39:02 +08:00
|
|
|
'use strict';
|
|
|
|
|
2019-10-07 16:44:45 +08:00
|
|
|
require('../../support/test-helper');
|
2016-05-18 14:11:52 +08:00
|
|
|
|
|
|
|
var assert = require('../../support/assert');
|
|
|
|
var TestClient = require('../../support/test-client');
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('dataviews using tables without overviews', function () {
|
|
|
|
var nonOverviewsMapConfig = {
|
2016-05-18 14:11:52 +08:00
|
|
|
version: '1.5.0',
|
|
|
|
analyses: [
|
2019-10-22 01:07:24 +08:00
|
|
|
{
|
|
|
|
id: 'data-source',
|
2016-05-18 14:11:52 +08:00
|
|
|
type: 'source',
|
|
|
|
params: {
|
2019-10-22 01:07:24 +08:00
|
|
|
query: 'select * from populated_places_simple_reduced'
|
2016-05-18 14:11:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
2019-10-22 01:07:24 +08:00
|
|
|
dataviews: {
|
2016-05-18 14:11:52 +08:00
|
|
|
country_places_count: {
|
|
|
|
type: 'formula',
|
2019-10-22 01:07:24 +08:00
|
|
|
source: { id: 'data-source' },
|
2016-05-18 14:11:52 +08:00
|
|
|
options: {
|
|
|
|
column: 'adm0_a3',
|
|
|
|
operation: 'count'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
country_categories: {
|
|
|
|
type: 'aggregation',
|
2019-10-22 01:07:24 +08:00
|
|
|
source: { id: 'data-source' },
|
2016-05-18 14:11:52 +08:00
|
|
|
options: {
|
|
|
|
column: 'adm0_a3',
|
|
|
|
aggregation: 'count'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
type: 'mapnik',
|
|
|
|
options: {
|
|
|
|
sql: 'select * from populated_places_simple_reduced',
|
|
|
|
cartocss: '#layer { marker-fill: red; marker-width: 32; marker-allow-overlap: true; }',
|
|
|
|
cartocss_version: '2.3.0',
|
|
|
|
source: { id: 'data-source' }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should expose a formula', function (done) {
|
2016-05-18 16:48:13 +08:00
|
|
|
var testClient = new TestClient(nonOverviewsMapConfig);
|
2019-11-14 03:08:04 +08:00
|
|
|
testClient.getDataview('country_places_count', { own_filter: 0 }, function (err, formulaResult, headers) {
|
2016-05-18 14:11:52 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2019-11-14 03:08:04 +08:00
|
|
|
assert.deepStrictEqual(formulaResult, { operation: 'count', result: 7313, nulls: 0, type: 'formula' });
|
2016-05-18 14:11:52 +08:00
|
|
|
|
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should admit a bbox', function (done) {
|
2016-05-19 00:02:08 +08:00
|
|
|
var params = {
|
2019-10-22 01:07:24 +08:00
|
|
|
bbox: '-170,-80,170,80'
|
2016-05-19 00:02:08 +08:00
|
|
|
};
|
|
|
|
var testClient = new TestClient(nonOverviewsMapConfig);
|
2019-11-14 03:08:04 +08:00
|
|
|
testClient.getDataview('country_places_count', params, function (err, formulaResult) {
|
2016-05-19 00:02:08 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2019-11-14 03:08:04 +08:00
|
|
|
assert.deepStrictEqual(formulaResult, { operation: 'count', result: 7253, nulls: 0, type: 'formula' });
|
2016-05-19 00:02:08 +08:00
|
|
|
|
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('filters', function () {
|
2016-05-18 14:11:52 +08:00
|
|
|
describe('category', function () {
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should expose a filtered formula', function (done) {
|
2016-05-18 14:11:52 +08:00
|
|
|
var params = {
|
|
|
|
filters: {
|
2019-10-22 01:07:24 +08:00
|
|
|
dataviews: { country_categories: { accept: ['CAN'] } }
|
2016-05-18 14:11:52 +08:00
|
|
|
}
|
|
|
|
};
|
2016-05-18 16:48:13 +08:00
|
|
|
var testClient = new TestClient(nonOverviewsMapConfig);
|
2019-11-14 03:08:04 +08:00
|
|
|
testClient.getDataview('country_places_count', params, function (err, formulaResult) {
|
2016-05-18 14:11:52 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2019-11-14 03:08:04 +08:00
|
|
|
assert.deepStrictEqual(formulaResult, { operation: 'count', result: 256, nulls: 0, type: 'formula' });
|
2016-05-18 14:11:52 +08:00
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
2016-05-19 00:16:32 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should expose a filtered formula and admit a bbox', function (done) {
|
2016-05-19 00:16:32 +08:00
|
|
|
var params = {
|
|
|
|
filters: {
|
2019-10-22 01:07:24 +08:00
|
|
|
dataviews: { country_categories: { accept: ['CAN'] } }
|
2016-05-19 00:16:32 +08:00
|
|
|
},
|
2019-10-22 01:07:24 +08:00
|
|
|
bbox: '-170,-80,170,80'
|
2016-05-19 00:16:32 +08:00
|
|
|
};
|
|
|
|
var testClient = new TestClient(nonOverviewsMapConfig);
|
2019-11-14 03:08:04 +08:00
|
|
|
testClient.getDataview('country_places_count', params, function (err, formulaResult) {
|
2016-05-19 00:16:32 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2019-11-14 03:08:04 +08:00
|
|
|
assert.deepStrictEqual(formulaResult, { operation: 'count', result: 254, nulls: 0, type: 'formula' });
|
2016-05-19 00:16:32 +08:00
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
2016-05-18 14:11:52 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('dataviews using tables with overviews', function () {
|
|
|
|
var overviewsMapConfig = {
|
2016-05-18 14:11:52 +08:00
|
|
|
version: '1.5.0',
|
|
|
|
analyses: [
|
2019-10-22 01:07:24 +08:00
|
|
|
{
|
|
|
|
id: 'data-source',
|
2016-05-18 14:11:52 +08:00
|
|
|
type: 'source',
|
|
|
|
params: {
|
2019-10-22 01:07:24 +08:00
|
|
|
query: 'select * from test_table_overviews'
|
2016-05-18 14:11:52 +08:00
|
|
|
}
|
2017-06-14 01:01:28 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'data-source-special-float-values',
|
|
|
|
type: 'source',
|
|
|
|
params: {
|
2019-10-22 01:07:24 +08:00
|
|
|
query: 'select * from test_special_float_values_table_overviews'
|
2017-06-14 01:01:28 +08:00
|
|
|
}
|
2016-05-18 14:11:52 +08:00
|
|
|
}
|
|
|
|
],
|
2019-10-22 01:07:24 +08:00
|
|
|
dataviews: {
|
2016-05-18 14:11:52 +08:00
|
|
|
test_sum: {
|
|
|
|
type: 'formula',
|
2019-10-22 01:07:24 +08:00
|
|
|
source: { id: 'data-source' },
|
2016-05-18 14:11:52 +08:00
|
|
|
options: {
|
|
|
|
column: 'value',
|
|
|
|
operation: 'sum'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
test_categories: {
|
|
|
|
type: 'aggregation',
|
2019-10-22 01:07:24 +08:00
|
|
|
source: { id: 'data-source' },
|
2016-05-18 14:11:52 +08:00
|
|
|
options: {
|
|
|
|
column: 'name',
|
|
|
|
aggregation: 'count',
|
2019-10-22 01:07:24 +08:00
|
|
|
aggregationColumn: 'name'
|
2016-05-18 14:11:52 +08:00
|
|
|
}
|
2016-05-18 16:48:13 +08:00
|
|
|
},
|
2017-06-14 01:01:28 +08:00
|
|
|
test_categories_special_values: {
|
|
|
|
type: 'aggregation',
|
|
|
|
source: {
|
|
|
|
id: 'data-source-special-float-values'
|
|
|
|
},
|
|
|
|
options: {
|
|
|
|
column: 'name',
|
|
|
|
aggregation: 'sum',
|
2019-10-22 01:07:24 +08:00
|
|
|
aggregationColumn: 'value'
|
2017-06-14 01:01:28 +08:00
|
|
|
}
|
|
|
|
},
|
2017-03-17 02:15:34 +08:00
|
|
|
test_histogram: {
|
|
|
|
type: 'histogram',
|
2019-10-22 01:07:24 +08:00
|
|
|
source: { id: 'data-source' },
|
2017-03-17 02:15:34 +08:00
|
|
|
options: {
|
|
|
|
column: 'value',
|
|
|
|
bins: 2
|
|
|
|
}
|
|
|
|
},
|
|
|
|
test_histogram_date: {
|
|
|
|
type: 'histogram',
|
2019-10-22 01:07:24 +08:00
|
|
|
source: { id: 'data-source' },
|
2017-03-17 02:15:34 +08:00
|
|
|
options: {
|
|
|
|
column: 'updated_at',
|
|
|
|
bins: 2
|
|
|
|
}
|
|
|
|
},
|
2017-06-15 00:57:26 +08:00
|
|
|
test_histogram_special_values: {
|
|
|
|
type: 'histogram',
|
|
|
|
source: {
|
|
|
|
id: 'data-source-special-float-values'
|
|
|
|
},
|
|
|
|
options: {
|
|
|
|
column: 'value',
|
|
|
|
bins: 2
|
|
|
|
}
|
|
|
|
},
|
2016-05-18 16:48:13 +08:00
|
|
|
test_avg: {
|
|
|
|
type: 'formula',
|
2019-10-22 01:07:24 +08:00
|
|
|
source: { id: 'data-source' },
|
2016-05-18 16:48:13 +08:00
|
|
|
options: {
|
|
|
|
column: 'value',
|
|
|
|
operation: 'avg'
|
|
|
|
}
|
|
|
|
},
|
2017-06-15 01:20:39 +08:00
|
|
|
test_formula_sum_special_values: {
|
2017-06-15 01:19:08 +08:00
|
|
|
type: 'formula',
|
|
|
|
source: {
|
|
|
|
id: 'data-source-special-float-values'
|
|
|
|
},
|
|
|
|
options: {
|
|
|
|
column: 'value',
|
|
|
|
operation: 'sum'
|
|
|
|
}
|
|
|
|
},
|
2016-05-18 16:48:13 +08:00
|
|
|
test_count: {
|
|
|
|
type: 'formula',
|
2019-10-22 01:07:24 +08:00
|
|
|
source: { id: 'data-source' },
|
2016-05-18 16:48:13 +08:00
|
|
|
options: {
|
|
|
|
column: 'value',
|
|
|
|
operation: 'count'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
test_min: {
|
|
|
|
type: 'formula',
|
2019-10-22 01:07:24 +08:00
|
|
|
source: { id: 'data-source' },
|
2016-05-18 16:48:13 +08:00
|
|
|
options: {
|
|
|
|
column: 'value',
|
|
|
|
operation: 'min'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
test_max: {
|
|
|
|
type: 'formula',
|
2019-10-22 01:07:24 +08:00
|
|
|
source: { id: 'data-source' },
|
2016-05-18 16:48:13 +08:00
|
|
|
options: {
|
|
|
|
column: 'value',
|
|
|
|
operation: 'max'
|
|
|
|
}
|
2016-05-18 14:11:52 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
type: 'mapnik',
|
|
|
|
options: {
|
|
|
|
sql: 'select * from test_table_overviews',
|
|
|
|
cartocss: '#layer { marker-fill: red; marker-width: 32; marker-allow-overlap: true; }',
|
|
|
|
cartocss_version: '2.3.0',
|
|
|
|
source: { id: 'data-source' }
|
|
|
|
}
|
2017-06-14 01:01:28 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'mapnik',
|
|
|
|
options: {
|
|
|
|
sql: 'select * from test_special_float_values_table_overviews',
|
|
|
|
cartocss: '#layer { marker-fill: red; marker-width: 32; marker-allow-overlap: true; }',
|
|
|
|
cartocss_version: '2.3.0',
|
|
|
|
source: {
|
|
|
|
id: 'data-source-special-float-values'
|
|
|
|
}
|
|
|
|
}
|
2016-05-18 14:11:52 +08:00
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should expose a sum formula', function (done) {
|
2016-05-18 16:48:13 +08:00
|
|
|
var testClient = new TestClient(overviewsMapConfig);
|
2019-11-14 03:08:04 +08:00
|
|
|
testClient.getDataview('test_sum', { own_filter: 0 }, function (err, formulaResult, headers) {
|
2016-05-18 14:11:52 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2019-11-14 03:08:04 +08:00
|
|
|
assert.deepStrictEqual(formulaResult, {
|
2019-10-22 01:07:24 +08:00
|
|
|
operation: 'sum',
|
|
|
|
result: 15,
|
|
|
|
infinities: 0,
|
|
|
|
nans: 0,
|
|
|
|
nulls: 0,
|
|
|
|
type: 'formula'
|
2017-06-15 01:20:39 +08:00
|
|
|
});
|
2016-05-18 14:11:52 +08:00
|
|
|
|
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should expose an avg formula', function (done) {
|
2016-05-18 16:48:13 +08:00
|
|
|
var testClient = new TestClient(overviewsMapConfig);
|
2019-11-14 03:08:04 +08:00
|
|
|
testClient.getDataview('test_avg', { own_filter: 0 }, function (err, formulaResult, headers) {
|
2016-05-18 16:48:13 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2019-11-14 03:08:04 +08:00
|
|
|
assert.deepStrictEqual(formulaResult, {
|
2019-10-22 01:07:24 +08:00
|
|
|
operation: 'avg',
|
|
|
|
result: 3,
|
|
|
|
nulls: 0,
|
|
|
|
type: 'formula',
|
|
|
|
infinities: 0,
|
|
|
|
nans: 0
|
2017-06-15 01:20:39 +08:00
|
|
|
});
|
2016-05-18 16:48:13 +08:00
|
|
|
|
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should expose a count formula', function (done) {
|
2016-05-18 16:48:13 +08:00
|
|
|
var testClient = new TestClient(overviewsMapConfig);
|
2019-11-14 03:08:04 +08:00
|
|
|
testClient.getDataview('test_count', { own_filter: 0 }, function (err, formulaResult, headers) {
|
2016-05-18 16:48:13 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2019-11-14 03:08:04 +08:00
|
|
|
assert.deepStrictEqual(formulaResult, {
|
2019-10-22 01:07:24 +08:00
|
|
|
operation: 'count',
|
|
|
|
result: 5,
|
|
|
|
nulls: 0,
|
|
|
|
type: 'formula',
|
|
|
|
infinities: 0,
|
|
|
|
nans: 0
|
2017-06-15 01:20:39 +08:00
|
|
|
});
|
2016-05-18 16:48:13 +08:00
|
|
|
|
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should expose a max formula', function (done) {
|
2016-05-18 16:48:13 +08:00
|
|
|
var testClient = new TestClient(overviewsMapConfig);
|
2019-11-14 03:08:04 +08:00
|
|
|
testClient.getDataview('test_max', { own_filter: 0 }, function (err, formulaResult) {
|
2016-05-18 16:48:13 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2019-11-14 03:08:04 +08:00
|
|
|
assert.deepStrictEqual(formulaResult, {
|
2019-10-22 01:07:24 +08:00
|
|
|
operation: 'max',
|
|
|
|
result: 5,
|
|
|
|
nulls: 0,
|
|
|
|
infinities: 0,
|
|
|
|
nans: 0,
|
|
|
|
type: 'formula'
|
2017-06-09 21:18:37 +08:00
|
|
|
});
|
2016-05-18 16:48:13 +08:00
|
|
|
|
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should expose a min formula', function (done) {
|
2016-05-18 16:48:13 +08:00
|
|
|
var testClient = new TestClient(overviewsMapConfig);
|
2019-11-14 03:08:04 +08:00
|
|
|
testClient.getDataview('test_min', { own_filter: 0 }, function (err, formulaResult) {
|
2016-05-18 16:48:13 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2019-11-14 03:08:04 +08:00
|
|
|
assert.deepStrictEqual(formulaResult, {
|
2019-10-22 01:07:24 +08:00
|
|
|
operation: 'min',
|
|
|
|
result: 1,
|
|
|
|
nulls: 0,
|
|
|
|
infinities: 0,
|
|
|
|
nans: 0,
|
|
|
|
type: 'formula'
|
2017-06-09 21:18:37 +08:00
|
|
|
});
|
2016-05-18 16:48:13 +08:00
|
|
|
|
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should admit a bbox', function (done) {
|
2016-05-19 00:16:32 +08:00
|
|
|
var params = {
|
2019-10-22 01:07:24 +08:00
|
|
|
bbox: '-170,-80,170,80'
|
2016-05-19 00:16:32 +08:00
|
|
|
};
|
|
|
|
var testClient = new TestClient(overviewsMapConfig);
|
2019-11-14 03:08:04 +08:00
|
|
|
testClient.getDataview('test_sum', params, function (err, formulaResult) {
|
2016-05-19 00:16:32 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2019-11-14 03:08:04 +08:00
|
|
|
assert.deepStrictEqual(formulaResult, {
|
2019-10-22 01:07:24 +08:00
|
|
|
operation: 'sum',
|
|
|
|
result: 15,
|
|
|
|
nulls: 0,
|
|
|
|
infinities: 0,
|
|
|
|
nans: 0,
|
|
|
|
type: 'formula'
|
2017-06-15 01:20:39 +08:00
|
|
|
});
|
2016-05-19 00:16:32 +08:00
|
|
|
|
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should expose a histogram', function (done) {
|
2017-03-17 02:15:34 +08:00
|
|
|
var testClient = new TestClient(overviewsMapConfig);
|
2018-08-30 00:00:13 +08:00
|
|
|
testClient.getDataview('test_histogram', function (err, histogram, headers) {
|
2017-03-17 02:15:34 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
assert.ok(histogram);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(histogram.type, 'histogram');
|
2017-03-17 02:15:34 +08:00
|
|
|
assert.ok(Array.isArray(histogram.bins));
|
2018-08-30 20:30:03 +08:00
|
|
|
|
2017-03-17 02:15:34 +08:00
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('filters', function () {
|
2017-03-17 02:15:34 +08:00
|
|
|
describe('histogram', function () {
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should expose a filtered histogram', function (done) {
|
2017-03-17 02:15:34 +08:00
|
|
|
var params = {
|
|
|
|
filters: {
|
|
|
|
dataviews: { test_histogram: { min: 2 } }
|
2017-12-13 17:43:43 +08:00
|
|
|
},
|
|
|
|
own_filter: 1
|
2017-03-17 02:15:34 +08:00
|
|
|
};
|
|
|
|
var testClient = new TestClient(overviewsMapConfig);
|
|
|
|
testClient.getDataview('test_histogram', params, function (err, histogram) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
assert.ok(histogram);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(histogram.type, 'histogram');
|
2017-03-17 02:15:34 +08:00
|
|
|
assert.ok(Array.isArray(histogram.bins));
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(histogram.bins.length, 4);
|
2017-03-17 02:15:34 +08:00
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should expose a filtered histogram with no results', function (done) {
|
2017-03-17 02:15:34 +08:00
|
|
|
var params = {
|
|
|
|
filters: {
|
|
|
|
dataviews: { test_histogram: { max: -1 } }
|
2017-12-13 17:43:43 +08:00
|
|
|
},
|
|
|
|
own_filter: 1
|
2017-03-17 02:15:34 +08:00
|
|
|
};
|
|
|
|
var testClient = new TestClient(overviewsMapConfig);
|
|
|
|
testClient.getDataview('test_histogram', params, function (err, histogram) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
assert.ok(histogram);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(histogram.type, 'histogram');
|
2017-03-17 02:15:34 +08:00
|
|
|
assert.ok(Array.isArray(histogram.bins));
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(histogram.bins.length, 0);
|
2017-03-17 02:15:34 +08:00
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should expose a filtered date histogram with no results', function (done) {
|
2017-03-17 02:15:34 +08:00
|
|
|
// This most likely works because the overviews will pass
|
|
|
|
// the responsibility to the normal dataviews.
|
|
|
|
var params = {
|
|
|
|
filters: {
|
|
|
|
dataviews: { test_histogram_date: { max: -1 } }
|
2017-12-13 17:43:43 +08:00
|
|
|
},
|
|
|
|
own_filter: 1
|
2017-03-17 02:15:34 +08:00
|
|
|
};
|
|
|
|
var testClient = new TestClient(overviewsMapConfig);
|
|
|
|
testClient.getDataview('test_histogram_date', params, function (err, histogram) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
assert.ok(histogram);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(histogram.type, 'histogram');
|
2017-03-17 02:15:34 +08:00
|
|
|
assert.ok(Array.isArray(histogram.bins));
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(histogram.bins.length, 0);
|
2017-03-17 02:15:34 +08:00
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-05-18 14:11:52 +08:00
|
|
|
describe('category', function () {
|
2016-05-19 00:16:32 +08:00
|
|
|
var params = {
|
|
|
|
filters: {
|
2019-10-22 01:07:24 +08:00
|
|
|
dataviews: { test_categories: { accept: ['Hawai'] } }
|
2016-05-19 00:16:32 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should expose a filtered sum formula', function (done) {
|
2016-05-18 16:48:13 +08:00
|
|
|
var testClient = new TestClient(overviewsMapConfig);
|
2019-11-14 03:08:04 +08:00
|
|
|
testClient.getDataview('test_sum', params, function (err, formulaResult, headers) {
|
2016-05-18 14:11:52 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2019-11-14 03:08:04 +08:00
|
|
|
assert.deepStrictEqual(formulaResult, {
|
2019-10-22 01:07:24 +08:00
|
|
|
operation: 'sum',
|
|
|
|
result: 1,
|
|
|
|
nulls: 0,
|
|
|
|
infinities: 0,
|
|
|
|
nans: 0,
|
|
|
|
type: 'formula'
|
2017-06-15 01:20:39 +08:00
|
|
|
});
|
2020-06-02 23:09:06 +08:00
|
|
|
|
2016-05-18 14:11:52 +08:00
|
|
|
testClient.drain(done);
|
|
|
|
});
|
2016-05-19 00:16:32 +08:00
|
|
|
});
|
2016-05-18 16:48:13 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should expose a filtered avg formula', function (done) {
|
2016-05-19 00:16:32 +08:00
|
|
|
var testClient = new TestClient(overviewsMapConfig);
|
2019-11-14 03:08:04 +08:00
|
|
|
testClient.getDataview('test_avg', params, function (err, formulaResult, headers) {
|
2016-05-19 00:16:32 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2019-11-14 03:08:04 +08:00
|
|
|
assert.deepStrictEqual(formulaResult, {
|
2019-10-22 01:07:24 +08:00
|
|
|
operation: 'avg',
|
|
|
|
result: 1,
|
|
|
|
nulls: 0,
|
|
|
|
infinities: 0,
|
|
|
|
nans: 0,
|
|
|
|
type: 'formula'
|
2017-06-15 01:20:39 +08:00
|
|
|
});
|
2016-05-18 16:48:13 +08:00
|
|
|
|
2016-05-19 00:16:32 +08:00
|
|
|
testClient.drain(done);
|
2016-05-18 16:48:13 +08:00
|
|
|
});
|
2016-05-19 00:16:32 +08:00
|
|
|
});
|
2016-05-18 16:48:13 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should expose a filtered count formula', function (done) {
|
2016-05-19 00:16:32 +08:00
|
|
|
var testClient = new TestClient(overviewsMapConfig);
|
2019-11-14 03:08:04 +08:00
|
|
|
testClient.getDataview('test_count', params, function (err, formulaResult, headers) {
|
2016-05-19 00:16:32 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2019-11-14 03:08:04 +08:00
|
|
|
assert.deepStrictEqual(formulaResult, {
|
2019-10-22 01:07:24 +08:00
|
|
|
operation: 'count',
|
|
|
|
result: 1,
|
|
|
|
infinities: 0,
|
|
|
|
nans: 0,
|
|
|
|
nulls: 0,
|
|
|
|
type: 'formula'
|
2017-06-15 22:31:24 +08:00
|
|
|
});
|
2016-05-18 16:48:13 +08:00
|
|
|
|
2016-05-19 00:16:32 +08:00
|
|
|
testClient.drain(done);
|
2016-05-18 16:48:13 +08:00
|
|
|
});
|
2016-05-19 00:16:32 +08:00
|
|
|
});
|
2016-05-18 16:48:13 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should expose a filterd max formula', function (done) {
|
2016-05-19 00:16:32 +08:00
|
|
|
var testClient = new TestClient(overviewsMapConfig);
|
2019-11-14 03:08:04 +08:00
|
|
|
testClient.getDataview('test_max', params, function (err, formulaResult) {
|
2016-05-19 00:16:32 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2019-11-14 03:08:04 +08:00
|
|
|
assert.deepStrictEqual(formulaResult, {
|
2019-10-22 01:07:24 +08:00
|
|
|
operation: 'max',
|
|
|
|
result: 1,
|
|
|
|
nulls: 0,
|
|
|
|
infinities: 0,
|
|
|
|
nans: 0,
|
|
|
|
type: 'formula'
|
2017-06-09 21:18:37 +08:00
|
|
|
});
|
2016-05-18 16:48:13 +08:00
|
|
|
|
2016-05-19 00:16:32 +08:00
|
|
|
testClient.drain(done);
|
2016-05-18 16:48:13 +08:00
|
|
|
});
|
2016-05-19 00:16:32 +08:00
|
|
|
});
|
2016-05-18 16:48:13 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should expose a filterd min formula', function (done) {
|
2016-05-19 00:16:32 +08:00
|
|
|
var testClient = new TestClient(overviewsMapConfig);
|
2019-11-14 03:08:04 +08:00
|
|
|
testClient.getDataview('test_min', params, function (err, formulaResult) {
|
2016-05-19 00:16:32 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2019-11-14 03:08:04 +08:00
|
|
|
assert.deepStrictEqual(formulaResult, {
|
2019-10-22 01:07:24 +08:00
|
|
|
operation: 'min',
|
|
|
|
result: 1,
|
|
|
|
nulls: 0,
|
|
|
|
infinities: 0,
|
|
|
|
nans: 0,
|
|
|
|
type: 'formula'
|
2017-06-09 21:18:37 +08:00
|
|
|
});
|
2016-05-18 16:48:13 +08:00
|
|
|
|
2016-05-19 00:16:32 +08:00
|
|
|
testClient.drain(done);
|
2016-05-18 16:48:13 +08:00
|
|
|
});
|
2016-05-19 00:16:32 +08:00
|
|
|
});
|
2016-05-18 16:48:13 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should expose a filtered sum formula with bbox', function (done) {
|
2016-05-19 00:16:32 +08:00
|
|
|
var bboxparams = {
|
|
|
|
filters: {
|
2019-10-22 01:07:24 +08:00
|
|
|
dataviews: { test_categories: { accept: ['Hawai'] } }
|
2016-05-19 00:16:32 +08:00
|
|
|
},
|
2019-10-22 01:07:24 +08:00
|
|
|
bbox: '-170,-80,170,80'
|
2016-05-19 00:16:32 +08:00
|
|
|
};
|
|
|
|
var testClient = new TestClient(overviewsMapConfig);
|
2019-11-14 03:08:04 +08:00
|
|
|
testClient.getDataview('test_sum', bboxparams, function (err, formulaResult) {
|
2016-05-19 00:16:32 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2019-11-14 03:08:04 +08:00
|
|
|
assert.deepStrictEqual(formulaResult, {
|
2019-10-22 01:07:24 +08:00
|
|
|
operation: 'sum',
|
|
|
|
result: 1,
|
|
|
|
nulls: 0,
|
|
|
|
infinities: 0,
|
|
|
|
nans: 0,
|
|
|
|
type: 'formula'
|
2017-06-15 01:20:39 +08:00
|
|
|
});
|
2016-05-19 00:16:32 +08:00
|
|
|
testClient.drain(done);
|
|
|
|
});
|
2016-05-18 14:11:52 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-06-14 01:01:28 +08:00
|
|
|
describe('aggregation special float values', function () {
|
|
|
|
var params = {};
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should expose an aggregation dataview filtering special float values out', function (done) {
|
2017-06-14 01:01:28 +08:00
|
|
|
var testClient = new TestClient(overviewsMapConfig);
|
2018-08-30 20:30:03 +08:00
|
|
|
testClient.getDataview('test_categories_special_values', params, function (err, dataview, headers) {
|
2017-06-14 01:01:28 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2018-08-30 20:30:03 +08:00
|
|
|
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(dataview, {
|
2017-06-14 01:01:28 +08:00
|
|
|
aggregation: 'sum',
|
|
|
|
count: 5,
|
|
|
|
nulls: 0,
|
|
|
|
nans: 1,
|
|
|
|
infinities: 1,
|
|
|
|
min: 6,
|
|
|
|
max: 6,
|
2017-06-14 21:05:46 +08:00
|
|
|
categoriesCount: 1,
|
2019-10-22 01:07:24 +08:00
|
|
|
categories: [{ category: 'Hawai', value: 6, agg: false }],
|
2017-06-14 01:01:28 +08:00
|
|
|
type: 'aggregation'
|
|
|
|
});
|
2018-08-30 20:30:03 +08:00
|
|
|
|
2017-06-14 01:01:28 +08:00
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
2017-06-15 00:57:26 +08:00
|
|
|
|
|
|
|
it('should expose a histogram dataview filtering special float values out', function (done) {
|
|
|
|
var testClient = new TestClient(overviewsMapConfig);
|
|
|
|
testClient.getDataview('test_histogram_special_values', params, function (err, dataview) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(dataview, {
|
2017-06-15 00:57:26 +08:00
|
|
|
bin_width: 0,
|
|
|
|
bins_count: 1,
|
|
|
|
bins_start: 3,
|
|
|
|
nulls: 0,
|
|
|
|
infinities: 1,
|
|
|
|
nans: 1,
|
|
|
|
avg: 3,
|
2019-10-22 01:07:24 +08:00
|
|
|
bins: [{ bin: 0, min: 3, max: 3, avg: 3, freq: 2 }],
|
2017-06-15 00:57:26 +08:00
|
|
|
type: 'histogram'
|
|
|
|
});
|
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
2017-06-15 01:19:08 +08:00
|
|
|
|
|
|
|
it('should expose a formula (sum) dataview filtering special float values out', function (done) {
|
|
|
|
var testClient = new TestClient(overviewsMapConfig);
|
2017-06-15 01:20:39 +08:00
|
|
|
testClient.getDataview('test_formula_sum_special_values', params, function (err, dataview) {
|
2017-06-15 01:19:08 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(dataview, {
|
2017-06-15 01:19:08 +08:00
|
|
|
operation: 'sum',
|
|
|
|
result: 6,
|
|
|
|
nulls: 0,
|
|
|
|
nans: 1,
|
|
|
|
infinities: 1,
|
|
|
|
type: 'formula'
|
|
|
|
});
|
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
2017-06-14 01:01:28 +08:00
|
|
|
});
|
2019-11-12 01:14:30 +08:00
|
|
|
|
2019-11-14 03:07:41 +08:00
|
|
|
describe('agreggation validation', function () {
|
2019-11-12 01:14:30 +08:00
|
|
|
const params = {
|
|
|
|
response: {
|
|
|
|
status: 400,
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json; charset=utf-8'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-11-14 03:07:41 +08:00
|
|
|
function createMapConfig (options) {
|
2019-11-12 01:14:30 +08:00
|
|
|
return {
|
2019-11-12 21:54:25 +08:00
|
|
|
version: '1.8.0',
|
2019-11-12 01:14:30 +08:00
|
|
|
analyses: [
|
2019-11-14 03:07:41 +08:00
|
|
|
{
|
|
|
|
id: 'data-source',
|
2019-11-12 01:14:30 +08:00
|
|
|
type: 'source',
|
|
|
|
params: {
|
|
|
|
query: 'select * from test_table_overviews'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
2019-11-14 03:07:41 +08:00
|
|
|
dataviews: {
|
2019-11-12 01:14:30 +08:00
|
|
|
test_invalid_aggregation: {
|
|
|
|
type: 'aggregation',
|
2019-11-14 03:07:41 +08:00
|
|
|
source: { id: 'data-source' },
|
2019-11-12 01:14:30 +08:00
|
|
|
options: options
|
|
|
|
}
|
|
|
|
},
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
type: 'mapnik',
|
|
|
|
options: {
|
|
|
|
sql: 'select * from test_table_overviews',
|
|
|
|
cartocss: '#layer { marker-fill: red; marker-width: 32; marker-allow-overlap: true; }',
|
|
|
|
cartocss_version: '2.3.0',
|
|
|
|
source: { id: 'data-source' }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
it('should fail if missing column', function (done) {
|
|
|
|
var options = {
|
2019-11-14 03:07:41 +08:00
|
|
|
aggregation: 'sum',
|
|
|
|
aggregationColumn: 'value'
|
2019-11-12 01:14:30 +08:00
|
|
|
};
|
2019-11-12 21:48:37 +08:00
|
|
|
var missingColumnMapConfig = createMapConfig(options);
|
2019-11-12 01:14:30 +08:00
|
|
|
|
2019-11-12 21:54:25 +08:00
|
|
|
var testClient = new TestClient(missingColumnMapConfig);
|
2019-11-12 01:14:30 +08:00
|
|
|
testClient.getDataview('test_invalid_aggregation', params, function (err, dataview) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.deepStrictEqual(dataview, {
|
|
|
|
errors: ["Aggregation expects 'column' in dataview options"],
|
|
|
|
errors_with_context: [{
|
|
|
|
type: 'unknown',
|
|
|
|
message: "Aggregation expects 'column' in dataview options"
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
|
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should fail if no aggregation operation', function (done) {
|
|
|
|
var options = {
|
2019-11-14 03:07:41 +08:00
|
|
|
column: 'value',
|
|
|
|
aggregationColumn: 'value'
|
2019-11-12 01:14:30 +08:00
|
|
|
};
|
|
|
|
var missingOperationMapConfig = createMapConfig(options);
|
|
|
|
|
|
|
|
var testClient = new TestClient(missingOperationMapConfig);
|
|
|
|
testClient.getDataview('test_invalid_aggregation', params, function (err, dataview) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.deepStrictEqual(dataview, {
|
|
|
|
errors: ["Aggregation expects 'aggregation' operation in dataview options"],
|
|
|
|
errors_with_context: [{
|
|
|
|
type: 'unknown',
|
|
|
|
message: "Aggregation expects 'aggregation' operation in dataview options"
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
|
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should fail if fake operation', function (done) {
|
|
|
|
var options = {
|
2019-11-14 03:07:41 +08:00
|
|
|
column: 'value',
|
|
|
|
aggregation: 'wadus',
|
|
|
|
aggregationColumn: 'value'
|
2019-11-12 01:14:30 +08:00
|
|
|
};
|
|
|
|
var wrongOperationMapConfig = createMapConfig(options);
|
|
|
|
|
|
|
|
var testClient = new TestClient(wrongOperationMapConfig);
|
|
|
|
testClient.getDataview('test_invalid_aggregation', params, function (err, dataview) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.deepStrictEqual(dataview, {
|
|
|
|
errors: ["Aggregation does not support 'wadus' operation"],
|
|
|
|
errors_with_context: [{
|
|
|
|
type: 'unknown',
|
|
|
|
message: "Aggregation does not support 'wadus' operation"
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
|
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should fail if invalid operation for overview', function (done) {
|
|
|
|
var options = {
|
2019-11-14 03:07:41 +08:00
|
|
|
column: 'value',
|
|
|
|
aggregation: 'avg',
|
|
|
|
aggregationColumn: 'value'
|
2019-11-12 01:14:30 +08:00
|
|
|
};
|
|
|
|
var wrongOperationMapConfig = createMapConfig(options);
|
|
|
|
|
|
|
|
var testClient = new TestClient(wrongOperationMapConfig);
|
|
|
|
testClient.getDataview('test_invalid_aggregation', params, function (err, dataview) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.deepStrictEqual(dataview, {
|
|
|
|
errors: ["Aggregation does not support 'avg' operation in dataview overview options"],
|
|
|
|
errors_with_context: [{
|
|
|
|
type: 'unknown',
|
|
|
|
message: "Aggregation does not support 'avg' operation in dataview overview options"
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
|
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should fail if no aggregation column when needed', function (done) {
|
|
|
|
var options = {
|
2019-11-14 03:07:41 +08:00
|
|
|
column: 'value',
|
|
|
|
aggregation: 'sum'
|
2019-11-12 01:14:30 +08:00
|
|
|
};
|
|
|
|
var missingOptionMapConfig = createMapConfig(options);
|
|
|
|
|
|
|
|
var testClient = new TestClient(missingOptionMapConfig);
|
|
|
|
testClient.getDataview('test_invalid_aggregation', params, function (err, dataview) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.deepStrictEqual(dataview, {
|
|
|
|
errors: ["Aggregation 'sum' is missing some options: aggregationColumn"],
|
|
|
|
errors_with_context: [{
|
|
|
|
type: 'unknown',
|
|
|
|
message: "Aggregation 'sum' is missing some options: aggregationColumn"
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
|
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2016-05-18 14:11:52 +08:00
|
|
|
});
|
|
|
|
});
|