<commit_before>// JavaScript Document
function searchInstructors() {
	 var pname = document.getElementById("pname").value;
	 var disc = document.getElementById("disc").value;
	 var $results = $("#results");
	 if(pname || disc) {
		var button = disableButton(document.getElementById("search"));
		$results.html("Searching...");
		var jsonData = getUBCIDs(pname, disc);
		if(jsonData.length==0) $results.html("Your search returned 0 results!");
		else {
			var resultTable = buildResultTable(jsonData);
			$results.html("");
			$results.append(resultTable).append(buildVisualizeButton());
		}
		enableButton(button);
	 } else $results.html("You must enter a name or discipline to search!");
}

function buildResultTable(data) {
	var resultTable = document.createElement("table");
	var tableHeader = resultTable.createTHead();
	var headerRow = tableHeader.insertRow(0);
	var showHead = headerRow.insertCell(0);
	var nameHead = headerRow.insertCell(1);
	var discHead = headerRow.insertCell(2);
	var idHead = headerRow.insertCell(3);
	
	var forceHead = headerRow.insertCell(4);
	nameHead.innerHTML = "Name";
	discHead.innerHTML = "Subject";
	idHead.innerHTML = "UBCID";
	showHead.innerHTML = "Show";
	forceHead.innerHTML = "Force Update";
	
	resultTable.setAttribute("id", "resultTable");
	resultTableBody = document.createElement("tbody");
	resultTable.appendChild(resultTableBody);
	
	$.each(data, function(element) {
		var newRow = resultTableBody.insertRow(-1);
		var viewSchedule = newRow.insertCell(0);
		var profName = newRow.insertCell(1);
		profName.innerHTML = element.name;
		var profDisc = newRow.insertCell(2);
		profDisc.innerHTML = element.disc;
		var ubcid = newRow.insertCell(3);
		ubcid.innerHTML = element.ubcid;
		var viewBox = document.createElement("input");
		viewBox.setAttribute("type", "checkbox");
		viewBox.setAttribute("value", value);
		viewSchedule.appendChild(viewBox);
		var update = newRow.insertCell(4);
		var forceUpdate = document.createElement("input");
		forceUpdate.setAttribute("type", "checkbox");
		forceUpdate.setAttribute("value", value);
		update.appendChild(forceUpdate);
	});
	return resultTable;
}

function buildVisualizeButton() {
	var visualizeButton = document.createElement("input");
	visualizeButton.setAttribute("type", "button");
	visualizeButton.setAttribute("onclick", "viewSchedule()");
	visualizeButton.setAttribute("value", "Visualize");
	return visualizeButton;	
}

function getUBCIDs(pname, disc) {
	var json = null;
	$.ajax("/31317092/project/getUBCID.php", {
		async:false,
		global:false,
		data: {pname:pname, disc:disc},
		dataType:"json",
		success: function(data) {<commit_msg>.each requires (key, value) parameters<commit_after>// JavaScript Document
function searchInstructors() {
	 var pname = document.getElementById("pname").value;
	 var disc = document.getElementById("disc").value;
	 var $results = $("#results");
	 if(pname || disc) {
		var button = disableButton(document.getElementById("search"));
		$results.html("Searching...");
		var jsonData = getUBCIDs(pname, disc);
		if(jsonData.length==0) $results.html("Your search returned 0 results!");
		else {
			var resultTable = buildResultTable(jsonData);
			$results.html("");
			$results.append(resultTable).append(buildVisualizeButton());
		}
		enableButton(button);
	 } else $results.html("You must enter a name or discipline to search!");
}

function buildResultTable(data) {
	var resultTable = document.createElement("table");
	var tableHeader = resultTable.createTHead();
	var headerRow = tableHeader.insertRow(0);
	var showHead = headerRow.insertCell(0);
	var nameHead = headerRow.insertCell(1);
	var discHead = headerRow.insertCell(2);
	var idHead = headerRow.insertCell(3);
	
	var forceHead = headerRow.insertCell(4);
	nameHead.innerHTML = "Name";
	discHead.innerHTML = "Subject";
	idHead.innerHTML = "UBCID";
	showHead.innerHTML = "Show";
	forceHead.innerHTML = "Force Update";
	
	resultTable.setAttribute("id", "resultTable");
	resultTableBody = document.createElement("tbody");
	resultTable.appendChild(resultTableBody);
	
	$.each(data, function(key, element) {
		var newRow = resultTableBody.insertRow(-1);
		var viewSchedule = newRow.insertCell(0);
		var profName = newRow.insertCell(1);
		profName.innerHTML = element.name;
		var profDisc = newRow.insertCell(2);
		profDisc.innerHTML = element.disc;
		var ubcid = newRow.insertCell(3);
		ubcid.innerHTML = element.ubcid;
		var viewBox = document.createElement("input");
		viewBox.setAttribute("type", "checkbox");
		viewBox.setAttribute("value", element.ubcid);
		viewSchedule.appendChild(viewBox);
		var update = newRow.insertCell(4);
		var forceUpdate = document.createElement("input");
		forceUpdate.setAttribute("type", "checkbox");
		forceUpdate.setAttribute("value", element.ubcid);
		update.appendChild(forceUpdate);
	});
	return resultTable;
}

function buildVisualizeButton() {
	var visualizeButton = document.createElement("input");
	visualizeButton.setAttribute("type", "button");
	visualizeButton.setAttribute("onclick", "viewSchedule()");
	visualizeButton.setAttribute("value", "Visualize");
	return visualizeButton;	
}

function getUBCIDs(pname, disc) {
	var json = null;
	$.ajax("/31317092/project/getUBCID.php", {
		async:false,
		global:false,
		data: {pname:pname, disc:disc},
		dataType:"json",
		success: function(data) {
{'fraction_non_alphanumeric': 0.1464741185296324, 'fraction_numerical': 0.008252063015753939, 'mean_word_length': 5.82842509603073, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1701984', 'n_tokens_mistral': 1724, 'n_tokens_neox': 1621, 'n_words': 327}