<commit_before>'use strict';

var GoSimple = GoSimple || {};

/**
 * Module: GoSimple.main
 * @description
 * @namespace
 * @memberof GoSimple.main
 */
GoSimple.main = (function () {
  // private variables
  var debug = true;
  var websocketSupported = false;
  var serviceUrl = 'localhost:8080';
  var connectTo = 'ws://' + serviceUrl + '/websocket';
  var socket = null;

  // this
  var self = {};
  self.attempts = 1;
  // public variables
  var pub = {};
  pub.connected = false;

  self.debug = function (msg) {
    if (debug) {
      console.debug(msg);
    }
  };

  pub.init = function () {
    self.debug('Simple init');
    self.check();
    self.connect();
  };

  /**
   * Check for websocket support
   */
  self.check = function () {
    if (window.WebSocket) {
      websocketSupported = true
    } else {
      pub.connected = 'GoSimple: Please update to a modern web browser';
    }
  };

  /**
   * Connect to websocket server
   */
  self.connect = function () {
    if (websocketSupported) {
      socket = new WebSocket(connectTo);
      socket.onopen = function () {
        pub.connected = true;
      };
      socket.onmessage = function (e) {
        self.receive(e);
      };
      socket.onclose = function () {
        pub.connected = false;
        self.close();
      };
    }
  };

  /**
   * Handle close event
   */
  self.close = function () {
    self.debug('connection closed, will try to reconnect');
    var time = self.generateInterval(self.attempts);
    setTimeout(function () {
      // increase the attempts by 1
      self.attempts++;

      // try to reconnect
      self.connect();
    }, time);
  };

  // based on http://blog.johnryding.com/post/78544969349/how-to-reconnect-web-sockets-in-a-realtime-web-app
  self.generateInterval = function (k) {
    var maxInterval = (Math.pow(2, k) - 1) * 1000;

    if (maxInterval > 30*1000) {
      maxInterval = 30*1000; // If the generated interval is more than 30 seconds, truncate it down to 30 seconds.
    }

    // generate the interval to a random number between 0 and the maxInterval determined from above
    return Math.random() * maxInterval;
  };

  /**
   * Handle incoming messages
   */
  self.receive = function (e) {
    // print on page
    var el = document.querySelector('#message');
    el.textContent = e.data;
    var msg = JSON.parse(e.data);
    self.debug(msg);
    if (msg.hasOwnProperty('Data')) {
      if (msg.Data.hasOwnProperty('message')) {
        console.log('got message: ', msg.Data.message);
      } else if (msg.Data.hasOwnProperty('cmd')) {
        console.log('got command: ', msg.Data.cmd);
        if (msg.Data.hasOwnProperty('what')) {
          console.log('what: ', msg.Data.what);
        }
      }

    }
  };

  return pub;
})();
document.addEventListener('DOMContentLoaded', GoSimple3.main.init);<commit_msg>for the last time fix JS namespace<commit_after>'use strict';

var GoSimple = GoSimple || {};

/**
 * Module: GoSimple.main
 * @description
 * @namespace
 * @memberof GoSimple.main
 */
GoSimple.main = (function () {
  // private variables
  var debug = true;
  var websocketSupported = false;
  var serviceUrl = 'localhost:8080';
  var connectTo = 'ws://' + serviceUrl + '/websocket';
  var socket = null;

  // this
  var self = {};
  self.attempts = 1;
  // public variables
  var pub = {};
  pub.connected = false;

  self.debug = function (msg) {
    if (debug) {
      console.debug(msg);
    }
  };

  pub.init = function () {
    self.debug('Simple init');
    self.check();
    self.connect();
  };

  /**
   * Check for websocket support
   */
  self.check = function () {
    if (window.WebSocket) {
      websocketSupported = true
    } else {
      pub.connected = 'GoSimple: Please update to a modern web browser';
    }
  };

  /**
   * Connect to websocket server
   */
  self.connect = function () {
    if (websocketSupported) {
      socket = new WebSocket(connectTo);
      socket.onopen = function () {
        pub.connected = true;
      };
      socket.onmessage = function (e) {
        self.receive(e);
      };
      socket.onclose = function () {
        pub.connected = false;
        self.close();
      };
    }
  };

  /**
   * Handle close event
   */
  self.close = function () {
    self.debug('connection closed, will try to reconnect');
    var time = self.generateInterval(self.attempts);
    setTimeout(function () {
      // increase the attempts by 1
      self.attempts++;

      // try to reconnect
      self.connect();
    }, time);
  };

  // based on http://blog.johnryding.com/post/78544969349/how-to-reconnect-web-sockets-in-a-realtime-web-app
  self.generateInterval = function (k) {
    var maxInterval = (Math.pow(2, k) - 1) * 1000;

    if (maxInterval > 30*1000) {
      maxInterval = 30*1000; // If the generated interval is more than 30 seconds, truncate it down to 30 seconds.
    }

    // generate the interval to a random number between 0 and the maxInterval determined from above
    return Math.random() * maxInterval;
  };

  /**
   * Handle incoming messages
   */
  self.receive = function (e) {
    // print on page
    var el = document.querySelector('#message');
    el.textContent = e.data;
    var msg = JSON.parse(e.data);
    self.debug(msg);
    if (msg.hasOwnProperty('Data')) {
      if (msg.Data.hasOwnProperty('message')) {
        console.log('got message: ', msg.Data.message);
      } else if (msg.Data.hasOwnProperty('cmd')) {
        console.log('got command: ', msg.Data.cmd);
        if (msg.Data.hasOwnProperty('what')) {
          console.log('what: ', msg.Data.what);
        }
      }

    }
  };

  return pub;
})();
document.addEventListener('DOMContentLoaded', GoSimple.main.init);
{'fraction_non_alphanumeric': 0.14615384615384616, 'fraction_numerical': 0.014160839160839161, 'mean_word_length': 2.4114490161001787, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4516934', 'n_tokens_mistral': 1850, 'n_tokens_neox': 1755, 'n_words': 433}