<commit_before>/*
 * Copyright (c) 2010 <NAME>
 * Distributed under the MIT/X11 software license, see the accompanying
 * file license.txt or http://www.opensource.org/licenses/mit-license.php.
 */

/* settings:
 * {
 *  generateConfirm: 120
 * }
 */
function TXList(list, app, settings) {
	this.transactions;
	this.nTXshown;

	this.sortTX = function(a, b) {
		if(a.time != b.time)
			return (a.time - b.time);

		if(a.category != b.category)
			return (b.category < a.category) ? -1 : 1;

		return (b.amount - a.amount);
	}

	this.countVisibleTX = function() {
		return list.children('tr:not(.txinfo)').size();
	}

	this.countTX = function() {
		return this.transactions.length;
	}

	/* call with relative number (e.g. +10 / -10) */
	this.showMore = function(n) {
		var x = this.nTXshown;
		this.nTXshown = Math.max(10, x + n);

		if (this.nTXshown != x)
			this.refresh();

		return this.nTXshown;
	}

	this.clear = function() {
		this.nTXshown = 10;
		list.children().remove();
	}

	this.processRPC = function(transactions, error) {
		if (error)
			return;

		var start = new Date().getTime();

		this.transactions = jQuery.grep(transactions, function(n, i) {
					return n.account == app.bitcoin.settings.account;
				});

		var end = new Date().getTime();
		var time = end - start;

		console.log("TXList: process took " + time + " ms (" + this.transactions.length + " TX)");

		this.renderList();
	}

	this.renderList = function() {
		var timestamp = new Date().getTime();

		list.children('#txlistempty').remove();

		if (this.transactions.length == 0)
			list.append('<tr id="txlistempty"><td colspan="4" class="center">no transactions</td></tr>');

		/* list comprehension is slooow... do it manually */
		var TXcount = 0;
		for (var key in this.transactions) {
			var tx = this.transactions[key];
			var txrow = this.getRow(tx);
			this.updateTX(txrow, tx, timestamp);
			TXcount++;
			if (TXcount >= this.nTXshown)
				break;
		}

		list.children().not('[update="' + timestamp + '"]').remove();

		list.children('tr:not(.txinfo):odd').addClass('odd').next('.txinfo').addClass('odd');
		list.children('tr:not(.txinfo):even').removeClass('odd').next('.txinfo').removeClass('odd');

		var time = new Date().getTime() - timestamp;

		console.log("TXList: render took " + time + " ms (" + TXcount + " TX)");
		console.log(this.countVisibleTX());
	}

	this.getTXid = function(tx) {
		var id;

		if (tx.txid == undefined)
			id = (tx.time + tx.amount + tx.otheraccount).replace(/ /g,'');
		else
			id = tx.txid;

		id += tx.category;

		return id;
	}

	this.getRow = function(tx) {
		var txid = this.getTXid(tx);

		var txrow = $(document.getElementById(txid));

		if (txrow.length == 0) {
			txrow = $('<tr id="' + txid + '"></tr>');
			list.prepend(txrow);
			var txdiv = $('<tr colspan="4" class="txinfo"><td colspan="4"><div style="display: none"></div></td></tr>');
			txrow.after(txdiv);

			txrow.click( function() {
					var div = $(this).next('tr.txinfo').children('td').children('div');
					if (app.useSlide()) div.slideToggle('fast');
					else div.toggle();
				});
		}

		return txrow;
	}

	this.updateTX = function(txrow, tx, timestamp) {<commit_msg>insert new TX at correct position<commit_after>/*
 * Copyright (c) 2010 <NAME>
 * Distributed under the MIT/X11 software license, see the accompanying
 * file license.txt or http://www.opensource.org/licenses/mit-license.php.
 */

/* settings:
 * {
 *  generateConfirm: 120
 * }
 */
function TXList(list, app, settings) {
	this.transactions;
	this.nTXshown;

	this.nTXmin = 10;

	this.sortTX = function(a, b) {
		if(a.time != b.time)
			return (a.time - b.time);

		if(a.category != b.category)
			return (b.category < a.category) ? -1 : 1;

		return (b.amount - a.amount);
	}

	this.countVisibleTX = function() {
		return list.children('tr:not(.txinfo)').size();
	}

	this.countTX = function() {
		return this.transactions.length;
	}

	/* call with relative number (e.g. +10 / -10) */
	this.showMore = function(n) {
		var x = this.nTXshown;
		this.nTXshown = Math.max(this.nTXmin, x + n);

		if (this.nTXshown != x)
			this.refresh();

		return this.nTXshown;
	}

	this.clear = function() {
		this.nTXshown = this.nTXmin;
		list.children().remove();
	}

	this.processRPC = function(transactions, error) {
		if (error)
			return;

		var start = new Date().getTime();

		this.transactions = jQuery.grep(transactions, function(n, i) {
					return n.account == app.bitcoin.settings.account;
				}).reverse();

		var end = new Date().getTime();
		var time = end - start;

		console.log("TXList: process took " + time + " ms (" + this.transactions.length + " TX)");

		this.renderList();
	}

	this.renderList = function() {
		var timestamp = new Date().getTime();

		list.children('#txlistempty').remove();

		if (this.transactions.length == 0)
			list.append('<tr id="txlistempty"><td colspan="4" class="center">no transactions</td></tr>');

		var youngest = list.children('tr:not(.txinfo)').last().attr('time');

		/* list comprehension is slooow... do it manually */
		var TXcount = 0;
		for (var key in this.transactions) {
			var tx = this.transactions[key];
			var where;

			if (tx.time <= youngest) {
				where = false;
				youngest = tx.time;
			} else {
				where = list.children('tr:not(.txinfo)').filter( function(index) {
							return $(this).attr('time') < tx.time;
						}).first();
			}

			var txrow = this.getRow(tx, where);
			this.updateTX(txrow, tx, timestamp);
			TXcount++;
			if (TXcount >= this.nTXshown)
				break;
		}

		list.children().not('[update="' + timestamp + '"]').remove();

		list.children('tr:not(.txinfo):odd').addClass('odd').next('.txinfo').addClass('odd');
		list.children('tr:not(.txinfo):even').removeClass('odd').next('.txinfo').removeClass('odd');

		var time = new Date().getTime() - timestamp;

		console.log("TXList: render took " + time + " ms (" + TXcount + " TX)");
		console.log(this.countVisibleTX());
	}

	this.getTXid = function(tx) {
		var id;

		if (tx.txid == undefined)
			id = (tx.time + tx.amount + tx.otheraccount).replace(/ /g,'');
		else
			id = tx.txid;

		id += tx.category;

		return id;
	}

	this.getRow = function(tx, where) {
		var txid = this.getTXid(tx);

		var txrow = $(document.getElementById(txid));

		if (txrow.length == 0) {
			txrow = $('<tr id="' + txid + '"></tr>');
			var txdiv = $('<tr colspan="4" class="txinfo"><td colspan="4"><div style="display: none"></div></td></tr>');

			if (!where || where.length == 0)
				list.append(txrow);
			else 
				where.before(txrow);

			txrow.after(txdiv);

			txrow.click( function() {
					var div = $(this).next('tr.txinfo').children('td').children('div');
					if (app.useSlide()) div.slideToggle('fast');
					else div.toggle();
				});

		}

		return txrow;
	}

	this.updateTX = function(txrow, tx, timestamp) {
{'fraction_non_alphanumeric': 0.1939465177784308, 'fraction_numerical': 0.007199529826623568, 'mean_word_length': 3.377491961414791, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 31, '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': '4835864', 'n_tokens_mistral': 2746, 'n_tokens_neox': 2371, 'n_words': 508}