From b67f6053e826c3dd047c245af87d7cb4a7e59e7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Wed, 12 Jul 2017 15:14:41 +0200 Subject: [PATCH] Should respect first timestamp as bin_start --- lib/cartodb/models/dataview/histogram.js | 6 +-- test/acceptance/dataviews/histogram.js | 48 +++++++++++++++++++++++- 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/lib/cartodb/models/dataview/histogram.js b/lib/cartodb/models/dataview/histogram.js index 8d624163..212cf3bb 100644 --- a/lib/cartodb/models/dataview/histogram.js +++ b/lib/cartodb/models/dataview/histogram.js @@ -562,10 +562,10 @@ function getTimezone(timezone) { function populateBinStart(override, firstRow) { var binStart; - if (override.hasOwnProperty('start')) { - binStart = getBinStart(override); - } else if (firstRow.hasOwnProperty('timestamp')) { + if (firstRow.hasOwnProperty('timestamp')) { binStart = firstRow.timestamp; + } else if (override.hasOwnProperty('start')) { + binStart = getBinStart(override); } else { binStart = firstRow.min; } diff --git a/test/acceptance/dataviews/histogram.js b/test/acceptance/dataviews/histogram.js index c5927d52..e33cb2c0 100644 --- a/test/acceptance/dataviews/histogram.js +++ b/test/acceptance/dataviews/histogram.js @@ -173,6 +173,16 @@ describe('histogram-dataview for date column type', function() { options: { column: 'd' } + }, + minute_histogram: { + source: { + id: 'minute-histogram-source' + }, + type: 'histogram', + options: { + column: 'd', + aggregation: 'minute' + } } }, [ @@ -211,6 +221,18 @@ describe('histogram-dataview for date column type', function() { ") date" ].join(' ') } + }, + { + "id": "minute-histogram-source", + "type": "source", + "params": { + "query": [ + "select null::geometry the_geom_webmercator, date AS d", + "from generate_series(", + "'2007-02-15 23:50:00'::timestamp, '2007-02-16 00:10:00'::timestamp, '1 minute'::interval", + ") date" + ].join(' ') + } } ] ); @@ -282,8 +304,8 @@ describe('histogram-dataview for date column type', function() { it('should override start and end ' + test.desc, function (done) { var params = { - start: 1180659600, // 2007-06-01 01:00:00 - end: 1193792400 // 2007-10-31 01:00:00 + start: 1180659600, // 2007-06-01 01:00:00 UTC => '2007-05-31T21:00:00-04:00' + end: 1193792400 // 2007-10-31 01:00:00 UTC }; this.testClient = new TestClient(mapConfig, 1234); @@ -300,6 +322,28 @@ describe('histogram-dataview for date column type', function() { }); }); + + it('should return same histogram ' + test.desc, function (done) { + var params = { + start: 1171501200, // 2007-02-15 01:00:00 = min(date_colum) + end: 1207702800 // 2008-04-09 01:00:00 = max(date_colum) + }; + + this.testClient = new TestClient(mapConfig, 1234); + this.testClient.getDataview(test.dataviewId, {}, function (err, dataview) { + assert.ok(!err, err); + + this.testClient = new TestClient(mapConfig, 1234); + this.testClient.getDataview(test.dataviewId, params, function (err, filteredDataview) { + assert.ok(!err, err); + + assert.deepEqual(dataview, filteredDataview); + done(); + }); + }); + }); + + it('should aggregate histogram overriding default timezone to CEST ' + test.desc, function (done) { var TIMEZONE_CEST_IN_SECONDS = 2 * 3600; // Central European Summer Time (Daylight Saving Time) var TIMEZONE_CEST_IN_MINUTES = 2 * 60; // Central European Summer Time (Daylight Saving Time)