<commit_before>$(document).ready(function() {
	load();
	/*
	var credits = $("#credits");
	var creditnames = $("#creditnames");
	create_block(credits, "Me", 35, false);
	create_block(credits, "Ivan", 25, false);
	create_block(credits, "Justin", 15, false);
	create_block(credits, "Sean", 10, false);
	create_block(credits, "Others", 15, false);
	
	create_label(creditnames, "Me", 35, false);
	create_label(creditnames, "Ivan", 25, false);
	create_label(creditnames, "Justin", 15, false);
	create_label(creditnames, "Sean", 10, false);
	create_label(creditnames, "Others", 15, false);
	
	var usage = $("#usage");
	var usagenames = $("#usagenames");
	create_block(usage, "Justin", 3, true);
	create_block(usage, "Kate", 5, true);
	create_block(usage, "Man", 8, true);
	create_block(usage, "Me", 21, true);
	create_block(usage, "Kevin", 14, true);
	create_block(usage, "Others", 14, true);
	create_block(usage, "Free", 35, true);
	create_label(usagenames, "Justin", 3, true);
	create_label(usagenames, "Kate", 5, true);
	create_label(usagenames, "Man", 8, true);
	create_label(usagenames, "Me", 21, true);
	create_label(usagenames, "Kevin", 14, true);
	create_label(usagenames, "Others", 14, true);
	create_label(usagenames, "Free", 35, true);
	*/
	

	

});


/*
	Create a block with given width and background color,
	and append it to the given bar element.
*/
function create_block(bar, username, width, isClosable) {
	var block = $(document.createElement('td'));
	block.css({
		'width': width + '%',
		'background-color': '#' + color_generator(username)
	});
	var percent = $(document.createElement('span'));
	percent.text(width + '%');

	if (isClosable) {
		block.attr("id", "usage" + username);
		if (username == "Free") {
			var get = $(document.createElement('a'));
			get.attr('id','getresourcesbutton');
			get.attr('href','#');
			get.text('get');
			get.click(get_resources_dialog);
			block.append(get);
			
			var share = $(document.createElement('a'));
			share.attr('id','shareresourcesbutton');
			share.attr('href','#');
			share.text('share');
			share.click(share_resources_dialog);
			block.append(share);
			
		} else if (username != "Me" && username != "Others" ) {
			var close = $(document.createElement('a'));
			close.attr('href','#');
			close.text('x');
			close.click(function() {
				$.post("http://192.168.127.12:8081/geni_dev_sean/control/ajax_editshare",
						{ username: username, percent: width },
						function (data) {
							var json = eval('(' + data + ')');
							if (json.success) {
								edit_block(username, 0);
							} else {
								alert(json.error);
							}
						});
			});
			block.append(close);
			percent.click(change_percent);
		}
	}
	
	if (username == "Others") {
		percent.click(function () { show_table(isClosable) });
	}
	
	block.append(percent);
	bar.append(block);
}


/*
	Change the block's width both in terms of its label and
	actual width. Resize free block to	fit the width of the bar.
	Remove the block from the usage bar if width is 0
	Called by save_percent or close on the block
*/
function edit_block(username, width) {
	if (username != "Free") {
		var block = $("#usage" + username);
		var label = $("#labelusage" + username);
		var old_percent = parseInt($("#usage" + username + " span").text());
		var free_percent = parseInt($("#usageFree span").text());
		var new_free_percent = free_percent + old_percent - width;
		if (new_free_percent >= 0) {
			if (width == 0) {
				block.remove();
				label.remove();
			} else {
				$("#usage" + username + " span").text(width + '%');
				block.css("width", width + '%');
				label.css("width", width + '%');
			}
			$("#usageFree span").text(new_free_percent + '%');
			$("#usageFree").css("width", new_free_percent + '%');
			$("#labelusageFree").css("width", new_free_percent + '%');
		}
	}
}


/*
	Create a name label with given width and append it to
	the given name table.
*/
function create_label(names, username, width, isClosable) {
	var label = $(document.createElement('td'));
	if (isClosable) {
		label.attr("id", "labelusage" + username);
	}
	label.text(username);
	label.css({
		'width': width + '%'
	});
	names.append(label);
}

/*
	Display the change percent dialog box
*/
function change_percent() {
	var dialog = $(document.createElement("div"));
	dialog.attr("id", "changepercentdialog");
	dialog.html('<h3>Change Percent</h3>');
	var input = $(document.createElement("input"));
	input.attr("name", $(this).parent().attr("id"));
	input.attr("type", "text");
	input.val(parseInt($(this).text()));
	input.click(function () { $(this).val("") });
	var symbol = $(document.createElement("span"));
	symbol.html(" %<br />");
	var cancel = $(document.createElement("button"));
	cancel.text("Cancel");
	var save = $(document.createElement("button"));
	save.text("Save");
	cancel.click(function () {
		close_dialog();
		$(this).parent().remove();
	});
	save.click(save_percent);
	dialog.append(input);
	dialog.append(symbol);
	dialog.append(cancel);
	dialog.append(save);
	$("#dialogframe").append(dialog);
	$("#dialogframe").fadeIn("fast");
	$("#overlay").fadeIn("fast");
	$("#changepercentdialog").fadeIn("fast");
}

/*
	Save the percent of the the block when click "save" on the
	change_percent dialog box
*/
function save_percent() {
	var input = $("#changepercentdialog input");
	var percent = input.val();
	var username = input.attr("name").substring(5);
	$.post("http://192.168.127.12:8081/geni_dev_sean/control/ajax_editshare",
			{ username: username, percent: percent },
			function (data) {
				var json = eval(data);
				if (json.success) {
					$("#changepercentdialog").remove();
					$("#dialogframe").hide();
					$("#overlay").hide();
					edit_block(username, percent);
				} else {
					create_warning(json.error, $("#changepercentdialog h3"));
					/*
					var warning = $(document.createElement("span"));
					warning.text(json.error);
					warning.addClass("warning");
					$("#changepercentdialog").css("height", "160px");
					warning.insertBefore($("#changepercentdialog").children("input"));
					*/
				}
	   		},
			"json");
}


/*
	Toggle display the tables for small percent users
*/
function show_table(isClosable) {
	if (isClosable) {
		$("#usageothers").toggle();
	} else {
		$("#creditothers").toggle();
	}
}


function get_resources_dialog() {
	$("#dialogframe").fadeIn("fast");
	$("#overlay").fadeIn("fast");
	$("#getresourcesdialog").fadeIn("fast");
	$(".cancel").click(close_dialog);
	$("#getresourcesaction").click(get_resources);
}


function share_resources_dialog() {
	$("#dialogframe").fadeIn("fast");
	$("#overlay").fadeIn("fast");
	$("#shareresourcesdialog").fadeIn("fast");
	$(".cancel").click(close_dialog);
	$("#shareresources").click(share_resources);
}

function close_dialog() {
    if ($(this).parent().children(".warning")) {
		$(this).parent().children(".warning").remove();
    }
	$(this).parent().hide();
	$("#dialogframe").hide();
	$("#overlay").hide();
}


function share_resources() {
	var username = $("#shareresourcesdialog #username").val();
	var percent = parseInt($("#shareresourcesdialog #percent").val());
	if ($("#shareresourcesdialog .warning")) {
	    $("#shareresourcesdialog .warning").remove();
	}

	if (percent > 0) {
		$.post("http://192.168.127.12:8081/geni_dev_sean/control/ajax_createshare",
				{ username: username, percent: percent },
				function (data) {
					var json = eval('(' + data + ')');
					if (json.success) {
						$("#shareresourcesdialog").hide();
						$("#dialogframe").hide();
						$("#overlay").hide();
						create_block($("#usage"), username, percent, true);
						create_label($("#usagenames"), username, percent, true);
					} else {
						create_warning(json.error, $("#shareresourcesdialog h3"));
					}
				});
	} else {
		create_warning("Percent must greater than 0", $("#shareresourcesdialog h3"));
	}
}


function get_resources() {
	var numvessels = parseInt($("#numvessels").val());
	var env = $("#environment").val();
	if ($("#getresourcesdialog .warning")) {
	    $("#getresourcesdialog .warning").remove();
	}
	$.post("http://192.168.127.12:8081/geni_dev_sean/control/ajax_getvessels",
			{ numvessels: numvessels, env: env },
			function (data) {
				var json = eval('(' + data + ')');
				if (json.success) {
					$("#getresourcesdialog").hide();
					$("#dialogframe").hide();
					$("#overlay").hide();
					create_block($("#usage"), "Me", parseInt(json.mypercent), true);
					create_label($("#usagenames"), "Me", parseInt(json.mypercent), true);
				} else {
					create_warning(json.error, $("#getresourcesdialog h3"));
				}
			});
}



function create_warning(error, position) {
	var warning = $(document.createElement("p"));
	warning.text(error);
	warning.addClass("warning");<commit_msg>test if get vessels succeeds<commit_after>$(document).ready(function() {
	load();
	/*
	var credits = $("#credits");
	var creditnames = $("#creditnames");
	create_block(credits, "Me", 35, false);
	create_block(credits, "Ivan", 25, false);
	create_block(credits, "Justin", 15, false);
	create_block(credits, "Sean", 10, false);
	create_block(credits, "Others", 15, false);
	
	create_label(creditnames, "Me", 35, false);
	create_label(creditnames, "Ivan", 25, false);
	create_label(creditnames, "Justin", 15, false);
	create_label(creditnames, "Sean", 10, false);
	create_label(creditnames, "Others", 15, false);
	
	var usage = $("#usage");
	var usagenames = $("#usagenames");
	create_block(usage, "Justin", 3, true);
	create_block(usage, "Kate", 5, true);
	create_block(usage, "Man", 8, true);
	create_block(usage, "Me", 21, true);
	create_block(usage, "Kevin", 14, true);
	create_block(usage, "Others", 14, true);
	create_block(usage, "Free", 35, true);
	create_label(usagenames, "Justin", 3, true);
	create_label(usagenames, "Kate", 5, true);
	create_label(usagenames, "Man", 8, true);
	create_label(usagenames, "Me", 21, true);
	create_label(usagenames, "Kevin", 14, true);
	create_label(usagenames, "Others", 14, true);
	create_label(usagenames, "Free", 35, true);
	*/
	

	

});


/*
	Create a block with given width and background color,
	and append it to the given bar element.
*/
function create_block(bar, username, width, isClosable) {
	var block = $(document.createElement('td'));
	block.css({
		'width': width + '%',
		'background-color': '#' + color_generator(username)
	});
	var percent = $(document.createElement('span'));
	percent.text(width + '%');

	if (isClosable) {
		block.attr("id", "usage" + username);
		if (username == "Free") {
			var get = $(document.createElement('a'));
			get.attr('id','getresourcesbutton');
			get.attr('href','#');
			get.text('get');
			get.click(get_resources_dialog);
			block.append(get);
			
			var share = $(document.createElement('a'));
			share.attr('id','shareresourcesbutton');
			share.attr('href','#');
			share.text('share');
			share.click(share_resources_dialog);
			block.append(share);
			
		} else if (username != "Me" && username != "Others" ) {
			var close = $(document.createElement('a'));
			close.attr('href','#');
			close.text('x');
			close.click(function() {
				$.post("http://192.168.127.12:8081/geni_dev_sean/control/ajax_editshare",
						{ username: username, percent: width },
						function (data) {
							var json = eval('(' + data + ')');
							if (json.success) {
								edit_block(username, 0);
							} else {
								alert(json.error);
							}
						});
			});
			block.append(close);
			percent.click(change_percent);
		}
	}
	
	if (username == "Others") {
		percent.click(function () { show_table(isClosable) });
	}
	
	block.append(percent);
	bar.append(block);
}


/*
	Change the block's width both in terms of its label and
	actual width. Resize free block to	fit the width of the bar.
	Remove the block from the usage bar if width is 0
	Called by save_percent or close on the block
*/
function edit_block(username, width) {
	if (username != "Free") {
		var block = $("#usage" + username);
		var label = $("#labelusage" + username);
		var old_percent = parseInt($("#usage" + username + " span").text());
		var free_percent = parseInt($("#usageFree span").text());
		var new_free_percent = free_percent + old_percent - width;
		if (new_free_percent >= 0) {
			if (width == 0) {
				block.remove();
				label.remove();
			} else {
				$("#usage" + username + " span").text(width + '%');
				block.css("width", width + '%');
				label.css("width", width + '%');
			}
			$("#usageFree span").text(new_free_percent + '%');
			$("#usageFree").css("width", new_free_percent + '%');
			$("#labelusageFree").css("width", new_free_percent + '%');
		}
	}
}


/*
	Create a name label with given width and append it to
	the given name table.
*/
function create_label(names, username, width, isClosable) {
	var label = $(document.createElement('td'));
	if (isClosable) {
		label.attr("id", "labelusage" + username);
	}
	label.text(username);
	label.css({
		'width': width + '%'
	});
	names.append(label);
}

/*
	Display the change percent dialog box
*/
function change_percent() {
	var dialog = $(document.createElement("div"));
	dialog.attr("id", "changepercentdialog");
	dialog.html('<h3>Change Percent</h3>');
	var input = $(document.createElement("input"));
	input.attr("name", $(this).parent().attr("id"));
	input.attr("type", "text");
	input.val(parseInt($(this).text()));
	input.click(function () { $(this).val("") });
	var symbol = $(document.createElement("span"));
	symbol.html(" %<br />");
	var cancel = $(document.createElement("button"));
	cancel.text("Cancel");
	var save = $(document.createElement("button"));
	save.text("Save");
	cancel.click(function () {
		close_dialog();
		$(this).parent().remove();
	});
	save.click(save_percent);
	dialog.append(input);
	dialog.append(symbol);
	dialog.append(cancel);
	dialog.append(save);
	$("#dialogframe").append(dialog);
	$("#dialogframe").fadeIn("fast");
	$("#overlay").fadeIn("fast");
	$("#changepercentdialog").fadeIn("fast");
}

/*
	Save the percent of the the block when click "save" on the
	change_percent dialog box
*/
function save_percent() {
	var input = $("#changepercentdialog input");
	var percent = input.val();
	var username = input.attr("name").substring(5);
	$.post("http://192.168.127.12:8081/geni_dev_sean/control/ajax_editshare",
			{ username: username, percent: percent },
			function (data) {
				var json = eval(data);
				if (json.success) {
					$("#changepercentdialog").remove();
					$("#dialogframe").hide();
					$("#overlay").hide();
					edit_block(username, percent);
				} else {
					create_warning(json.error, $("#changepercentdialog h3"));
					/*
					var warning = $(document.createElement("span"));
					warning.text(json.error);
					warning.addClass("warning");
					$("#changepercentdialog").css("height", "160px");
					warning.insertBefore($("#changepercentdialog").children("input"));
					*/
				}
	   		},
			"json");
}


/*
	Toggle display the tables for small percent users
*/
function show_table(isClosable) {
	if (isClosable) {
		$("#usageothers").toggle();
	} else {
		$("#creditothers").toggle();
	}
}


function get_resources_dialog() {
	$("#dialogframe").fadeIn("fast");
	$("#overlay").fadeIn("fast");
	$("#getresourcesdialog").fadeIn("fast");
	$(".cancel").click(close_dialog);
	$("#getresourcesaction").click(get_resources);
}


function share_resources_dialog() {
	$("#dialogframe").fadeIn("fast");
	$("#overlay").fadeIn("fast");
	$("#shareresourcesdialog").fadeIn("fast");
	$(".cancel").click(close_dialog);
	$("#shareresources").click(share_resources);
}

function close_dialog() {
    if ($(this).parent().children(".warning")) {
		$(this).parent().children(".warning").remove();
    }
	$(this).parent().hide();
	$("#dialogframe").hide();
	$("#overlay").hide();
}


function share_resources() {
	var username = $("#shareresourcesdialog #username").val();
	var percent = parseInt($("#shareresourcesdialog #percent").val());
	if ($("#shareresourcesdialog .warning")) {
	    $("#shareresourcesdialog .warning").remove();
	}

	if (percent > 0) {
		$.post("http://192.168.127.12:8081/geni_dev_sean/control/ajax_createshare",
				{ username: username, percent: percent },
				function (data) {
					var json = eval('(' + data + ')');
					if (json.success) {
						$("#shareresourcesdialog").hide();
						$("#dialogframe").hide();
						$("#overlay").hide();
						create_block($("#usage"), username, percent, true);
						create_label($("#usagenames"), username, percent, true);
					} else {
						create_warning(json.error, $("#shareresourcesdialog h3"));
					}
				});
	} else {
		create_warning("Percent must greater than 0", $("#shareresourcesdialog h3"));
	}
}


function get_resources() {
	var numvessels = parseInt($("#numvessels").val());
	var env = $("#environment").val();
	if ($("#getresourcesdialog .warning")) {
	    $("#getresourcesdialog .warning").remove();
	}
	$.post("http://192.168.127.12:8081/geni_dev_sean/control/ajax_getvessels",
			{ numvessels: numvessels, env: env },
			function (data) {
				var json = eval('(' + data + ')');
				alert(json.mypercent);
				if (json.success) {
					$("#getresourcesdialog").hide();
					$("#dialogframe").hide();
					$("#overlay").hide();
					create_block($("#usage"), "Me", parseInt(json.mypercent), true);
					create_label($("#usagenames"), "Me", parseInt(json.mypercent), true);
				} else {
					create_warning(json.error, $("#getresourcesdialog h3"));
				}
			});
}



function create_warning(error, position) {
	var warning = $(document.createElement("p"));
	warning.text(error);
	warning.addClass("warning");
{'fraction_non_alphanumeric': 0.20687293069985158, 'fraction_numerical': 0.013471857517981505, 'mean_word_length': 4.500470957613815, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 8, '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': '3930763', 'n_tokens_mistral': 6542, 'n_tokens_neox': 5677, 'n_words': 1160}