diff --git a/lib/cartodb/backends/turbo-carto-postgres-datasource.js b/lib/cartodb/backends/turbo-carto-postgres-datasource.js index 9db42b05..79e718ea 100644 --- a/lib/cartodb/backends/turbo-carto-postgres-datasource.js +++ b/lib/cartodb/backends/turbo-carto-postgres-datasource.js @@ -77,11 +77,14 @@ PostgresDatasource.prototype.getRamp = function (column, buckets, method, callba return callback(err); } - resultSet = resultSet || {}; - var result = resultSet.rows || []; - + var result = getResult(resultSet); var strategy = method2strategy[methodName]; - var ramp = result[0][methodName] || []; + var ramp = result[methodName] || []; + var stats = { + min_val: result.min_val, + max_val: result.max_val, + avg_val: result.avg_val + }; // Skip null values from ramp // Generated turbo-carto won't be correct, but better to keep it working than failing // TODO fix cartodb-postgres extension quantification functions @@ -92,8 +95,16 @@ PostgresDatasource.prototype.getRamp = function (column, buckets, method, callba }); } - return callback(null, { ramp: ramp, strategy: strategy }); + return callback(null, { ramp: ramp, strategy: strategy, stats: stats }); }, true); // use read-only transaction }; +function getResult(resultSet) { + resultSet = resultSet || {}; + var result = resultSet.rows || []; + result = result[0] || {}; + + return result; +} + module.exports = PostgresDatasource;