<commit_before>/*jslint browser: true, devel: true, sloppy: true*/
/*global google, $*/

// Window constants
var wps_url = "http://ceda-wps2.badc.rl.ac.uk:8080/submit/form?proc_id=PlotTimeSeries&FilePath=";
var track_colours = ["#4D4D4D", "#5DA5DA", "#FAA43A",
                     "#60BD68", "#F17CB0", "#B2912F",
                     "#B276B2", "#DECF3F", "#F15854"];

// -----------------------------String.hashCode--------------------------------
String.prototype.hashCode = function () {
    // Please see: http://bit.ly/1dSyf18 for original
    var i, c, hash;

    hash = 0;
    if (this.length === 0) {
        return hash;
    }

    for (i = 0; i < this.length; i++) {
        c = this.charCodeAt(i);
        hash = ((hash << 5) - hash) + c;
    }

    return hash;
};

String.prototype.truncatePath = function (levels) {
    // Removes 'levels' directories from a path, e.g.:
    // "/usr/bin/path/to/something/useful".truncatePath(3);
    //     => "/usr/bin/path
    parts = this.split("/");
    t_path = parts.slice(0, parts.length - levels).join("/");
    return t_path;
}

// ------------------------------Variable Filter-------------------------------
function clear_aggregated_variables() {
    select = $("#multiselect").html("");
    select.multiSelect("refresh");
}

function display_aggregated_variables(aggregations) {
    var select, i, buckets;

    select = $("#multiselect");
    buckets = aggregations.variables.buckets;
    for (i = 0; i < buckets.length; i += 1) {
        select.multiSelect("addOption", {
            value: buckets[i].key,
            text: (buckets[i].key + " (" + buckets[i].doc_count + ")")
        });
    }
}

function request_from_multiselect() {
    var i, vars, req;
    req = [];
    vars = $("#multiselect").val();

    if (vars) {
        for (i = 0; i < vars.length; i += 1) {
            req.push({
                term: {
                    _all: vars[i]
                }
            });
        }
        return req;
    } else {
        return "";
    }
}

// ---------------------------"Export Results" Modal---------------------------
function update_export_results_modal(hits) {
    $("#results").html(JSON.stringify(hits, null, "    "));
}

// -------------------------------ElasticSearch--------------------------------
var es_url = "http://fatcat-test.jc.rl.ac.uk:9200/badc/eufar/_search";
function request_from_filters(full_text) {
    var i, req, vars;

    req = [];
    if (full_text.length > 0) {
        ft = full_text.split(" ");
        for (i = 0; i < ft.length; i += 1) {
            req.push({
                term: {
                    _all: ft[i]
                }
            });
        }
        return req;
    }
}

function create_elasticsearch_request(gmaps_corners, full_text, size) {
    var i, tmp_ne, tmp_sw, nw, se, request, tf, vars;

    tmp_ne = gmaps_corners.getNorthEast();
    tmp_sw = gmaps_corners.getSouthWest();
    nw = [tmp_sw.lng().toString(), tmp_ne.lat().toString()];
    se = [tmp_ne.lng().toString(), tmp_sw.lat().toString()];

    // ElasticSearch request
    request = {
        "_source": {<commit_msg>Update Elasticsearch URL<commit_after>/*jslint browser: true, devel: true, sloppy: true*/
/*global google, $*/

// Window constants
var wps_url = "http://ceda-wps2.badc.rl.ac.uk:8080/submit/form?proc_id=PlotTimeSeries&FilePath=";
var track_colours = ["#4D4D4D", "#5DA5DA", "#FAA43A",
                     "#60BD68", "#F17CB0", "#B2912F",
                     "#B276B2", "#DECF3F", "#F15854"];

// -----------------------------String.hashCode--------------------------------
String.prototype.hashCode = function () {
    // Please see: http://bit.ly/1dSyf18 for original
    var i, c, hash;

    hash = 0;
    if (this.length === 0) {
        return hash;
    }

    for (i = 0; i < this.length; i++) {
        c = this.charCodeAt(i);
        hash = ((hash << 5) - hash) + c;
    }

    return hash;
};

String.prototype.truncatePath = function (levels) {
    // Removes 'levels' directories from a path, e.g.:
    // "/usr/bin/path/to/something/useful".truncatePath(3);
    //     => "/usr/bin/path
    parts = this.split("/");
    t_path = parts.slice(0, parts.length - levels).join("/");
    return t_path;
}

// ------------------------------Variable Filter-------------------------------
function clear_aggregated_variables() {
    select = $("#multiselect").html("");
    select.multiSelect("refresh");
}

function display_aggregated_variables(aggregations) {
    var select, i, buckets;

    select = $("#multiselect");
    buckets = aggregations.variables.buckets;
    for (i = 0; i < buckets.length; i += 1) {
        select.multiSelect("addOption", {
            value: buckets[i].key,
            text: (buckets[i].key + " (" + buckets[i].doc_count + ")")
        });
    }
}

function request_from_multiselect() {
    var i, vars, req;
    req = [];
    vars = $("#multiselect").val();

    if (vars) {
        for (i = 0; i < vars.length; i += 1) {
            req.push({
                term: {
                    _all: vars[i]
                }
            });
        }
        return req;
    } else {
        return "";
    }
}

// ---------------------------"Export Results" Modal---------------------------
function update_export_results_modal(hits) {
    $("#results").html(JSON.stringify(hits, null, "    "));
}

// -------------------------------ElasticSearch--------------------------------
var es_url = "http://fatcat-test.jc.rl.ac.uk/es/badc/eufar/_search";
function request_from_filters(full_text) {
    var i, req, vars;

    req = [];
    if (full_text.length > 0) {
        ft = full_text.split(" ");
        for (i = 0; i < ft.length; i += 1) {
            req.push({
                term: {
                    _all: ft[i]
                }
            });
        }
        return req;
    }
}

function create_elasticsearch_request(gmaps_corners, full_text, size) {
    var i, tmp_ne, tmp_sw, nw, se, request, tf, vars;

    tmp_ne = gmaps_corners.getNorthEast();
    tmp_sw = gmaps_corners.getSouthWest();
    nw = [tmp_sw.lng().toString(), tmp_ne.lat().toString()];
    se = [tmp_ne.lng().toString(), tmp_sw.lat().toString()];

    // ElasticSearch request
    request = {
        "_source": {
{'fraction_non_alphanumeric': 0.23523763802208353, 'fraction_numerical': 0.01632261161785886, 'mean_word_length': 1.703287197231834, 'pattern_counts': {'":': 2, '<': 15, '<?xml version=': 0, '>': 7, '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': '3334494', 'n_tokens_mistral': 2111, 'n_tokens_neox': 1985, 'n_words': 398}