<commit_before>var State = {
    base: "/state/",
    idbase: "state_",
    stateHash: [],
    currentState: [],

    makeHash: function () {
        //makeHash is function that constructs State.stateHash - a hash table with 
        //with (key, pointer) pairs where: 
        //   key = a state variable (e.g. "ExperimentState.pmt_DAC_State[6].voltage")
        //   pointer = a pointer to one HTML element that matches that state variable
        //So, for example, 
        // > stateHash[key] = pointer
        // > stateHash[ExperimentState.pmt_DAC_State[6].voltage] = [object HTMLSpanElement]
        log("Getting state from server.");
        State.stateHash = [];
        deferred = loadJSONDoc(this.base + "webGetState");
        deferred.addCallback(function(result) {
            log("State received.  Creating hash table.");
            var resultkeys = keys(result);
            //log(resultkeys);
            forEach(getElementsByTagAndClassName('span','autoUpdate'),
                function(elem) {                
//                    stateVar = (sp=elem.className.split(' '), sp[0]=="autoUpdate" ? sp[1] : sp[0])
                    stateVar = elem.className.match(/ExperimentState[..a-zA-Z0-9\_\[\]]*/)[0];
                    State.stateHash[stateVar] = elem;
                    }
            )
            log("Finished creating State.stateHash.  It has " + keys(State.stateHash).length + " entries.");
        });
        deferred.addErrback(function (err) {
            log("Error updating state: " + repr(err));
        });
    },

    updateWithHash: function () {
        log("Updating state.");
        if (State.stateHash.length == 0) {
            State.makeHash();
            log("Getting new hash.");
        }
        deferred = loadJSONDoc(this.base + "webGetState");
        deferred.addCallback(function (newState) {
            var hashkeys = keys(State.stateHash);
            forEach(hashkeys, 
                function (hashkey) {
                    if (newState[hashkey] == State.currentState[hashkey]) {
                        //do nothing if there is no change
                    }
                    else {
                        //if there is a change, put the new data in the appropriate elements
                        State.stateHash[hashkey].innerHTML = newState[hashkey];
                        //log("changed " + hashkey);
                    }
                }
            )
            State.currentState = newState;
        });
        deferred.addErrback(function (err) {
            log("Error updating state: " + repr(err));
        });
    },
    
    updateLoop: function() {
        State.updateWithHash();
        callLater(3, State.updateLoop);
    },
    
};
<commit_msg>*** empty log message ***<commit_after>var State = {
    base: "/state/",
    idbase: "state_",
    stateHash: null,
    currentState: [],

    makeHash: function () {
        //makeHash is function that constructs State.stateHash - a hash table with 
        //with (key, pointer) pairs where: 
        //   key = a state variable (e.g. "ExperimentState.pmt_DAC_State[6].voltage")
        //   pointer = a pointer to one HTML element that matches that state variable
        //So, for example, 
        // > stateHash[key] = pointer
        // > stateHash[ExperimentState.pmt_DAC_State[6].voltage] = [object HTMLSpanElement]
        log("Getting state from server.");
        State.stateHash = [];
        deferred = loadJSONDoc(this.base + "webGetState");
        deferred.addCallback(function(result) {
            log("State received.  Creating hash table.");
            var resultkeys = keys(result);
            //log(resultkeys);
            forEach(getElementsByTagAndClassName('span','autoUpdate'),
                function(elem) {                
//                    stateVar = (sp=elem.className.split(' '), sp[0]=="autoUpdate" ? sp[1] : sp[0])
                    stateVar = elem.className.match(/ExperimentState[..a-zA-Z0-9\_\[\]]*/)[0];
                    State.stateHash[stateVar] = elem;
                    }
            )
            log("Finished creating State.stateHash.  It has " + keys(State.stateHash).length + " entries.");
        });
        deferred.addErrback(function (err) {
            log("Error updating state: " + repr(err));
        });
    },

    updateWithHash: function () {
        log("Updating state.");
        if(State.stateHash == null) {
           State.makeHash();
            log("Getting new hash.");
        }
        deferred = loadJSONDoc(this.base + "webGetState");
        deferred.addCallback(function (newState) {
            var hashkeys = keys(State.stateHash);
            forEach(hashkeys, 
                function (hashkey) {
                    if (newState[hashkey] == State.currentState[hashkey]) {
                        //do nothing if there is no change
                    }
                    else {
                        //if there is a change, put the new data in the appropriate elements
                        State.stateHash[hashkey].innerHTML = newState[hashkey];
                        //log("changed " + hashkey);
                    }
                }
            )
            State.currentState = newState;
        });
        deferred.addErrback(function (err) {
            log("Error updating state: " + repr(err));
        });
    },
    
    updateLoop: function() {
        State.updateWithHash();
        callLater(3, State.updateLoop);
    },
    
};

{'fraction_non_alphanumeric': 0.12750090942160786, 'fraction_numerical': 0.0034558021098581304, 'mean_word_length': 1.6260744985673352, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '7173339', 'n_tokens_mistral': 1505, 'n_tokens_neox': 1433, 'n_words': 316}