<commit_before>function strip_ending_slash(str) {
    if(str.substr(-1) == '/') {
        return str.substr(0, str.length - 1);
    }
    return str;
}

// return a list of urls from the requested parameters
// why N urls? because sometimes urls would become too long (with many targets)
// it's up to the caller to deal with this.
function build_graphite_url(options, raw) {
    raw = raw || false;
    var limit = 2000;  // http://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers
    var url = options.graphite_url + "?";
    var url_target = '';  // will contain the part of a url with target args
    var target_parts = []; // will contain one or more of the above, depending on limit

    internal_options = ['_t'];
    graphite_options = ['target', 'targets', 'from', 'until', 'rawData', 'format'];
    graphite_png_options = ['areaMode', 'width', 'height', 'template', 'margin', 'bgcolor',
                         'fgcolor', 'fontName', 'fontSize', 'fontBold', 'fontItalic',
                         'yMin', 'yMax', 'colorList', 'title', 'vtitle', 'lineMode',
                         'lineWith', 'hideLegend', 'hideAxes', 'hideGrid', 'minXstep',
                         'majorGridlineColor', 'minorGridLineColor', 'minorY',
                         'thickness', 'min', 'max', 'tz'];

    // use random parameter to force image refresh
    options["_t"] = options["_t"] || Math.random();

    $.each(options, function (key, value) {
        if(raw) {
            if ($.inArray(key, graphite_options) == -1) {
                return;
            }
        } else {
            if ($.inArray(key, graphite_options) == -1 && $.inArray(key, graphite_png_options) == -1) {
                return;
            }
        }
        if (key === "targets") {
            $.each(value, function (index, value) {
                    if (raw) {
                        // it's normally pointless to use alias() in raw mode, because we apply an alias (name) ourself
                        // in the client rendering step.  we just need graphite to return the target.
                        // but graphite sometimes alters the name of the target in the returned data
                        // (https://github.com/graphite-project/graphite-web/issues/248)
                        // so we need a good string identifier and set it using alias() (which graphite will honor)
                        // so that we recognize the returned output. simplest is just to include the target spec again
                        // though this duplicates a lot of info in the url.
                        new_part = "&target=alias(" + encodeURIComponent(value.target) + ",'" + value.target +"')";
                    } else {
                        new_part = "&target=alias(color(" +encodeURIComponent(value.target + ",'" + value.color) +"'),'" + value.name +"')";
                    }
                    // note that this doesn't account for non-target args that will get added to url later, but this is good enough.
                    if (url.length + url_target.length + new_part.length > limit) {
                        target_parts.push(url_target);
                        url_target = "";
                    }
                    url_target += new_part;
            });
        } else if (value !== null) {
            // key can be 'target' here, so the 'targets' option doesn't have to be set (see above)
            // so url_target can remain empty sometimes, which is fine. though using 'targets' is
            // probably the better way.
            url += "&" + key + "=" + encodeURIComponent(value);
        }
    });
    target_parts.push(url_target);
    return $.map(target_parts, function(target_part) {
        if(raw) {
            target_part += '&format=json';
        }
        return (url + target_part).replace(/\?&/, "?");
    });
};

function build_anthracite_url(options) {
    return strip_ending_slash(options.anthracite_url) + '/jsonp';
}
<commit_msg>update anthracite events jsonp url<commit_after>function strip_ending_slash(str) {
    if(str.substr(-1) == '/') {
        return str.substr(0, str.length - 1);
    }
    return str;
}

// return a list of urls from the requested parameters
// why N urls? because sometimes urls would become too long (with many targets)
// it's up to the caller to deal with this.
function build_graphite_url(options, raw) {
    raw = raw || false;
    var limit = 2000;  // http://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers
    var url = options.graphite_url + "?";
    var url_target = '';  // will contain the part of a url with target args
    var target_parts = []; // will contain one or more of the above, depending on limit

    internal_options = ['_t'];
    graphite_options = ['target', 'targets', 'from', 'until', 'rawData', 'format'];
    graphite_png_options = ['areaMode', 'width', 'height', 'template', 'margin', 'bgcolor',
                         'fgcolor', 'fontName', 'fontSize', 'fontBold', 'fontItalic',
                         'yMin', 'yMax', 'colorList', 'title', 'vtitle', 'lineMode',
                         'lineWith', 'hideLegend', 'hideAxes', 'hideGrid', 'minXstep',
                         'majorGridlineColor', 'minorGridLineColor', 'minorY',
                         'thickness', 'min', 'max', 'tz'];

    // use random parameter to force image refresh
    options["_t"] = options["_t"] || Math.random();

    $.each(options, function (key, value) {
        if(raw) {
            if ($.inArray(key, graphite_options) == -1) {
                return;
            }
        } else {
            if ($.inArray(key, graphite_options) == -1 && $.inArray(key, graphite_png_options) == -1) {
                return;
            }
        }
        if (key === "targets") {
            $.each(value, function (index, value) {
                    if (raw) {
                        // it's normally pointless to use alias() in raw mode, because we apply an alias (name) ourself
                        // in the client rendering step.  we just need graphite to return the target.
                        // but graphite sometimes alters the name of the target in the returned data
                        // (https://github.com/graphite-project/graphite-web/issues/248)
                        // so we need a good string identifier and set it using alias() (which graphite will honor)
                        // so that we recognize the returned output. simplest is just to include the target spec again
                        // though this duplicates a lot of info in the url.
                        new_part = "&target=alias(" + encodeURIComponent(value.target) + ",'" + value.target +"')";
                    } else {
                        new_part = "&target=alias(color(" +encodeURIComponent(value.target + ",'" + value.color) +"'),'" + value.name +"')";
                    }
                    // note that this doesn't account for non-target args that will get added to url later, but this is good enough.
                    if (url.length + url_target.length + new_part.length > limit) {
                        target_parts.push(url_target);
                        url_target = "";
                    }
                    url_target += new_part;
            });
        } else if (value !== null) {
            // key can be 'target' here, so the 'targets' option doesn't have to be set (see above)
            // so url_target can remain empty sometimes, which is fine. though using 'targets' is
            // probably the better way.
            url += "&" + key + "=" + encodeURIComponent(value);
        }
    });
    target_parts.push(url_target);
    return $.map(target_parts, function(target_part) {
        if(raw) {
            target_part += '&format=json';
        }
        return (url + target_part).replace(/\?&/, "?");
    });
};

function build_anthracite_url(options) {
    url = strip_ending_slash(options.anthracite_url) + '/events/jsonp';
    if ('events_query' in options) {
        url += '?q=' + options['events_query'];
    }
    return url;
}

{'fraction_non_alphanumeric': 0.1296205630354957, 'fraction_numerical': 0.004651162790697674, 'mean_word_length': 1.8791402396053558, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '2051428', 'n_tokens_mistral': 2318, 'n_tokens_neox': 2199, 'n_words': 681}