replace timezone => offset

This commit is contained in:
Carlos Matallín
2017-07-14 18:30:36 +02:00
parent 21b8655f85
commit 70b4d5b7fd
5 changed files with 79 additions and 79 deletions
+1 -1
View File
@@ -104,7 +104,7 @@ function getQueryRewriteData(mapConfig, dataviewDefinition, params) {
}
function getOverrideParams(params, ownFilter) {
var overrideParams = _.reduce(_.pick(params, 'start', 'end', 'bins', 'timezone'),
var overrideParams = _.reduce(_.pick(params, 'start', 'end', 'bins', 'offset'),
function castNumbers(overrides, val, k) {
if (!Number.isFinite(+val)) {
throw new Error('Invalid number format for parameter \'' + k + '\'');
+1 -1
View File
@@ -89,7 +89,7 @@ LayergroupController.prototype.register = function(app) {
'column_type', // string
'bins', // number
'aggregation', //string
'timezone', // number
'offset', // number
'q' // widgets search
];
+23 -23
View File
@@ -145,9 +145,9 @@ var dateBasicsQueryTpl = dot.template([
' min(date_part(\'epoch\', {{=it._column}})) AS min_val,',
' avg(date_part(\'epoch\', {{=it._column}})) AS avg_val,',
' min(date_trunc(',
' \'{{=it._aggregation}}\', {{=it._column}} AT TIME ZONE \'{{=it._timezone}}\'',
' \'{{=it._aggregation}}\', {{=it._column}} AT TIME ZONE \'{{=it._offset}}\'',
' )) AS start_date,',
' max({{=it._column}} AT TIME ZONE \'{{=it._timezone}}\') AS end_date,',
' max({{=it._column}} AT TIME ZONE \'{{=it._offset}}\') AS end_date,',
' count(1) AS total_rows',
' FROM ({{=it._query}}) _cdb_basics',
')'
@@ -162,11 +162,11 @@ var dateOverrideBasicsQueryTpl = dot.template([
' min(',
' date_trunc(',
' \'{{=it._aggregation}}\',',
' TO_TIMESTAMP({{=it._start}})::timestamp AT TIME ZONE \'{{=it._timezone}}\'',
' TO_TIMESTAMP({{=it._start}})::timestamp AT TIME ZONE \'{{=it._offset}}\'',
' )',
' ) AS start_date,',
' max(',
' TO_TIMESTAMP({{=it._end}})::timestamp AT TIME ZONE \'{{=it._timezone}}\'',
' TO_TIMESTAMP({{=it._end}})::timestamp AT TIME ZONE \'{{=it._offset}}\'',
' ) AS end_date,',
' count(1) AS total_rows',
' FROM ({{=it._query}}) _cdb_basics',
@@ -201,7 +201,7 @@ var dateHistogramQueryTpl = dot.template([
' THEN 0',
' ELSE GREATEST(1, LEAST(',
' WIDTH_BUCKET(',
' {{=it._column}}::timestamp AT TIME ZONE \'{{=it._timezone}}\',',
' {{=it._column}}::timestamp AT TIME ZONE \'{{=it._offset}}\',',
' bins_array',
' ),',
' bins_number',
@@ -212,7 +212,7 @@ var dateHistogramQueryTpl = dot.template([
' \'epoch\', ',
' date_trunc(',
' \'{{=it._aggregation}}\', {{=it._column}}::timestamptz',
' ) AT TIME ZONE \'{{=it._timezone}}\'',
' ) AT TIME ZONE \'{{=it._offset}}\'',
' )',
' )::numeric AS timestamp,',
' min(date_part(\'epoch\', {{=it._column}}))::numeric AS min,',
@@ -243,7 +243,7 @@ Time series:
options: {
column: 'date', // column data type: date
aggregation: 'day' // OPTIONAL (if undefined then it'll be built as numeric)
timezone: -7200 // OPTIONAL (UTC offset in seconds)
offset: -7200 // OPTIONAL (UTC offset in seconds)
}
}
*/
@@ -257,7 +257,7 @@ function Histogram(query, options, queries) {
this.column = options.column;
this.bins = options.bins;
this.aggregation = options.aggregation;
this.timezone = options.timezone;
this.offset = options.offset;
this._columnType = null;
}
@@ -380,7 +380,7 @@ Histogram.prototype._buildDateHistogramQuery = function (psql, override, callbac
var _column = this.column;
var _query = this.query;
var _aggregation = override && override.aggregation ? override.aggregation : this.aggregation;
var _timezone = override && Number.isFinite(override.timezone) ? override.timezone : this.timezone;
var _offset = override && Number.isFinite(override.offset) ? override.offset : this.offset;
if (!_aggregation) {
this.getAutomaticAggregation(psql, function (err, aggregation) {
@@ -403,14 +403,14 @@ Histogram.prototype._buildDateHistogramQuery = function (psql, override, callbac
_aggregation: _aggregation,
_start: getBinStart(override),
_end: getBinEnd(override),
_timezone: getTimezone(_timezone, _aggregation)
_offset: getOffset(_offset, _aggregation)
});
} else {
dateBasicsQuery = dateBasicsQueryTpl({
_query: _query,
_column: _column,
_aggregation: _aggregation,
_timezone: getTimezone(_timezone, _aggregation)
_offset: getOffset(_offset, _aggregation)
});
}
@@ -429,7 +429,7 @@ Histogram.prototype._buildDateHistogramQuery = function (psql, override, callbac
_query: _query,
_column: _column,
_aggregation: _aggregation,
_timezone: getTimezone(_timezone, _aggregation)
_offset: getOffset(_offset, _aggregation)
});
var histogramSql = [
@@ -492,7 +492,7 @@ Histogram.prototype.format = function(result, override) {
var buckets = [];
var aggregation = getAggregation(override, this.aggregation);
var timezone = getTimezoneParam(override, this.timezone);
var offset = getOffsetParam(override, this.offset);
var binsCount = getBinsCount(override);
var width = getWidth(override);
var binsStart = getBinStart(override);
@@ -514,7 +514,7 @@ Histogram.prototype.format = function(result, override) {
return {
aggregation: aggregation,
timezone: timezone,
offset: offset,
bin_width: width,
bins_count: binsCount,
bins_start: binsStart,
@@ -528,12 +528,12 @@ function getAggregation(override, aggregation) {
return override && override.aggregation ? override.aggregation : aggregation;
}
function getTimezoneParam(override, timezone) {
if (override && override.timezone) {
return override.timezone;
function getOffsetParam(override, offset) {
if (override && override.offset) {
return override.offset;
}
if (timezone) {
return timezone;
if (offset) {
return offset;
}
return 0;
}
@@ -567,8 +567,8 @@ function getWidth(override) {
return width;
}
function getTimezone(timezone, aggregation) {
if (!timezone) {
function getOffset(offset, aggregation) {
if (!offset) {
return '0';
}
@@ -576,8 +576,8 @@ function getTimezone(timezone, aggregation) {
return '0';
}
var timezoneInHours = Math.ceil(timezone / 3600);
return '' + timezoneInHours;
var offsetInHours = Math.ceil(offset / 3600);
return '' + offsetInHours;
}
function populateBinStart(override, firstRow) {