<commit_before>//
// The core time checker logic itself.
//
// TODO: Need to extract the following dependencies:
//
//      - XHR / Network calls
//      - Timer functions (setTimeout)
//

(function(scope){
    // 
    // Make sure requirements are loaded (TODO: Other ways to do this?)
    //
    if (!scope.Network){
        throw "Unable to located required module 'Network'."
    }
    
    // Make sure our object doesn't already exist
    // before defining it.
    if (!scope.TimeChecker){
        scope.TimeChecker = function(options){
            
            // Deafult options if none provided
            if (!options){
                options = {};
                options.CorrectLatency = true;
                options.TestDelay = 50;
                options.TestCount = 100;
            }
            
            // Apply any options
            var self = this,
                stopTest = false,
                RETRY_INTERVAL_MS = options.TestDelay, 
                calls = 0, 
                MAX_TEST_RUNS = options.TestCount,
                CORRECT_LATENCY = options.CorrectLatency;
                
            // Test result collections
            var timeResults = [],
                latencies = [];
            
            // Function used to run a single test method
            var invokeTest = function(){
                if ((calls < MAX_TEST_RUNS) && (!stopTest)){
                    // Begin test run: first take time snapshot
                    var start = new Date().getTime();
                    
                    // Make call to get data
                    $.ajax({
                        url: '/Time',
                        success: function(data){
                            var end = new Date().getTime();
                            var latency = (end - start) / 2.0;
                            
                            // compute/save time delta
                            if (CORRECT_LATENCY){
                                timeResults.push(Math.abs(start - (data.ServerTime - latency)));
                            } else {
                                timeResults.push(Math.abs(start - data.ServerTime));
                            }
                            
                            // save latency
                            latencies.push(latency);
                            
                            // Invoke callback (if supplied)
                            if (self.OnNextResult){
                                self.OnNextResult({
                                    Latencies : latencies,
                                    Measurements : timeResults
                                });
                            }

                            // Increment call counter
                            calls++;
                            
                            // Fire off again after RETRY delay
                            if (!stopTest){
                                setTimeout(invokeTest, RETRY_INTERVAL_MS);
                            } 
                        }
                    });
                } else {
                    // Done - reset and stop call chain
                    calls = 0;
                    if (self.OnComplete){
                        self.OnComplete();
                    }
                }
            };
            
            // callback methods
            self.OnNextResult = null;
            self.OnComplete = null;<commit_msg>Staged a zero-value time delta in array initializer to give correct scale; Fixed reset issue when stopping test runs<commit_after>//
// The core time checker logic itself.
//
// TODO: Need to extract the following dependencies:
//
//      - XHR / Network calls
//      - Timer functions (setTimeout)
//

(function(scope){
    // 
    // Make sure requirements are loaded (TODO: Other ways to do this?)
    //
    if (!scope.Network){
        throw "Unable to located required module 'Network'."
    }
    
    // Make sure our object doesn't already exist
    // before defining it.
    if (!scope.TimeChecker){
        scope.TimeChecker = function(options){
            
            // Deafult options if none provided
            if (!options){
                options = {};
                options.CorrectLatency = true;
                options.TestDelay = 50;
                options.TestCount = 100;
            }
            
            // Apply any options
            var self = this,
                stopTest = false,
                RETRY_INTERVAL_MS = options.TestDelay, 
                calls = 0, 
                MAX_TEST_RUNS = options.TestCount,
                CORRECT_LATENCY = options.CorrectLatency;
                
            // Test result collections
            var timeResults = [0.0],
                latencies = [];
            
            // Function used to run a single test method
            var invokeTest = function(){
                if ((calls < MAX_TEST_RUNS) && (!stopTest)){
                    // Begin test run: first take time snapshot
                    var start = new Date().getTime();
                    
                    // Make call to get data
                    $.ajax({
                        url: '/Time',
                        success: function(data){
                            var end = new Date().getTime();
                            var latency = (end - start) / 2.0;
                            
                            // compute/save time delta
                            if (CORRECT_LATENCY){
                                timeResults.push(Math.abs(start - (data.ServerTime - latency)));
                            } else {
                                timeResults.push(Math.abs(start - data.ServerTime));
                            }
                            
                            // save latency
                            latencies.push(latency);
                            
                            // Invoke callback (if supplied)
                            if (self.OnNextResult){
                                self.OnNextResult({
                                    Latencies : latencies,
                                    Measurements : timeResults
                                });
                            }

                            // Increment call counter
                            calls++;
                            
                            // Fire off again after RETRY delay
                            if (!stopTest){
                                setTimeout(invokeTest, RETRY_INTERVAL_MS);
                            } else {
                                // Done - reset and stop call chain
                                calls = 0;
                                if (self.OnComplete){
                                    self.OnComplete();
                                }
                            }
                        }
                    });
                } else {
                    // Done - reset and stop call chain
                    calls = 0;
                    if (self.OnComplete){
                        self.OnComplete();
                    }
                }
            };
            
            // callback methods
            self.OnNextResult = null;
            self.OnComplete = null;
{'fraction_non_alphanumeric': 0.07651535743408534, 'fraction_numerical': 0.0028540364229410167, 'mean_word_length': 0.7753920386007238, 'pattern_counts': {'":': 0, '<': 5, '<?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': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4190057', 'n_tokens_mistral': 1607, 'n_tokens_neox': 1493, 'n_words': 416}