<commit_before>(function() {
  angular.module('KMXBackend')
    .factory('SocketService', socketHandler); 

  socketHandler.$inject = ['$rootScope','kmxLogger'];
  
  function socketHandler($rootScope,kmxLogger) {
    var socketWorker;
    //var messageCount = 0;
    var socketHandlers = {
        
        STATUS: statusHandler,// 0: Non blocking callback. Called from the interpreter in different thread
        COMPLETE: completeHandler,// 1: Non blocking callback. Called from the interpreter in different thread
        ERR_MSG: errorMessageHandler,// 2: Non blocking callback
        CONSOLE: consoleHandler,// 3: Non blocking callback, event though it has return value??
        USER: userHandler,// 4: Blocking callback. Called from the interpreter in different thread
        USER_M_CODE: userMCodeHandler,// 5: Blocking callback. Called from the interpreter in different thread
        STATE: stateHandler,// 6: Non blocking callback. Updates gui with current state from server.
        MESSAGEBOX: messageHandler// 7: Blocking callback. However there is no need to block OK only boxes.
    }    
    
    return {
        acknowledge: acknowledge,
        init: init
    }
    
    function init(){
      if(socketWorker){
        return;
      }

      socketWorker = new Worker("js/backend/socket-worker.js");
      socketWorker.onmessage = workerMessage;
      
      var url = 'ws://' + window.location.host + '/ws';
      socketWorker.postMessage({command:'connect',url:url}) 
      
      //does not seem to work, at least not in chrome
//      window.onbeforeunload = function(){
//        socketWorker.postMessage({command:'disconnect'})
//      }
      
    }
    function workerMessage(event) {
      //messageCount++;
      //if(messageCount%5 == 0){
        //console.info("Messages received", messageCount);
      //}
      var data = event.data; 
      if(data.data){
        var obj = data.message;
        var handler = socketHandlers[obj.type];// || _this.defaultHandler;
        var ret = handler(obj);
        if(obj.block){
          //only ack messages that require users answer here
          acknowledge(obj, ret);              
        }
      } else if(data.status){
        //var json = angular.toJson(data.message,true);
        //logHandler(json, LOG_TYPE.NONE);
        //console.log(json);
        
        //Event is coming outside of angular.
        //enter digest cycle with scope.apply
        $rootScope.$apply(function(){
          $rootScope.$broadcast('status-update', { status: data.message });
        });        
      } else if(data.log){
        logHandler(data.message, data.type);
      }
    }
    
    function acknowledge(obj, ret){
      socketWorker.postMessage({command:'acknowledge',obj:obj,ret:ret});
    } 

    
    
    function statusHandler(obj) {
      kmxLogger.log('status', 'Line: '+ obj.data.line + " - " + obj.data.message)
    }
    function completeHandler(obj) {
      kmxLogger.log('status', 'Done Line: '+ obj.data.line + " - " + obj.data.message)
    }
    function errorMessageHandler(obj) {
      kmxLogger.log('error', obj.data);
    }
    function consoleHandler(obj) {
      kmxLogger.log('console', obj.data);
    }
    
    function userHandler(obj) {
      if (confirm('USR: ' + obj.data + ' ?')) {
        return 0; // zero is true for this callback
      } else {
          return 1;
      }
    }
    function userMCodeHandler(obj) {
      if (confirm('Are you sure you want to continue after M' + obj.data + ' ?')) {
        return 0; // zero is true for this callback
      } else {
          return 1;
      }
    }
    <commit_msg>Log all values in complete handler<commit_after>(function() {
  angular.module('KMXBackend')
    .factory('SocketService', socketHandler); 

  socketHandler.$inject = ['$rootScope','kmxLogger'];
  
  function socketHandler($rootScope,kmxLogger) {
    var socketWorker;
    //var messageCount = 0;
    var socketHandlers = {
        
        STATUS: statusHandler,// 0: Non blocking callback. Called from the interpreter in different thread
        COMPLETE: completeHandler,// 1: Non blocking callback. Called from the interpreter in different thread
        ERR_MSG: errorMessageHandler,// 2: Non blocking callback
        CONSOLE: consoleHandler,// 3: Non blocking callback, event though it has return value??
        USER: userHandler,// 4: Blocking callback. Called from the interpreter in different thread
        USER_M_CODE: userMCodeHandler,// 5: Blocking callback. Called from the interpreter in different thread
        STATE: stateHandler,// 6: Non blocking callback. Updates gui with current state from server.
        MESSAGEBOX: messageHandler// 7: Blocking callback. However there is no need to block OK only boxes.
    }    
    
    return {
        acknowledge: acknowledge,
        init: init
    }
    
    function init(){
      if(socketWorker){
        return;
      }

      socketWorker = new Worker("js/backend/socket-worker.js");
      socketWorker.onmessage = workerMessage;
      
      var url = 'ws://' + window.location.host + '/ws';
      socketWorker.postMessage({command:'connect',url:url}) 
      
      //does not seem to work, at least not in chrome
//      window.onbeforeunload = function(){
//        socketWorker.postMessage({command:'disconnect'})
//      }
      
    }
    function workerMessage(event) {
      //messageCount++;
      //if(messageCount%5 == 0){
        //console.info("Messages received", messageCount);
      //}
      var data = event.data; 
      if(data.data){
        var obj = data.message;
        var handler = socketHandlers[obj.type];// || _this.defaultHandler;
        var ret = handler(obj);
        if(obj.block){
          //only ack messages that require users answer here
          acknowledge(obj, ret);              
        }
      } else if(data.status){
        //var json = angular.toJson(data.message,true);
        //logHandler(json, LOG_TYPE.NONE);
        //console.log(json);
        
        //Event is coming outside of angular.
        //enter digest cycle with scope.apply
        $rootScope.$apply(function(){
          $rootScope.$broadcast('status-update', { status: data.message });
        });        
      } else if(data.log){
        logHandler(data.message, data.type);
      }
    }
    
    function acknowledge(obj, ret){
      socketWorker.postMessage({command:'acknowledge',obj:obj,ret:ret});
    } 

    
    
    function statusHandler(obj) {
      kmxLogger.log('status', 'Line: '+ obj.data.line + " - " + obj.data.message);
    }
    function completeHandler(obj) {
      kmxLogger.log('status', 'Done Line: '+ obj.data.line + " Status: " + obj.data.status + " Sequence " + obj.data.sequence + " - " + obj.data.message);
    }
    function errorMessageHandler(obj) {
      kmxLogger.log('error', obj.data);
    }
    function consoleHandler(obj) {
      kmxLogger.log('console', obj.data);
    }
    
    function userHandler(obj) {
      if (confirm('USR: ' + obj.data + ' ?')) {
        return 0; // zero is true for this callback
      } else {
          return 1;
      }
    }
    function userMCodeHandler(obj) {
      if (confirm('Are you sure you want to continue after M' + obj.data + ' ?')) {
        return 0; // zero is true for this callback
      } else {
          return 1;
      }
    }
    
{'fraction_non_alphanumeric': 0.12152966793685356, 'fraction_numerical': 0.004082743603701687, 'mean_word_length': 2.246024734982332, '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': '2978719', 'n_tokens_mistral': 2106, 'n_tokens_neox': 2034, 'n_words': 547}