<commit_before>var assert = require('assert');

var _ = require('underscore');
var PSQL = require('cartodb-psql');
var step = require('step');

var RendererParams = require('../renderers/renderer_params');
var Timer = require('../stats/timer');
var BBoxFilter = require('../models/filters/bbox');

function WidgetBackend() {
}

module.exports = WidgetBackend;


WidgetBackend.prototype.getWidget = function (mapConfigProvider, params, callback) {
    var timer = new Timer();

    var layerIndex = params.layer;

    var mapConfig;
    var widget;
    step(
        function getMapConfig() {
            mapConfigProvider.getMapConfig(this);
        },
        function getWidget(err, _mapConfig) {
            assert.ifError(err);

            mapConfig = _mapConfig;

            var widget = mapConfig.getWidget(layerIndex, params.widgetName);
            if (!widget) {
                throw new Error("Widget '" + params.widgetName + "' does not exists");
            }

            return widget;
        },
        function runWidgetQuery(err, _widget) {
            assert.ifError(err);

            widget = _widget;

            var dbParams = RendererParams.dbParamsFromReqParams(params);
            _.extend(dbParams, mapConfig.getLayerDatasource(params.layer));
            var pg = new PSQL(dbParams);

            var ownFilter = +params.own_filter;
            ownFilter = !!ownFilter;

            var filters;
            if (ownFilter) {
                filters = mapConfig.getLayerFilters(layerIndex);
            } else {
                filters = mapConfig.getLayerFilters(layerIndex, params.widgetName);
            }

            if (params.bbox) {
                filters = filters.concat(new BBoxFilter({}, {bbox: params.bbox}));
            }

            var overrideParams = _.reduce(_.pick(params, 'start', 'end', 'bins'), function(overrides, val, k) {
                overrides[k] = +val;
                return overrides;
            }, {ownFilter: ownFilter});

            widget.getResult(pg, filters, overrideParams, this);

        },
        function returnCallback(err, result) {
            return callback(err, result, timer.getTimes());
        }
    );
};
<commit_msg>Cast numbers in override params<commit_after>var assert = require('assert');

var _ = require('underscore');
var PSQL = require('cartodb-psql');
var step = require('step');

var RendererParams = require('../renderers/renderer_params');
var Timer = require('../stats/timer');
var BBoxFilter = require('../models/filters/bbox');

function WidgetBackend() {
}

module.exports = WidgetBackend;


WidgetBackend.prototype.getWidget = function (mapConfigProvider, params, callback) {
    var timer = new Timer();

    var layerIndex = params.layer;

    var mapConfig;
    var widget;
    step(
        function getMapConfig() {
            mapConfigProvider.getMapConfig(this);
        },
        function getWidget(err, _mapConfig) {
            assert.ifError(err);

            mapConfig = _mapConfig;

            var widget = mapConfig.getWidget(layerIndex, params.widgetName);
            if (!widget) {
                throw new Error("Widget '" + params.widgetName + "' does not exists");
            }

            return widget;
        },
        function runWidgetQuery(err, _widget) {
            assert.ifError(err);

            widget = _widget;

            var dbParams = RendererParams.dbParamsFromReqParams(params);
            _.extend(dbParams, mapConfig.getLayerDatasource(params.layer));
            var pg = new PSQL(dbParams);

            var ownFilter = +params.own_filter;
            ownFilter = !!ownFilter;

            var filters;
            if (ownFilter) {
                filters = mapConfig.getLayerFilters(layerIndex);
            } else {
                filters = mapConfig.getLayerFilters(layerIndex, params.widgetName);
            }

            if (params.bbox) {
                filters = filters.concat(new BBoxFilter({}, {bbox: params.bbox}));
            }

            var overrideParams = _.reduce(_.pick(params, 'start', 'end', 'bins', 'column_type'),
                function castNumbers(overrides, val, k) {
                    overrides[k] = Number.isFinite(+val) ? +val : val;
                    return overrides;
                },
                {ownFilter: ownFilter}
            );

            widget.getResult(pg, filters, overrideParams, this);

        },
        function returnCallback(err, result) {
            return callback(err, result, timer.getTimes());
        }
    );
};

{'fraction_non_alphanumeric': 0.11786654960491659, 'fraction_numerical': 0.0, 'mean_word_length': 2.0645595158036314, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5878210', 'n_tokens_mistral': 1241, 'n_tokens_neox': 1205, 'n_words': 264}