From 6c063095a365d80478685ab64130017a49b00cb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Thu, 3 Aug 2017 18:18:35 +0200 Subject: [PATCH 1/2] Going red: aggregation is undefined when automattic mode is enabled and timestamp start is 1970-01-01 (epoch) --- test/acceptance/dataviews/histogram.js | 72 ++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/test/acceptance/dataviews/histogram.js b/test/acceptance/dataviews/histogram.js index 51808d67..1e3a2d40 100644 --- a/test/acceptance/dataviews/histogram.js +++ b/test/acceptance/dataviews/histogram.js @@ -887,3 +887,75 @@ describe('histogram-dates: aggregation input value', function() { }); }); }); + + +describe('histogram-dates: timestamp starts at epoch', function() { + + afterEach(function(done) { + if (this.testClient) { + this.testClient.drain(done); + } else { + done(); + } + }); + + var mapConfig = createMapConfig( + [ + { + type: "cartodb", + options: { + source: { + id: "a0" + }, + cartocss: "#points { marker-width: 10; marker-fill: red; }", + cartocss_version: "2.3.0" + } + } + ], + { + epoch_start_histogram: { + source: { + id: 'a0' + }, + type: 'histogram', + options: { + column: 'd', + aggregation: 'auto' + } + } + }, + [ + { + id: 'a0', + type: 'source', + params: { + query: [ + 'select null::geometry the_geom_webmercator, date AS d', + 'from generate_series(', + '\'1970-01-04 10:00:00\'::timestamp,', + '\'1984-01-04 10:00:00\'::timestamp,', + ' \'1 month\'::interval', + ') date' + ].join(' ') + } + } + ] + ); + + it('should work when timestamp_start is epoch (1970-01-01 = 0)', function(done) { + this.testClient = new TestClient(mapConfig, 1234); + const override = {}; + + this.testClient.getDataview('epoch_start_histogram', override, function(err, dataview) { + assert.ifError(err); + + console.log(dataview); + const { aggregation, timestamp_start } = dataview; + + assert.equal(timestamp_start, 0); + assert.equal(aggregation, 'quarter'); + + done(); + }); + }); +}); From 48ad7059e1de5da9095bb7f0b69d8d0199c2e50d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Thu, 3 Aug 2017 18:23:55 +0200 Subject: [PATCH 2/2] Going green: do not rely on falsy conditional --- lib/cartodb/models/dataview/histogram.js | 2 +- test/acceptance/dataviews/histogram.js | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/cartodb/models/dataview/histogram.js b/lib/cartodb/models/dataview/histogram.js index 13a9d998..76b42c03 100644 --- a/lib/cartodb/models/dataview/histogram.js +++ b/lib/cartodb/models/dataview/histogram.js @@ -589,7 +589,7 @@ Histogram.prototype.format = function(result, override) { nans = firstRow.nans_count; binsStart = populateBinStart(override, firstRow); - if (timestampStart) { + if (Number.isFinite(timestampStart)) { aggregation = getAggregation(override, this.aggregation); offset = getOffset(override, this.offset); } diff --git a/test/acceptance/dataviews/histogram.js b/test/acceptance/dataviews/histogram.js index 1e3a2d40..a75cf2b1 100644 --- a/test/acceptance/dataviews/histogram.js +++ b/test/acceptance/dataviews/histogram.js @@ -949,11 +949,10 @@ describe('histogram-dates: timestamp starts at epoch', function() { this.testClient.getDataview('epoch_start_histogram', override, function(err, dataview) { assert.ifError(err); - console.log(dataview); const { aggregation, timestamp_start } = dataview; assert.equal(timestamp_start, 0); - assert.equal(aggregation, 'quarter'); + assert.equal(aggregation, 'month'); done(); });