<commit_before>/**
 * Created by barrera on 19/01/2017.
 */
"use strict";

var foundationExperimentsPageModule = (function ($) {

    function replaceZeroAndLinkExpDesign(data, full) {
        if (data === 0) {
            return '<span title="' + data + '"/>';
        }
        return '<span title="' + data + '">' +
            '<a href="experiments/' + full.experimentAccession + '/experiment-design" title="View experiment design in Expression Atlas">' + data +
            '</a></span>';
    }

    function withLineBreaks(data) {
        var i, html;
        html = '';
        for (i = 0; i < data.length; i += 1) {
            html += data[i] + '<br/>';
        }
        return html;
    }

    function formatExperimentType(data, contextPath) {
        if (data === 'RNASEQ_MRNA_BASELINE' || data === 'PROTEOMICS_BASELINE') {
            return '<img src= "' + contextPath + '/resources/images/allup2_transparent_bkg.png" alt="baseline"/>';
        }
        if (data === 'RNASEQ_MRNA_DIFFERENTIAL' || data === 'MICROARRAY_ANY') {
            return '<img src="' + contextPath + '/resources/images/updown_transparent_bkg.png" alt="differential"/>';
        }
        return data;
    }

    function formatExperimentAccession(data) {
        return '<a href="http://www.ebi.ac.uk/arrayexpress/experiments/' + data + '" title="View in Array Express">' +
            '<span class="icon icon-generic" data-icon="L"></span>' + '</a>';
    }

    function formatLastUpdate(data) {
        return data;
    }

    function formatExperimentDescription(data, full) {
        return '<a href="experiments/' + full.experimentAccession + '" title="View in Expression Atlas">' + data + '</a>';
    }

    function formatArrayDesign(data, full) {
        var result = "";
        $(data).each(function (index, elem) {
            result = result + '<a href="http://www.ebi.ac.uk/arrayexpress/arrays/' + elem + '" title="View in Array Express">' + full.arrayDesignNames[index] + '</a><br/>';
        });

        return result;
    }

    var asInitVals = [];

    function _init(experimentType, kingdom, organism, experimentSet, contextPath) {

        /* Sort on the 'alt' tags of images in a column */
        $.extend($.fn.dataTableExt.oSort, {
            "alt-string-pre": function ( a ) {
                return a.match(/alt="(.*?)"/)[1].toLowerCase();
            },

            "alt-string-asc": function( a, b ) {
                return ((a < b) ? -1 : ((a > b) ? 1 : 0));
            },

            "alt-string-desc": function(a,b) {
                return ((a < b) ? 1 : ((a > b) ? -1 : 0));
            }
        } );

        /* This was taken from datatables examples
         * This sorting function pair will use the * 'title' attribute of en empty span element (or anything else)
         * to sort numerically (for example `<span title="1000000"><span>1'000'000`) */
        $.extend($.fn.dataTableExt.oSort, {
            "title-numeric-pre":function (a) {
                var x = a.match(/title="*(-?[0-9\.]+)/)[1];
                return parseFloat(x);
            },

            "title-numeric-asc":function (a, b) {
                return ((a < b) ? -1 : ((a > b) ? 1 : 0));
            },

            "title-numeric-desc":function (a, b) {
                return ((a < b) ? 1 : ((a > b) ? -1 : 0));
            }
        });

        /* Sorting by date */
        $.extend($.fn.dataTableExt.oSort, {
            "date-eu-pre": function ( date ) {
                date = date.replace(" ", "");

                /*date a, format dd/mn/(yyyy) ; (year is optional)*/
                var eu_date = date.split('-');

                /*year (optional)*/
                var year = eu_date[2] ? eu_date[2] : 0;

                /*month*/
                var month = eu_date[1];
                if (month.length === 1) {
                    month = 0 + month;
                }

                /*day*/
                var day = eu_date[0];
                if (day.length === 1) {
                    day = 0 + day;
                }

                return (year + month + day) * 1;
            },

            "date-eu-asc": function ( a, b ) {
                return ((a < b) ? -1 : ((a > b) ? 1 : 0));
            },

            "date-eu-desc": function ( a, b ) {
                return ((a < b) ? 1 : ((a > b) ? -1 : 0));
            }
        } );

        var $experimentsTable = $("#experiments-table");
        //reset empty data message to avoid showing "Showing 0 to 0 of 0 entries"
        $experimentsTable.dataTable.defaults.oLanguage.sInfoEmpty = ' ';

        var oTable = $experimentsTable.DataTable({
            "autoWidth": false,
            "processing": true,
            "ajax": contextPath + "/json/experiments",
            "columns":[
                { "title":"Type", "data":"experimentType", "className":"center", "type":"alt-string", "width": "7%",
                    "render": function (data, type, full) {
                        return formatExperimentType(data, contextPath);
                    } },
                { "title":"Loaded", "data":"lastUpdate", "className":"center nowrap", 'type': 'date-eu', "width": "6%",
                    "render": function (data, type, full) {
                        return formatLastUpdate(data);
                    } },
                { "title":"Experiment", "data":"experimentDescription", "className":"center",
                    "render": function (data, type, full) {
                        return formatExperimentDescription(data, full);
                    } },
                { "title":"Assays", "data":"numberOfAssays", "className":"center", "type":"title-numeric", "width":"5%",
                    "render": function (data, type, full) {
                        return replaceZeroAndLinkExpDesign(data, type, full);
                    } },<commit_msg>Fix bug (#17)<commit_after>/**
 * Created by barrera on 19/01/2017.
 */
"use strict";

var foundationExperimentsPageModule = (function ($) {

    function replaceZeroAndLinkExpDesign(data, full) {
        if (data === 0) {
            return '<span title="' + data + '"/>';
        }
        return '<span title="' + data + '">' +
            '<a href="experiments/' + full.experimentAccession + '/experiment-design" title="View experiment design in Expression Atlas">' + data +
            '</a></span>';
    }

    function withLineBreaks(data) {
        var i, html;
        html = '';
        for (i = 0; i < data.length; i += 1) {
            html += data[i] + '<br/>';
        }
        return html;
    }

    function formatExperimentType(data, contextPath) {
        if (data === 'RNASEQ_MRNA_BASELINE' || data === 'PROTEOMICS_BASELINE') {
            return '<img src= "' + contextPath + '/resources/images/allup2_transparent_bkg.png" alt="baseline"/>';
        }
        if (data === 'RNASEQ_MRNA_DIFFERENTIAL' || data === 'MICROARRAY_ANY') {
            return '<img src="' + contextPath + '/resources/images/updown_transparent_bkg.png" alt="differential"/>';
        }
        return data;
    }

    function formatExperimentAccession(data) {
        return '<a href="http://www.ebi.ac.uk/arrayexpress/experiments/' + data + '" title="View in Array Express">' +
            '<span class="icon icon-generic" data-icon="L"></span>' + '</a>';
    }

    function formatLastUpdate(data) {
        return data;
    }

    function formatExperimentDescription(data, full) {
        return '<a href="experiments/' + full.experimentAccession + '" title="View in Expression Atlas">' + data + '</a>';
    }

    function formatArrayDesign(data, full) {
        var result = "";
        $(data).each(function (index, elem) {
            result = result + '<a href="http://www.ebi.ac.uk/arrayexpress/arrays/' + elem + '" title="View in Array Express">' + full.arrayDesignNames[index] + '</a><br/>';
        });

        return result;
    }

    var asInitVals = [];

    function _init(experimentType, kingdom, organism, experimentSet, contextPath) {

        /* Sort on the 'alt' tags of images in a column */
        $.extend($.fn.dataTableExt.oSort, {
            "alt-string-pre": function ( a ) {
                return a.match(/alt="(.*?)"/)[1].toLowerCase();
            },

            "alt-string-asc": function( a, b ) {
                return ((a < b) ? -1 : ((a > b) ? 1 : 0));
            },

            "alt-string-desc": function(a,b) {
                return ((a < b) ? 1 : ((a > b) ? -1 : 0));
            }
        } );

        /* This was taken from datatables examples
         * This sorting function pair will use the * 'title' attribute of en empty span element (or anything else)
         * to sort numerically (for example `<span title="1000000"><span>1'000'000`) */
        $.extend($.fn.dataTableExt.oSort, {
            "title-numeric-pre":function (a) {
                var x = a.match(/title="*(-?[0-9\.]+)/)[1];
                return parseFloat(x);
            },

            "title-numeric-asc":function (a, b) {
                return ((a < b) ? -1 : ((a > b) ? 1 : 0));
            },

            "title-numeric-desc":function (a, b) {
                return ((a < b) ? 1 : ((a > b) ? -1 : 0));
            }
        });

        /* Sorting by date */
        $.extend($.fn.dataTableExt.oSort, {
            "date-eu-pre": function ( date ) {
                date = date.replace(" ", "");

                /*date a, format dd/mn/(yyyy) ; (year is optional)*/
                var eu_date = date.split('-');

                /*year (optional)*/
                var year = eu_date[2] ? eu_date[2] : 0;

                /*month*/
                var month = eu_date[1];
                if (month.length === 1) {
                    month = 0 + month;
                }

                /*day*/
                var day = eu_date[0];
                if (day.length === 1) {
                    day = 0 + day;
                }

                return (year + month + day) * 1;
            },

            "date-eu-asc": function ( a, b ) {
                return ((a < b) ? -1 : ((a > b) ? 1 : 0));
            },

            "date-eu-desc": function ( a, b ) {
                return ((a < b) ? 1 : ((a > b) ? -1 : 0));
            }
        } );

        var $experimentsTable = $("#experiments-table");
        //reset empty data message to avoid showing "Showing 0 to 0 of 0 entries"
        $experimentsTable.dataTable.defaults.oLanguage.sInfoEmpty = ' ';

        var oTable = $experimentsTable.DataTable({
            "autoWidth": false,
            "processing": true,
            "ajax": contextPath + "/json/experiments",
            "columns":[
                { "title":"Type", "data":"experimentType", "className":"center", "type":"alt-string", "width": "7%",
                    "render": function (data, type, full) {
                        return formatExperimentType(data, contextPath);
                    } },
                { "title":"Loaded", "data":"lastUpdate", "className":"center nowrap", 'type': 'date-eu', "width": "6%",
                    "render": function (data, type, full) {
                        return formatLastUpdate(data);
                    } },
                { "title":"Experiment", "data":"experimentDescription", "className":"center",
                    "render": function (data, type, full) {
                        return formatExperimentDescription(data, full);
                    } },
                { "title":"Assays", "data":"numberOfAssays", "className":"center", "type":"title-numeric", "width":"5%",
                    "render": function (data, type, full) {
                        return replaceZeroAndLinkExpDesign(data, full);
                    } },
{'fraction_non_alphanumeric': 0.16609764424718335, 'fraction_numerical': 0.01109593717992489, 'mean_word_length': 1.660535876475931, 'pattern_counts': {'":': 68, '<': 55, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '139015', 'n_tokens_mistral': 3529, 'n_tokens_neox': 3289, 'n_words': 799}