<commit_before>var qzi = {};
function markExam () {
    console.log("markExam()");
    var adminID = getParameterByName('admin');
    var classID = getParameterByName('classid');
    var quizNumber = getParameterByName('quizno');
    // Call server and get an object with the correct answers
    var result = apiRequest(
        '/?admin='
            + adminID
            + '&page=quiz'
            + '&cmd=getcorrectanswers'
        , {
            classid:classID,
            quizno:quizNumber
        });
    if (false === result) return;
    qzi.correctAnswers = result.correctAnswers;
    qzi.studentNames = result.studentNames;
    qzi.serverResults = result.serverResults;
    qzi.numberOfStudents = result.numberOfStudents;
    qzi.numberOfQuestions = result.numberOfQuestions;
    qzi.clientResult = {};
    qzi.currentStudentID = false;
    setDisplayMode('marking');
    clearMarksheet();
    var inputNode = document.getElementById('string-input');
    inputNode.setAttribute('onkeypress','keystrokeHandler(event);');
    inputNode.focus();
};

function keystrokeHandler(event) {
    if (event.key === 'Enter') {
        var inputVal = '';
        var inputNode = document.getElementById('string-input');
        var inputVal = inputNode.value;
        if (inputVal.length === 10) {
            setAnswer(inputVal);
        } else {
            alert("Input overlap, try again.");
        }
        inputNode.value = '';
    }
};

function setAnswer(inputVal) {
    var ans = {};
    inputVal = inputVal.replace(/^0*/,'');
    var studentOffset = parseInt(inputVal.slice(0,1),10);
    var questionOffset = parseInt(inputVal.slice(1,2),10);
    ans.studentID = inputVal.slice(2,2+studentOffset);
    ans.questionNumber = inputVal.slice(2+studentOffset,2+studentOffset+questionOffset);
    ans.choice = inputVal.slice(2+studentOffset+questionOffset,2+studentOffset+questionOffset+1);
    checkAlreadyDone(ans);
};

function checkAlreadyDone(ans) {
    console.log("checkAlreadyDone()");
    clearError();
    // Is this student already done?
    if (qzi.serverResults[ans.studentID]) {<commit_msg>Attempt to fix bad-input glitches<commit_after>var qzi = {};
function markExam () {
    console.log("markExam()");
    var adminID = getParameterByName('admin');
    var classID = getParameterByName('classid');
    var quizNumber = getParameterByName('quizno');
    // Call server and get an object with the correct answers
    var result = apiRequest(
        '/?admin='
            + adminID
            + '&page=quiz'
            + '&cmd=getcorrectanswers'
        , {
            classid:classID,
            quizno:quizNumber
        });
    if (false === result) return;
    qzi.correctAnswers = result.correctAnswers;
    qzi.studentNames = result.studentNames;
    qzi.serverResults = result.serverResults;
    qzi.numberOfStudents = result.numberOfStudents;
    qzi.numberOfQuestions = result.numberOfQuestions;
    qzi.clientResult = {};
    qzi.currentStudentID = false;
    setDisplayMode('marking');
    clearMarksheet();
    var inputNode = document.getElementById('string-input');
    inputNode.setAttribute('onkeypress','keystrokeHandler(event);');
    inputNode.focus();
};

function keystrokeHandler(event) {
    if (event.key === 'Enter') {
        var inputVal = '';
        var inputNode = document.getElementById('string-input');
	function setvalue() {
            var inputVal = inputNode.value;
            if (inputVal.length === 10) {
		setAnswer(inputVal);
            } else {
		alert("Bad input (" + inputVal + "), try again.");
		return false;
            }
            inputNode.value = '';
	    return true;
	}
	setTimeout(function(){
	    if (!setvalue()){
		setTimeout(setvalue, 1000);;
	    }
	}, 20);
    }
};

function setAnswer(inputVal) {
    var ans = {};
    inputVal = inputVal.replace(/^0*/,'');
    var studentOffset = parseInt(inputVal.slice(0,1),10);
    var questionOffset = parseInt(inputVal.slice(1,2),10);
    ans.studentID = inputVal.slice(2,2+studentOffset);
    ans.questionNumber = inputVal.slice(2+studentOffset,2+studentOffset+questionOffset);
    ans.choice = inputVal.slice(2+studentOffset+questionOffset,2+studentOffset+questionOffset+1);
    checkAlreadyDone(ans);
};

function checkAlreadyDone(ans) {
    console.log("checkAlreadyDone()");
    clearError();
    // Is this student already done?
    if (qzi.serverResults[ans.studentID]) {
{'fraction_non_alphanumeric': 0.13585847130868678, 'fraction_numerical': 0.009525969607620775, 'mean_word_length': 3.152542372881356, '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': '2683261', 'n_tokens_mistral': 1346, 'n_tokens_neox': 1307, 'n_words': 237}