<commit_before>function serializeToKibanaUrlFormat(param) {
    var innerValue;

    if (Array.isArray(param)) {
        innerValue = param.map(function (obj) {
            return serializeToKibanaUrlFormat(obj);
        }).join(',');
        return '!(' + innerValue + ')';
    } else if (param instanceof Object) {
        innerValue = Object.keys(param).map(function (fieldName) {
            return fieldName + ':' + serializeToKibanaUrlFormat(param[fieldName]);
        }).join(',');
        return '(' + innerValue + ')';
    } else {
        return param
    }
}

function singleQuotedString(str) {
    return '\'' + str + '\'';
}

function addDaysToDate(date, days) {
    var parsedDate = new Date(Date.parse(date));
    parsedDate.setDate(parsedDate.getDate() + days);
    return parsedDate.toISOString();
}

function Kibana(kibanaUrl) {
    this.kibanaUrl = kibanaUrl;

    this.getIframeUrl = function (username, bounds) {
        var minTime = addDaysToDate(bounds.minTime, -2);
        var maxTime = addDaysToDate(bounds.maxTime, 5);

        var g = {
            refreshInterval: {
                display: 'Off',
                pause: '!f',
                section: 0,
                value: 0
            },
            time: {
                from: singleQuotedString(minTime),
                mode: 'absolute',
                to: singleQuotedString(maxTime)
            }
        };

        var query = {
            query_string: {
                analyze_wildcard: '!t',
                query: singleQuotedString('_type:' + username)
            }
        };

        var aggs = [
            {
                id: 1,
                params: {
                    field: 'value'
                },
                schema: 'metric',
                type: 'avg'
            },
            {
                id: 2,
                params: {
                    customInterval: singleQuotedString('2h'),
                    field: singleQuotedString('@timestamp'),
                    interval: 'd',
                    min_doc_count: 1
                },
                schema: 'segment',
                type: 'date_histogram'
            }
        ];

        var params = {
            addLegend: '!f',
            addTimeMarker: '!f',
            addTooltip: '!t',
            defaultYExtents: '!f',
            drawLinesBetweenPoints: '!t',
            interpolate: 'linear',
            radiusRatio: 9,
            scale: 'linear',
            setYExtents: '!t',
            shareYAxis: '!t',
            showCircles: '!t',
            smoothLines: '!f',
            yAxis: {
                max: bounds.maxWeight + 1,
                min: bounds.minWeight - 1
            }
        };

        var a = {
            linked: '!f',
            query: query,
            vis: {
                aggs: aggs,
                params: params,<commit_msg>Kibana refactor<commit_after>function serializeToKibanaUrlFormat(param) {
    var innerValue;

    if (Array.isArray(param)) {
        innerValue = param.map(function (obj) {
            return serializeToKibanaUrlFormat(obj);
        }).join(',');
        return '!(' + innerValue + ')';
    } else if (param instanceof Object) {
        innerValue = Object.keys(param).map(function (fieldName) {
            return fieldName + ':' + serializeToKibanaUrlFormat(param[fieldName]);
        }).join(',');
        return '(' + innerValue + ')';
    } else if (typeof param === 'boolean') {
        return param ? '!t' : '!f';
    } else if (typeof param === 'string') {
        return '\'' + param + '\'';
    } else {
        return param;
    }
}

function addDaysToDate(date, days) {
    var parsedDate = new Date(Date.parse(date));
    parsedDate.setDate(parsedDate.getDate() + days);
    return parsedDate.toISOString();
}

function Kibana(kibanaUrl) {
    this.kibanaUrl = kibanaUrl;

    this.getIframeUrl = function (username, bounds) {
        var minTime = addDaysToDate(bounds.minTime, -2);
        var maxTime = addDaysToDate(bounds.maxTime, 5);

        var g = {
            refreshInterval: {
                display: 'Off',
                pause: false,
                section: 0,
                value: 0
            },
            time: {
                from: minTime,
                mode: 'absolute',
                to: maxTime
            }
        };

        var query = {
            query_string: {
                analyze_wildcard: true,
                query: '_type:' + username
            }
        };

        var aggs = [
            {
                id: 1,
                params: {
                    field: 'value'
                },
                schema: 'metric',
                type: 'avg'
            },
            {
                id: 2,
                params: {
                    customInterval: '2h',
                    field: '@timestamp',
                    interval: 'd',
                    min_doc_count: 1
                },
                schema: 'segment',
                type: 'date_histogram'
            }
        ];

        var params = {
            addLegend: false,
            addTimeMarker: false,
            addTooltip: true,
            defaultYExtents: false,
            drawLinesBetweenPoints: true,
            interpolate: 'linear',
            radiusRatio: 9,
            scale: 'linear',
            setYExtents: true,
            shareYAxis: true,
            showCircles: true,
            smoothLines: false,
            yAxis: {
                max: bounds.maxWeight + 1,
                min: bounds.minWeight - 1
            }
        };

        var a = {
            linked: false,
            query: query,
            vis: {
                aggs: aggs,
                params: params,
{'fraction_non_alphanumeric': 0.11543810848400557, 'fraction_numerical': 0.0038247566063977748, 'mean_word_length': 1.2411375146084924, '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': '3238073', 'n_tokens_mistral': 1641, 'n_tokens_neox': 1554, 'n_words': 328}