Windshaft-cartodb/test/acceptance/ported/torque-boundaries-test.js

474 lines
17 KiB
JavaScript
Raw Normal View History

'use strict';
var testHelper = require('../../support/test-helper');
2015-07-08 05:46:58 +08:00
var assert = require('../../support/assert');
2019-10-07 15:40:50 +08:00
var cartodbServer = require('../../../lib/server');
var ServerOptions = require('./support/ported-server-options');
2015-07-08 05:46:58 +08:00
2019-10-07 15:40:50 +08:00
var LayergroupToken = require('../../../lib/models/layergroup-token');
2019-10-22 01:07:24 +08:00
describe('torque boundary points', function () {
var server;
before(function () {
server = cartodbServer(ServerOptions);
server.setMaxListeners(0);
});
2015-07-08 05:46:58 +08:00
var layergroupIdToDelete = null;
2019-10-22 01:07:24 +08:00
beforeEach(function () {
2015-07-08 05:46:58 +08:00
layergroupIdToDelete = null;
});
2019-10-22 01:07:24 +08:00
afterEach(function (done) {
2015-09-25 22:16:51 +08:00
var keysToDelete = {
'user:localhost:mapviews:global': 5
};
var mapKey = 'map_cfg|' + LayergroupToken.parse(layergroupIdToDelete).token;
keysToDelete[mapKey] = 0;
testHelper.deleteRedisKeys(keysToDelete, done);
});
2019-10-22 01:07:24 +08:00
var boundaryPointsMapConfig = {
2015-07-08 05:46:58 +08:00
version: '1.1.0',
layers: [
2019-10-22 01:07:24 +08:00
{
type: 'torque',
options: {
sql: 'WITH p AS ( ' +
2015-07-08 05:46:58 +08:00
" SELECT '1970-01-02'::date as d, " +
// r1 is pixel resolution at zoom level 1
// s1 is tile size at zoom level 1
2019-10-22 01:07:24 +08:00
' 1e-40 as o, 78271.517578125 as r1, 20037508.5 as s1 )' +
' SELECT 1 as i, d, ST_MakePoint(0,0) as ug FROM p' +
' UNION ALL ' +
'SELECT 2, d, ST_MakePoint(-o,-o) FROM p' +
' UNION ALL ' +
'SELECT 3, d, ST_MakePoint(-o,o) FROM p' +
' UNION ALL ' +
'SELECT 4, d, ST_MakePoint(o,-o) FROM p' +
' UNION ALL ' +
'SELECT 5, d, ST_MakePoint(o,o) FROM p' +
' UNION ALL ' +
'SELECT 6, d, ST_MakePoint(-r1,r1) FROM p' +
' UNION ALL ' +
'SELECT 7, d, ST_MakePoint(-r1/2,r1) FROM p' +
' UNION ALL ' +
'SELECT 8, d, ST_MakePoint(-r1,-r1) FROM p' +
' UNION ALL ' +
2015-07-08 05:46:58 +08:00
// this is discarded, being on the right boundary
2019-10-22 01:07:24 +08:00
'SELECT 9, d, ST_MakePoint(s1,0) FROM p' +
' UNION ALL ' +
2015-07-08 05:46:58 +08:00
// this is discarded, being on the top boundary
2019-10-22 01:07:24 +08:00
'SELECT 10, d, ST_MakePoint(0,s1) FROM p' +
' UNION ALL ' +
2015-07-08 05:46:58 +08:00
// this is discarded, rounding to the right boundary
2019-10-22 01:07:24 +08:00
'SELECT 11, d, ST_MakePoint(s1-r1/2,0) FROM p' +
' UNION ALL ' +
2015-07-08 05:46:58 +08:00
// this is discarded, rounding to the top boundary
2019-10-22 01:07:24 +08:00
'SELECT 12, d, ST_MakePoint(0,s1-r1/2) FROM p',
geom_column: 'ug',
cartocss: 'Map { ' +
2015-07-08 05:46:58 +08:00
'-torque-frame-count:2; ' +
'-torque-resolution:1; ' +
'-torque-time-attribute:"d"; ' +
'-torque-data-aggregation:linear; ' +
'-torque-aggregation-function:"count(i)"; }',
2019-10-22 01:07:24 +08:00
cartocss_version: '1.0.1'
}
}
2015-07-08 05:46:58 +08:00
]
};
var tileRequests = [
{
desc: '0/0/0',
repr: [
' ------',
'| |',
'| |',
' ------'
],
z: 0,
x: 0,
y: 0,
expects: [
{
x__uint8: 255,
y__uint8: 128,
vals__uint8: [{
v: 2,
d: 'i=9 and i=11'
}],
dates__uint16: [0]
},
{
x__uint8: 128,
y__uint8: 128,
vals__uint8: [{
v: 8,
d: 'i=[1..8]'
}],
dates__uint16: [0]
},
{
x__uint8: 128,
y__uint8: 255,
vals__uint8: [{
v: 2,
d: 'i=10 and i=12'
}],
dates__uint16: [0]
}
]
},
{
desc: '1/0/0',
repr: [
'*00 | 10',
'----+----',
'01 | 11'
],
z: 1,
x: 0,
y: 0,
expects: [
{
x__uint8: 255,
y__uint8: 0,
2019-10-22 01:07:24 +08:00
vals__uint8: [{ v: 2, d: 'i=6 (-r1,r1) and i=7(-r1/2,r1)' }],
2015-07-08 05:46:58 +08:00
dates__uint16: [0]
},
{
x__uint8: 255,
y__uint8: 1,
2019-10-22 01:07:24 +08:00
vals__uint8: [{ v: 2, d: 'i=1 and i=3' }],
2015-07-08 05:46:58 +08:00
dates__uint16: [0]
},
{
x__uint8: 255,
y__uint8: 255,
2019-10-22 01:07:24 +08:00
vals__uint8: [{ v: 2, d: 'i=10 and i=12' }],
2015-07-08 05:46:58 +08:00
dates__uint16: [0]
}
]
},
{
desc: '1/1/0',
repr: [
'00 | 10*',
'----+----',
'01 | 11'
],
z: 1,
x: 1,
y: 0,
expects: [
{
x__uint8: 255,
y__uint8: 0,
2019-10-22 01:07:24 +08:00
vals__uint8: [{ v: 2, d: 'i=9 and i=11' }],
2015-07-08 05:46:58 +08:00
dates__uint16: [0]
},
{
x__uint8: 0,
y__uint8: 0,
2019-10-22 01:07:24 +08:00
vals__uint8: [{ v: 2, d: 'i=1 and i=5' }],
2015-07-08 05:46:58 +08:00
dates__uint16: [0]
},
{
x__uint8: 0,
y__uint8: 255,
2019-10-22 01:07:24 +08:00
vals__uint8: [{ v: 2, d: 'i=10 and i=12' }],
2015-07-08 05:46:58 +08:00
dates__uint16: [0]
}
]
},
{
desc: '1/0/1',
repr: [
'00 | 10',
'----+----',
'*01 | 11'
],
z: 1,
x: 0,
y: 1,
expects: [
{
x__uint8: 255,
y__uint8: 255,
2019-10-22 01:07:24 +08:00
vals__uint8: [{ v: 3, d: 'i=1, i=2 and i=8' }],
2015-07-08 05:46:58 +08:00
dates__uint16: [0]
}
]
},
{
desc: '1/1/1',
repr: [
'00 | 10',
'----+----',
'01 | 11*'
],
z: 1,
x: 1,
y: 1,
expects: [
{
x__uint8: 255,
y__uint8: 255,
vals__uint8: [{
v: 2,
d: 'i=9 and i=11'
}],
dates__uint16: [0]
},
{
x__uint8: 0,
y__uint8: 255,
vals__uint8: [{
v: 2,
d: 'i=1 and i=4'
}],
dates__uint16: [0]
}
]
}
];
2019-10-22 01:07:24 +08:00
tileRequests.forEach(function (tileRequest) {
2015-07-08 05:46:58 +08:00
// See https://github.com/CartoDB/Windshaft/issues/186
var desc = 'handles ' + tileRequest.desc + '.json.torque\n\n\t' + tileRequest.repr.join('\n\t') + '\n\n';
it(desc, function (done) {
assert.response(server, {
2019-10-02 01:34:03 +08:00
url: '/api/v1/map',
2015-07-08 05:46:58 +08:00
method: 'POST',
headers: { host: 'localhost', 'Content-Type': 'application/json' },
2015-07-08 05:46:58 +08:00
data: JSON.stringify(boundaryPointsMapConfig)
}, {}, function (res, err) {
assert.ok(!err, 'Failed to create layergroup');
var parsedBody = JSON.parse(res.body);
var expected_token = parsedBody.layergroupid;
layergroupIdToDelete = expected_token;
var partialUrl = tileRequest.z + '/' + tileRequest.x + '/' + tileRequest.y;
assert.response(server, {
2019-10-02 01:34:03 +08:00
url: '/api/v1/map/' + expected_token + '/0/' + partialUrl + '.json.torque',
method: 'GET',
headers: {
host: 'localhost'
}
2015-07-08 05:46:58 +08:00
}, {}, function (res, err) {
assert.ok(!err, 'Failed to get json');
assert.strictEqual(res.statusCode, 200, res.body);
assert.strictEqual(res.headers['content-type'], 'application/json; charset=utf-8');
2015-07-08 05:46:58 +08:00
var parsed = JSON.parse(res.body);
/* Order the JSON first by descending x__uint8 and ascending
* y__uint8 */
2019-10-22 01:07:24 +08:00
parsed.sort(function (a, b) {
if (a.x__uint8 === b.x__uint8) {
return (a.y__uint8 > b.y__uint8);
}
return (a.x__uint8 < b.x__uint8);
});
2015-07-08 05:46:58 +08:00
var i = 0;
2019-10-22 01:07:24 +08:00
tileRequest.expects.forEach(function (expected) {
assert.strictEqual(
2015-07-08 05:46:58 +08:00
parsed[i].x__uint8,
expected.x__uint8,
parsed[i].x__uint8 + ' == ' + expected.x__uint8 +
'\nRESULT\n------' +
'\n' + JSON.stringify(parsed, null, 4) +
'\nEXPECTED\n--------' +
'\n' + JSON.stringify(tileRequest.expects, null, 4)
);
assert.strictEqual(
2015-07-08 05:46:58 +08:00
parsed[i].y__uint8,
expected.y__uint8,
parsed[i].y__uint8 + ' == ' + expected.y__uint8 +
'\nRESULT\n------' +
'\n' + JSON.stringify(parsed, null, 4) +
'\nEXPECTED\n--------' +
'\n' + JSON.stringify(tileRequest.expects, null, 4)
);
var j = 0;
2019-10-22 01:07:24 +08:00
expected.vals__uint8.forEach(function (val) {
assert.strictEqual(
2015-07-08 05:46:58 +08:00
parsed[i].vals__uint8[j],
val.v,
'desc: ' + val.d +
'Number of points got=' + parsed.length + '; ' +
'expected=' + tileRequest.expects.length +
'\n\tindex=' + i +
'\n\tvals__uint8 index=' + j +
'\n\tgot=' + parsed[i].vals__uint8[j] +
'\n\texpected=' + val.v +
'\nRESULT\n------' +
'\n' + JSON.stringify(parsed, null, 4) +
'\nEXPECTED\n--------' +
'\n' + JSON.stringify(tileRequest.expects, null, 4));
j++;
});
i++;
});
assert.strictEqual(
2015-07-08 05:46:58 +08:00
parsed.length,
tileRequest.expects.length,
'Number of points did not match ' +
'got=' + parsed.length + '; ' +
'expected=' + tileRequest.expects.length +
'\nRESULT\n------' +
'\n' + JSON.stringify(parsed, null, 4) +
'\nEXPECTED\n--------' +
'\n' + JSON.stringify(tileRequest.expects, null, 4));
done();
});
});
});
});
2019-10-22 01:07:24 +08:00
it('regression london point', function (done) {
var londonPointMapConfig = {
2015-07-08 05:46:58 +08:00
version: '1.1.0',
layers: [
2019-10-22 01:07:24 +08:00
{
type: 'torque',
options: {
sql: 'SELECT ' +
'1 as i, ' +
2015-07-08 05:46:58 +08:00
"'1970-01-02'::date as d, " +
2019-10-22 01:07:24 +08:00
'ST_MakePoint(-11309.9155492599,6715342.44989312) g',
geom_column: 'g',
cartocss: 'Map { ' +
2015-07-08 05:46:58 +08:00
'-torque-frame-count:2; ' +
'-torque-resolution:1; ' +
'-torque-time-attribute:"d"; ' +
'-torque-data-aggregation:linear; ' +
'-torque-aggregation-function:"count(i)"; }',
2019-10-22 01:07:24 +08:00
cartocss_version: '1.0.1'
}
}
2015-07-08 05:46:58 +08:00
]
};
assert.response(server, {
2019-10-02 01:34:03 +08:00
url: '/api/v1/map',
2015-07-08 05:46:58 +08:00
method: 'POST',
headers: { host: 'localhost', 'Content-Type': 'application/json' },
2015-07-08 05:46:58 +08:00
data: JSON.stringify(londonPointMapConfig)
}, {}, function (res, err) {
assert.ok(!err, 'Failed to create layergroup');
var parsedBody = JSON.parse(res.body);
var layergroupId = parsedBody.layergroupid;
layergroupIdToDelete = layergroupId;
assert.response(server, {
2019-10-02 01:34:03 +08:00
url: '/api/v1/map/' + layergroupId + '/0/2/1/1.json.torque',
method: 'GET',
headers: {
host: 'localhost'
}
2015-07-08 05:46:58 +08:00
}, {}, function (res, err) {
assert.ok(!err, 'Failed to request torque.json');
var parsed = JSON.parse(res.body);
assert.deepStrictEqual(parsed, [{
2015-07-08 05:46:58 +08:00
x__uint8: 255,
y__uint8: 172,
vals__uint8: [1],
dates__uint16: [0]
}]);
done();
});
});
});
2019-10-22 01:07:24 +08:00
it('should consider resolution for least value in query', function (done) {
var londonPointMapConfig = {
2015-07-08 05:46:58 +08:00
version: '1.1.0',
layers: [
2019-10-22 01:07:24 +08:00
{
type: 'torque',
options: {
sql: '' +
'SELECT ' +
'0 as i, ' +
2015-07-08 05:46:58 +08:00
"st_transform('0101000020E6100000FABD3AB4B5031C400581A80ECC2F4940'::geometry, 3857) as g " +
2019-10-22 01:07:24 +08:00
'UNION ALL ' +
'SELECT ' +
'2 as i, ' +
2015-07-08 05:46:58 +08:00
"st_transform('0101000020E61000006739E30EAE031C406625C0C3C72F4940'::geometry, 3857) as g " +
2019-10-22 01:07:24 +08:00
'UNION ALL ' +
'SELECT ' +
'3 as i, ' +
2015-07-08 05:46:58 +08:00
"st_transform('0101000020E6100000E26DB8A2A7031C40C8BAA5C2C52F4940'::geometry, 3857) as g",
2019-10-22 01:07:24 +08:00
geom_column: 'g',
cartocss: 'Map { ' +
2015-07-08 05:46:58 +08:00
'-torque-frame-count:1; ' +
'-torque-animation-duration:30;' +
'-torque-time-attribute:"i"; ' +
'-torque-aggregation-function:"count(i)"; ' +
'-torque-resolution:2; ' +
'-torque-data-aggregation: cumulative; }',
2019-10-22 01:07:24 +08:00
cartocss_version: '1.0.1'
}
}
2015-07-08 05:46:58 +08:00
]
};
assert.response(server, {
2019-10-02 01:34:03 +08:00
url: '/api/v1/map',
2015-07-08 05:46:58 +08:00
method: 'POST',
headers: { host: 'localhost', 'Content-Type': 'application/json' },
2015-07-08 05:46:58 +08:00
data: JSON.stringify(londonPointMapConfig)
}, {}, function (res, err) {
assert.ok(!err, 'Failed to create layergroup');
var parsedBody = JSON.parse(res.body);
var layergroupId = parsedBody.layergroupid;
layergroupIdToDelete = layergroupId;
assert.response(server, {
2019-10-02 01:34:03 +08:00
url: '/api/v1/map/' + layergroupId + '/0/13/4255/2765.json.torque',
method: 'GET',
headers: {
host: 'localhost'
}
2015-07-08 05:46:58 +08:00
}, {}, function (res, err) {
assert.ok(!err, 'Failed to request torque.json');
var parsed = JSON.parse(res.body);
assert.deepStrictEqual(parsed.sort(function (a, b) { return a.x__uint8 > b.x__uint8; }), [
2015-07-08 05:46:58 +08:00
{
x__uint8: 47,
y__uint8: 127,
vals__uint8: [2],
dates__uint16: [0]
},
{
x__uint8: 48,
y__uint8: 127,
vals__uint8: [1],
dates__uint16: [0]
}
]);
done();
});
});
});
});