From c0febf2fd1a673c60891fa562ccf87605ed82a4e Mon Sep 17 00:00:00 2001 From: Javier Goizueta Date: Fri, 5 Oct 2018 20:08:40 +0200 Subject: [PATCH] Rename time dimension parameters --- .../models/aggregation/aggregation-query.js | 11 +++--- .../models/aggregation/time-dimension.js | 36 +++++++++---------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/lib/cartodb/models/aggregation/aggregation-query.js b/lib/cartodb/models/aggregation/aggregation-query.js index 8f8d2de8..fdd499f7 100644 --- a/lib/cartodb/models/aggregation/aggregation-query.js +++ b/lib/cartodb/models/aggregation/aggregation-query.js @@ -135,12 +135,13 @@ const aggregateDimensions = ctx => ctx.dimensions || {}; const timeDimensionParameters = definition => { // definition.column should correspond to a wrapped date column + const group = definition.group || {}; return { time: `to_timestamp("${definition.column}")`, - timezone: definition.timezone || 'utc', - grouping: definition.grouping, - count: definition.count || 1, - starting: definition.starting, + timezone: group.timezone || 'utc', + units: group.units, + count: group.count || 1, + starting: group.starting, format: definition.format }; }; @@ -154,7 +155,7 @@ const adaptDimensionDefinition = definition => { }; const dimensionExpression = definition => { - if (definition.grouping) { + if (definition.group) { // Currently only time dimensions are supported with parameters return Object.assign({ type: 'timeDimension' }, timeDimension(timeDimensionParameters(definition))); } else { diff --git a/lib/cartodb/models/aggregation/time-dimension.js b/lib/cartodb/models/aggregation/time-dimension.js index 9e897825..27f6de0c 100644 --- a/lib/cartodb/models/aggregation/time-dimension.js +++ b/lib/cartodb/models/aggregation/time-dimension.js @@ -111,7 +111,7 @@ const serialParts = { }; function serialSqlExpr(params) { - const { sql, zeroBased } = serialParts[params.grouping]; + const { sql, zeroBased } = serialParts[params.units]; const column = timeExpression(params.time, params.timezone); const epoch = epochExpression(params.starting); const serial = sql.replace(/\$t/g, column).replace(/\$epoch/g, epoch); @@ -150,7 +150,7 @@ function isoSqlExpr(params) { // TODO: it would be sensible to return the ISO of the first unit in the period throw new Error('Multiple time units not supported for ISO format'); } - return isoParts[params.grouping].replace(/\$t/g, column); + return isoParts[params.units].replace(/\$t/g, column); } const cyclicParts = { @@ -168,11 +168,11 @@ const cyclicParts = { function cyclicSqlExpr(params) { const column = timeExpression(params.time, params.timezone); - return cyclicParts[params.grouping].replace(/\$t/g, column); + return cyclicParts[params.units].replace(/\$t/g, column); } -const ACCEPTED_PARAMETERS = ['time', 'grouping', 'timezone', 'count', 'starting', 'format']; -const REQUIRED_PARAMETERS = ['time', 'grouping']; +const ACCEPTED_PARAMETERS = ['time', 'units', 'timezone', 'count', 'starting', 'format']; +const REQUIRED_PARAMETERS = ['time', 'units']; function validateParameters(params, checker) { const errors = []; @@ -193,33 +193,33 @@ function validateParameters(params, checker) { return params_errors.params; } -const VALID_CYCLIC_GROUPINGS = Object.keys(cyclicParts); -const VALID_SERIAL_GROUPINGS = Object.keys(serialParts); -const VALID_ISO_GROUPINGS = Object.keys(isoParts); +const VALID_CYCLIC_UNITS = Object.keys(cyclicParts); +const VALID_SERIAL_UNITS = Object.keys(serialParts); +const VALID_ISO_UNITS = Object.keys(isoParts); function cyclicCheckParams(params) { const errors = []; - if (!VALID_CYCLIC_GROUPINGS.includes(params.grouping)) { - errors.push(`Invalid grouping "${params.grouping}"`); + if (!VALID_CYCLIC_UNITS.includes(params.units)) { + errors.push(`Invalid units "${params.units}"`); } if (params.count && params.count > 1) { - errors.push(`Count ${params.count} not supported for cyclic ${params.grouping}`); + errors.push(`Count ${params.count} not supported for cyclic ${params.units}`); } return { errors: errors, params: params }; } function serialCheckParams(params) { const errors = []; - if (!VALID_SERIAL_GROUPINGS.includes(params.grouping)) { - errors.push(`Invalid grouping "${params.grouping}"`); + if (!VALID_SERIAL_UNITS.includes(params.units)) { + errors.push(`Invalid grouping units "${params.units}"`); } return { errors: errors, params: Object.assign({}, params, { starting: epochWithDefaults(params.starting) }) }; } function isoCheckParams(params) { const errors = []; - if (!VALID_ISO_GROUPINGS.includes(params.grouping)) { - errors.push(`Invalid grouping "${params.grouping}"`); + if (!VALID_ISO_UNITS.includes(params.units)) { + errors.push(`Invalid units "${params.units}"`); } if (params.starting) { errors.push("Parameter 'starting' not supported for ISO format"); @@ -242,13 +242,13 @@ const CLASSIFIERS = { } }; -function isCyclic(groupBy) { - return VALID_CYCLIC_GROUPINGS.includes(groupBy); +function isCyclic(units) { + return VALID_CYCLIC_UNITS.includes(units); } function classifierFor(params) { let classifier = 'serial'; - if (params.grouping && isCyclic(params.grouping)) { + if (params.units && isCyclic(params.units)) { classifier = 'cyclic'; } else if (params.format === 'iso') { classifier = 'iso';