<commit_before>var depth = 3;
var language
var langExt

var codeArea = document.getElementById('CodeArea');
var score = document.getElementById('score');
codeArea.focus();
var text = "";

//https://api.github.com/search/repositories?q=language:JavaScript&sort=stars


var correct = 0;
var total = 0;
var perplexity = 'Unknown!';
function keypressed(x){
	if (text.length > 0){
		var nextChar = text.slice(0,1);
		text = text.slice(1);
		
		var c;
		if (x.charCode == nextChar.charCodeAt(0)){
			c = 'g';
			correct++;
		} else {
			c = 'r';
		}
		nextChar = (nextChar=='\n')?'\u2936<BR>':nextChar;
		
		var insert = '<span class='+c+'>'+nextChar+'</span>';
		codeArea.innerHTML = codeArea.innerHTML+insert;
		
		total++;
		perplexity = total/correct;
		score.innerHTML = perplexity.toFixed(3);
		
		console.log(x.charCode);
	}
};

function newLanguage(){
	codeArea.innerHTML = 'Loading, please wait...';
	language = document.getElementById("language").value;
	langExt = document.getElementById("extension").value;
	for (k in activeList){
		activeList[k].abort();
	}
	fileList = [];
	getFiles(language, langExt, depth);
	function temp(){
		if (Object.keys(activeList).length > 0 || (fileList.length < 1)){
			window.setTimeout(temp, 500);
		} else {
			//console.log("getting random file");
			getRandFile(function(t){
				text = t;
				codeArea.innerHTML = 'Type Here!<BR>';
			});
		}
	}
	temp();
}
newLanguage();
codeArea.onkeypress = keypressed;<commit_msg>Added DigramTable functionality.<commit_after>var depth = 3;
var language
var langExt

var codeArea = document.getElementById('CodeArea');
var score = document.getElementById('score');
codeArea.focus();
var text = "";

var digramPeekArray = [null, null, null, null, null]
var digramPeekTable = document.getElementById('digram-table');
var digramTable = {}

//https://api.github.com/search/repositories?q=language:JavaScript&sort=stars


var correct = 0;
var total = 0;
var perplexity = 'Unknown!';
function keypressed(x){
	if (text.length > 0){
		var nextChar = text.slice(0,1);
		text = text.slice(1);
		
		var c;
		if (x.charCode == nextChar.charCodeAt(0)){
			c = 'g';
			correct++;
		} else {
			c = 'r';
		}
		nextChar = (nextChar=='\n')?'\u2936<BR>':nextChar;
		
		var insert = '<span class='+c+'>'+nextChar+'</span>';
		codeArea.innerHTML = codeArea.innerHTML+insert;
		
		total++;
		perplexity = total/correct;
		score.innerHTML = perplexity.toFixed(3);
		
	        console.log(x.charCode);
	        digramPeekArray = digramTable[nextChar];
	        update_table();
	}
};

function newLanguage(){
	codeArea.innerHTML = 'Loading, please wait...';
	language = document.getElementById("language").value;
	langExt = document.getElementById("extension").value;
	for (k in activeList){
		activeList[k].abort();
	}
	fileList = [];
	getFiles(language, langExt, depth);
	function temp(){
		if (Object.keys(activeList).length > 0 || (fileList.length < 1)){
			window.setTimeout(temp, 500);
		} else {
			//console.log("getting random file");
			getRandFile(function(t){
				text = t;
				codeArea.innerHTML = 'Type Here!<BR>';
			});
		}
	}
    temp();
    digramTable = populateDigramTable(text, {});
}

function populateDigramTable(text, digram_table) {
    var previous = text.slice(0,1);
    var sum = 0;
    digram_table[previous] = {};
    for (index = 1; index <= text.slice(1).length; index++) {
	var character = text[index];
	if (previous in digram_table) {
	    if (character in digram_table[previous]) {
		digram_table[previous][character] += 1;
	    }
	    else {
		digram_table[previous][character] = 1;
	    }
	}
	else {
	    digram_table[previous] = {};
	    digram_table[previous][character] = 1;
	}
	sum += 1;
	previous = character;
    }
    var sorted_digram_table = {};
    for (item in digram_table) {
	var frequencies = []
	for (item2 in digram_table[item]) {
	    frequencies.push([item2, digram_table[item][item2]]);
	}
	frequencies.sort(compare);
	frequencies.reverse();
	sorted_digram_table[item] = frequencies.slice(0,6);
    }
    return sorted_digram_table;
}

function compare(a, b) {
    if (a[1] < b[1]) return -1;
    if (a[1] > b[1]) return 1;
    return 0;
}
	
	
newLanguage();
codeArea.onkeypress = keypressed;
{'fraction_non_alphanumeric': 0.16726147989531287, 'fraction_numerical': 0.013561741613133477, 'mean_word_length': 3.9400705052878964, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 16, 'https://': 2, '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': '4695248', 'n_tokens_mistral': 1592, 'n_tokens_neox': 1437, 'n_words': 299}