<commit_before>/* global formatDate */
/* global $ */
var block = 0;
var blocks = [];

$(document).on('ready', function() {
	setInterval(function(){
		move_on_down();
	}, 2000);

	var clicked = false;
	$(document).on("click", ".block", function(event){
		clicked = !clicked;
		show_details(Number($(this).html()));
	});

	$(document).on("mouseover", ".block", function(event){
		show_details(Number($(this).html()));
	});
	
	$(document).on("mouseleave", "#blockWrap", function(){
		if(!clicked) $("#details").fadeOut();
	});
});

function show_details(id){
	var left = event.pageX - $('#details').parent().offset().left - 50;
	if(left < 0) left = 0;
	var ccid = formatCCID(blocks[id].blockstats.transactions[0].type, blocks[id].blockstats.transactions[0].uuid, atob(blocks[id].blockstats.transactions[0].chaincodeID));
	var payload = atob(blocks[id].blockstats.transactions[0].payload);

	var html = '<p class="blckLegend"> Block Height: ' + blocks[id].id + '</p>';
	html += '<hr class="line"/><p>Created: &nbsp;' + formatDate(blocks[id].blockstats.transactions[0].timestamp.seconds * 1000, '%M-%d-%Y %I:%m%p') + ' UTC</p>';
	html += '<p> UUID: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + formatUUID(blocks[id].blockstats.transactions[0].type, blocks[id].blockstats.transactions[0].uuid) + '</p>';
	html += '<p> Type:  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + formatType(blocks[id].blockstats.transactions[0].type) + '</p>';
	html += '<p> CC ID:  &nbsp;&nbsp;&nbsp;&nbsp;' + ccid + '</p>';
	html += '<p> Payload:  &nbsp;' + formatPayload(payload, ccid) + '</p>';
	$("#details").html(html).css("left", left).fadeIn();
}

function new_block(newblck){
	if(!blocks[Number(newblck.id)]){
		for(var last in blocks);								//find the id of the last known block
		if(!last) last = 0;
		last++;
		//console.log('last', last, Number(newblck.id));
		if(block > 0){											//never fake blocks on an initial load
			for(var i=last; i < Number(newblck.id); i++){		//build fake blocks for ones we missed out on
				console.log('run?');
				blocks[Number(i)] = newblck;
				build_block(i);
			}
		}
		blocks[Number(newblck.id)] = newblck;
		build_block(newblck.id);								//build block
	}
}

function build_block(id){
	$("#blockWrap").append('<div class="block">' +  nDig(id, 3) + '</div>');
	$(".block:last").animate({opacity: 1, left: (block * 36)}, 600, function(){
		$(".lastblock").removeClass("lastblock");
		$(".block:last").addClass("lastblock");
	});
	block++;
}

function move_on_down(){
	if(block > 10){
		$(".block:first").animate({opacity: 0}, 800, function(){$(".block:first").remove();});
		$(".block").animate({left: "-=36"}, 800, function(){});
		block--;
	}
}

function clear_blocks(){
	block = 0;
	blocks = [];
	$(".block").remove();
}


function formatCCID(i, uuid, ccid){								//flip uuid and ccid if deploy, weird i know<commit_msg>- added comments<commit_after>/* global formatDate */
/* global $ */
var block = 0;
var blocks = [];

$(document).on('ready', function() {
	setInterval(function(){
		move_on_down();
	}, 2000);

	var clicked = false;
	$(document).on("click", ".block", function(event){
		clicked = !clicked;
		show_details(Number($(this).html()));
	});

	$(document).on("mouseover", ".block", function(event){
		show_details(Number($(this).html()));
	});
	
	$(document).on("mouseleave", "#blockWrap", function(){
		if(!clicked) $("#details").fadeOut();
	});
});

function show_details(id){										//build the block details html
	var left = event.pageX - $('#details').parent().offset().left - 50;
	if(left < 0) left = 0;
	var ccid = formatCCID(blocks[id].blockstats.transactions[0].type, blocks[id].blockstats.transactions[0].uuid, atob(blocks[id].blockstats.transactions[0].chaincodeID));
	var payload = atob(blocks[id].blockstats.transactions[0].payload);

	var html = '<p class="blckLegend"> Block Height: ' + blocks[id].id + '</p>';
	html += '<hr class="line"/><p>Created: &nbsp;' + formatDate(blocks[id].blockstats.transactions[0].timestamp.seconds * 1000, '%M-%d-%Y %I:%m%p') + ' UTC</p>';
	html += '<p> UUID: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + formatUUID(blocks[id].blockstats.transactions[0].type, blocks[id].blockstats.transactions[0].uuid) + '</p>';
	html += '<p> Type:  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + formatType(blocks[id].blockstats.transactions[0].type) + '</p>';
	html += '<p> CC ID:  &nbsp;&nbsp;&nbsp;&nbsp;' + ccid + '</p>';
	html += '<p> Payload:  &nbsp;' + formatPayload(payload, ccid) + '</p>';
	$("#details").html(html).css("left", left).fadeIn();
}

function new_block(newblck){									//rec a new block
	if(!blocks[Number(newblck.id)]){
		for(var last in blocks);								//find the id of the last known block
		if(!last) last = 0;
		last++;
		//console.log('last', last, Number(newblck.id));
		if(block > 0){											//never fake blocks on an initial load
			for(var i=last; i < Number(newblck.id); i++){		//build fake blocks for ones we missed out on
				console.log('run?');
				blocks[Number(i)] = newblck;
				build_block(i);
			}
		}
		blocks[Number(newblck.id)] = newblck;
		build_block(newblck.id);								//build block
	}
}

function build_block(id){										//build and append the block html
	$("#blockWrap").append('<div class="block">' +  nDig(id, 3) + '</div>');
	$(".block:last").animate({opacity: 1, left: (block * 36)}, 600, function(){
		$(".lastblock").removeClass("lastblock");
		$(".block:last").addClass("lastblock");
	});
	block++;
}

function move_on_down(){										//move the blocks left
	if(block > 10){
		$(".block:first").animate({opacity: 0}, 800, function(){$(".block:first").remove();});
		$(".block").animate({left: "-=36"}, 800, function(){});
		block--;
	}
}

function clear_blocks(){										//empty blocks
	block = 0;
	blocks = [];
	$(".block").remove();
}


function formatCCID(i, uuid, ccid){								//flip uuid and ccid if deploy, weird i know
{'fraction_non_alphanumeric': 0.234375, 'fraction_numerical': 0.014423076923076924, 'mean_word_length': 4.469483568075117, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, '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': '4975867', 'n_tokens_mistral': 2272, 'n_tokens_neox': 2045, 'n_words': 422}