<commit_before>/* Osmium
 * Copyright (C) 2014 Romain "Artefact2" Dalmaso <<EMAIL>>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/*<<< require snippet tabs >>>*/
/*<<< require snippet perfectscrollbar >>>*/

$(function() {
	var tabs = $("ul.tabs");
	if(tabs.length > 0) {
		for(var i = 0; i < tabs.length; ++i) {
			osmium_tabify($(tabs[i]), 0);
		}
	}

	var csec = $("div#dbb.compare > section.compare");
	if(csec.length > 0) {
		csec.perfectScrollbar({
			suppressScrollY: true,
			wheelPropagation: true, /* <- Doesn't work as advertised? */
		});
		csec.off('mousewheel'); /* XXX: Hackish */

		/* Table sorting */
		var round_sd = function(n, d) {
			if(!n) return n;
			var m = d - Math.floor(Math.log(Math.abs(n)) / Math.log(10)) - 1;
			return n.toFixed(Math.max(0, m));
		};

		var asclambda = function(columnindex) {
			return function(trA, trB) {
				return $(trA).children().eq(columnindex).data('rawval')
					- $(trB).children().eq(columnindex).data('rawval');
			};
		};
		var desclambda = function(columnindex) {
			return function(trA, trB) {
				return $(trB).children().eq(columnindex).data('rawval')
					- $(trA).children().eq(columnindex).data('rawval');
			};
		};
		var unsortlambda = function(trA, trB) {
			return $(trA).data('idx') - $(trB).data('idx');
		};

		var ctable = csec.children('table.d');
		var tbody = ctable.children('tbody');
		ctable
			.children('thead')
			.children('tr')
			.children('th')
			.on('click', function() {
				var th = $(this);
				var asc = th.hasClass('asc');
				var desc = th.hasClass('desc');

				ctable.children('colgroup').removeClass('sorted');
				th.parent().children('th').removeClass('asc desc');

				if(!asc && !desc) {
					th.addClass('asc');
					ctable.children('colgroup').eq(th.index()).addClass('sorted');
					tbody.children('tr').sort(asclambda(th.index())).appendTo(tbody);
				} else if(asc) {
					th.addClass('desc');
					ctable.children('colgroup').eq(th.index()).addClass('sorted');
					tbody.children('tr').sort(desclambda(th.index())).appendTo(tbody);
				} else if(desc) {
					ctable.children('colgroup').eq(th.index()).removeClass('sorted');
					tbody.children('tr').sort(unsortlambda).appendTo(tbody);
				}
			})
		;

		tbody
			.children('tr')
			.children('th:first-child')
			.on('click', function() {
				var tr = $(this).parent();
				var wasbase = tr.hasClass('base');

				tbody.find('small.basecmp').remove();
				tbody.children('tr').removeClass('base')
					.children('td').removeClass('gain loss');
				if(wasbase) return;

				tr.addClass('base');
				tbody.children('tr').each(function() {
					var other = $(this);
					if(other.index() === tr.index()) return;

					other.children('td').each(function() {
						var td = $(this);
						var baseval = tr.children().eq(td.index()).data('rawval');
						if(!baseval) return;

						var otherval = td.data('rawval');
						var delta = 100 * (otherval - baseval) / baseval;
						if(!delta) return;

						td.append(
							$(document.createElement('small'))
								.addClass('basecmp')
								.append(document.createElement('br'))
								.append(document.createTextNode(delta >= 0 ? '+' : '-'))
								.append(document.createTextNode(round_sd(Math.abs(delta), 2) + " %"))
						);

						var highisgood = ctable.children('thead')
							.children('tr').children()
							.eq(td.index()).data('hig');
						var gain = delta >= 0;
						if(highisgood) {
							td.addClass(gain ? 'gain' : 'loss');
						} else {
							td.addClass(gain ? 'loss' : 'gain');
						}
					});
				});
			})
		;
	}

	var typelist = $("div#dbb ul.typelist");<commit_msg>Fix: correctly identify gain/losses in dbbrowser for negative attributes.<commit_after>/* Osmium
 * Copyright (C) 2014 Romain "Artefact2" Dalmaso <<EMAIL>>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/*<<< require snippet tabs >>>*/
/*<<< require snippet perfectscrollbar >>>*/

$(function() {
	var tabs = $("ul.tabs");
	if(tabs.length > 0) {
		for(var i = 0; i < tabs.length; ++i) {
			osmium_tabify($(tabs[i]), 0);
		}
	}

	var csec = $("div#dbb.compare > section.compare");
	if(csec.length > 0) {
		csec.perfectScrollbar({
			suppressScrollY: true,
			wheelPropagation: true, /* <- Doesn't work as advertised? */
		});
		csec.off('mousewheel'); /* XXX: Hackish */

		/* Table sorting */
		var round_sd = function(n, d) {
			if(!n) return n;
			var m = d - Math.floor(Math.log(Math.abs(n)) / Math.log(10)) - 1;
			return n.toFixed(Math.max(0, m));
		};

		var asclambda = function(columnindex) {
			return function(trA, trB) {
				return $(trA).children().eq(columnindex).data('rawval')
					- $(trB).children().eq(columnindex).data('rawval');
			};
		};
		var desclambda = function(columnindex) {
			return function(trA, trB) {
				return $(trB).children().eq(columnindex).data('rawval')
					- $(trA).children().eq(columnindex).data('rawval');
			};
		};
		var unsortlambda = function(trA, trB) {
			return $(trA).data('idx') - $(trB).data('idx');
		};

		var ctable = csec.children('table.d');
		var tbody = ctable.children('tbody');
		ctable
			.children('thead')
			.children('tr')
			.children('th')
			.on('click', function() {
				var th = $(this);
				var asc = th.hasClass('asc');
				var desc = th.hasClass('desc');

				ctable.children('colgroup').removeClass('sorted');
				th.parent().children('th').removeClass('asc desc');

				if(!asc && !desc) {
					th.addClass('asc');
					ctable.children('colgroup').eq(th.index()).addClass('sorted');
					tbody.children('tr').sort(asclambda(th.index())).appendTo(tbody);
				} else if(asc) {
					th.addClass('desc');
					ctable.children('colgroup').eq(th.index()).addClass('sorted');
					tbody.children('tr').sort(desclambda(th.index())).appendTo(tbody);
				} else if(desc) {
					ctable.children('colgroup').eq(th.index()).removeClass('sorted');
					tbody.children('tr').sort(unsortlambda).appendTo(tbody);
				}
			})
		;

		tbody
			.children('tr')
			.children('th:first-child')
			.on('click', function() {
				var tr = $(this).parent();
				var wasbase = tr.hasClass('base');

				tbody.find('small.basecmp').remove();
				tbody.children('tr').removeClass('base')
					.children('td').removeClass('gain loss');
				if(wasbase) return;

				tr.addClass('base');
				tbody.children('tr').each(function() {
					var other = $(this);
					if(other.index() === tr.index()) return;

					other.children('td').each(function() {
						var td = $(this);
						var baseval = tr.children().eq(td.index()).data('rawval');
						if(!baseval) return;

						var otherval = td.data('rawval');
						var delta = 100 * (otherval - baseval) / baseval;
						if(!delta) return;

						td.append(
							$(document.createElement('small'))
								.addClass('basecmp')
								.append(document.createElement('br'))
								.append(document.createTextNode(delta >= 0 ? '+' : '-'))
								.append(document.createTextNode(round_sd(Math.abs(delta), 2) + " %"))
						);

						var highisgood = ctable.children('thead')
							.children('tr').children()
							.eq(td.index()).data('hig');
						var gain = (baseval < otherval);
						if(highisgood) {
							td.addClass(gain ? 'gain' : 'loss');
						} else {
							td.addClass(gain ? 'loss' : 'gain');
						}
					});
				});
			})
		;
	}

	var typelist = $("div#dbb ul.typelist");
{'fraction_non_alphanumeric': 0.1880261927034612, 'fraction_numerical': 0.004560336763330215, 'mean_word_length': 3.244665012406948, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5254761', 'n_tokens_mistral': 3463, 'n_tokens_neox': 2781, 'n_words': 615}