<commit_before>/*
 * This handles the functions for the cells
 * */
var ht = $("#"+tableDiv.id).handsontable('getInstance');

var tempCopy;
var offset;

//Redoes the last undone operation
function undo() {
	ht.undo();
}

//Undoes the last operation
function redo() {
	ht.redo();
}

//Handles the sum operation
function sum() {
	var selected = ht.getSelected();
	if(selected != undefined) {
		var sum = 0;
		var cells = ht.getData(selected[0], selected[1], selected[2], selected[3]);
		
		//Adds all selected cells
		for(var i = 0; i < cells.length; i++) {
			for(var y = 0; y < cells[i].length; y++) {
				if(cells[i][y] != null) sum += Number(cells[i][y]);
			}
		}
		
		//Deselect selection
		ht.deselectCell();
		
		//Inserts sum in cell if it's below the original selection
		$("#" + tableDiv.id).on('click', function() {
			var clicked = ht.getSelected();
			if(selected[2] < clicked[0]) {
				var string = "=SUM(" + funcStrCreator(selected) + ")"
				funcTracker[funcTracker.length] = new cellFunction(clicked[0], clicked[1], string);
				ht.setDataAtCell(clicked[0], clicked[1], sum, true);
				$(this).off('click');
			}
		});
	}
}

//Handles the average operation
function average() {
	var selected = ht.getSelected();
	if (selected != undefined) {
	var cells = ht.getData(selected[0], selected[1], selected[2], selected[3]);
		var sum = 0;
		var count = 0;
		//Adds all selected cells
		for(var i = 0; i < cells.length; i++) {
			for(var y = 0; y < cells[i].length; y++) {
				if(cells[i][y] != null) {
					sum += Number(cells[i][y]);
					if (cells[i][y].length > 0) count++;
				}
			}
		}
		
		//Deselect selection
		ht.deselectCell();
		
		//Inserts average in cell if it's below the original selection
		$("#" + tableDiv.id).on('click', function() {
			var clicked = ht.getSelected();
			if(selected[2] < clicked[0]) {
				var string = "=AVG(" + funcStrCreator(selected) + ")"
				funcTracker[funcTracker.length] = new cellFunction(clicked[0], clicked[1], string);
				ht.setDataAtCell(clicked[0], clicked[1], sum/count, true);
				$(this).off('click');
			}
		});
	}
}

//Handles the cut operation
function cut() {
	if (ht.getSelected() != undefined) {
		var selected = topLeft(ht.getSelected());
		tempCopy = ht.getData(selected[0], selected[1], selected[2], selected[3]);
		var allZero = emptyArray(selected[0], selected[1], selected[2], selected[3]);
		ht.populateFromArray(selected[0],selected[1], allZero, selected[2], selected[3]);
		/**<commit_msg>Fixed old average/sum button methods to be consistent with current sum/average function strings.<commit_after>/*
 * This handles the functions for the cells
 * */
var ht = $("#"+tableDiv.id).handsontable('getInstance');

var tempCopy;
var offset;

//Redoes the last undone operation
function undo() {
	ht.undo();
}

//Undoes the last operation
function redo() {
	ht.redo();
}

//Handles the sum operation
function sum() {
	var selected = ht.getSelected();
	if(selected != undefined) {
		var sum = 0;
		var cells = ht.getData(selected[0], selected[1], selected[2], selected[3]);
		
		//Adds all selected cells
		for(var i = 0; i < cells.length; i++) {
			for(var y = 0; y < cells[i].length; y++) {
				if(cells[i][y] != null) sum += Number(cells[i][y]);
			}
		}
		
		//Deselect selection
		ht.deselectCell();
		
		//Inserts sum in cell if it's below the original selection
		$("#" + tableDiv.id).on('click', function() {
			var clicked = ht.getSelected();
			if(selected[2] < clicked[0]) {
				var string = "=SUM(" + funcStrCreator(selected) + ")"
				funcTracker[clicked[0]*ht.countRows()+clicked[1]] = new cellFunction(clicked[0], clicked[1], string);
				ht.setDataAtCell(clicked[0], clicked[1], string, true);
				$(this).off('click');
			}
		});
	}
}

//Handles the average operation
function average() {
	var selected = ht.getSelected();
	if (selected != undefined) {
	var cells = ht.getData(selected[0], selected[1], selected[2], selected[3]);
		var sum = 0;
		var count = 0;
		//Adds all selected cells
		for(var i = 0; i < cells.length; i++) {
			for(var y = 0; y < cells[i].length; y++) {
				if(cells[i][y] != null) {
					sum += Number(cells[i][y]);
					if (cells[i][y].length > 0) count++;
				}
			}
		}
		
		//Deselect selection
		ht.deselectCell();
		
		//Inserts average in cell if it's below the original selection
		$("#" + tableDiv.id).on('click', function() {
			var clicked = ht.getSelected();
			if(selected[2] < clicked[0]) {
				var string = "=AVG(" + funcStrCreator(selected) + ")"
				funcTracker[clicked[0]*ht.countRows()+clicked[1]] = new cellFunction(clicked[0], clicked[1], string);
				console.log(string);
				ht.setDataAtCell(clicked[0], clicked[1], string, true);
				$(this).off('click');
			}
		});
	}
}

//Handles the cut operation
function cut() {
	if (ht.getSelected() != undefined) {
		var selected = topLeft(ht.getSelected());
		tempCopy = ht.getData(selected[0], selected[1], selected[2], selected[3]);
		var allZero = emptyArray(selected[0], selected[1], selected[2], selected[3]);
		ht.populateFromArray(selected[0],selected[1], allZero, selected[2], selected[3]);
		/**
{'fraction_non_alphanumeric': 0.18592767295597484, 'fraction_numerical': 0.01650943396226415, 'mean_word_length': 3.823696682464455, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 5, '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': '3994386', 'n_tokens_mistral': 1983, 'n_tokens_neox': 1754, 'n_words': 439}