<commit_before>/**
 * @name MainCtrl
 * @description Main controller.
 * @author <NAME>
 */
angular.module('umfTestApp')
  .controller('MainCtrl', ['$scope', '$location', function ($scope, $location) {
    'use strict';

    var VERSION = "1.0";

    $scope.payloadSizeOptions = [
      {name: '.5 kB', value: 0.5},
      {name: '1 kB', value: 1},
      {name: '2 kB', value: 2},
      {name: '4 kB', value: 4},
      {name: '8 kB', value: 8},
      {name: '16 kB', value: 16},
      {name: '32 kB', value: 32},
      {name: '64 kB', value: 64},
      {name: '128 kB', value: 128},
      {name: '256 kB', value: 256},
      {name: '512 kB', value: 512},
      {name: '1024 kB', value: 1024}
    ];
    $scope.msgTypes = [
      {name: 'Random', value: 'random'},
      {name: 'Chat', value: 'chat'},
      {name: 'Client info', value: 'client'},
      {name: 'Mouse position', value: 'mouse'},
      {name: 'Heart beat', value: 'heart'}
    ];
    $scope.startTestButtonOptions = [
      {name: 'Start', class: 'btn-primary'},
      {name: 'Stop', class: 'btn-danger'}
    ];
    $scope.iterationChoices = [
      {name: 'One shot', value: 1},
      {name: 'Twice', value: 2},
      {name: 'Five times', value: 5},
      {name: 'Until stopped', value: -1}
    ];
    $scope.messages = [
      {'output': 'Sent from my browser!'}
    ];
    $scope.console = [];

    $scope.settings = {
      textBuffer: '',
      timerID: null,
      msgPerSecond: 1,
      iterationCnt: 0,
      iteration: $scope.iterationChoices[0],
      payloadSize: $scope.payloadSizeOptions[0],
      msgType: $scope.msgTypes[0],
      startTestButton: $scope.startTestButtonOptions[0]
    };

    if ("WebSocket" in window) {
      $scope.ws = new WebSocket("ws://" + document.domain + ":5000/ws");
      if ($scope.ws) {
        consoleLog("Initializing UMFTester v" + VERSION);
        consoleLog("Connected to WebSocket.");
        consoleLog("Ready for testing.");
      }
    }

    $scope.ws.onmessage = function (msg) {
      var message = JSON.parse(msg.data);
      consoleLog("Incoming message: ", message);
    };

    $scope.startTest = function () {
      var cnt
        , i
        , msg
        , payloadSize
        , settings = $scope.settings;

      settings.startTestButton = (settings.startTestButton.name == 'Start') ?
        $scope.startTestButtonOptions[1] : $scope.startTestButtonOptions[0];

      if (settings.startTestButton.name == 'Start') {
        if (settings.timerID != null) {
          clearInterval($scope.settings.timerID);
          $scope.settings.timerID = null;
          consoleLog("Test ended.");
        }
      } else {
        $scope.console = [];
        payloadSize = settings.payloadSize.value * 1024;
        settings.textBuffer = randomText(payloadSize);
        settings.iterationCnt = Number(settings.iteration.value);

        consoleLog("Starting test.");
        consoleLog("Messages per second: " + settings.msgPerSecond);
        consoleLog("Payload size: " + payloadSize + " bytes.");

        $scope.settings.timerID = setInterval(function () {
          consoleLog("iterationCnt: " + settings.iterationCnt);
          var go = true;
          if (settings.iteration.value != -1) {
            if (--settings.iterationCnt < 0) {
              clearInterval($scope.settings.timerID);
              $scope.settings.timerID = null;
              settings.startTestButton = $scope.startTestButtonOptions[0];
              consoleLog("Test ended.");
              go = false;
            }
          }
          if (go) {
            cnt = Number(settings.msgPerSecond);
            msg = $scope.messages[0];
            msg.output = settings.textBuffer;
            for (i = 0; i < cnt; i++) {
              msg = JSON.stringify(msg);
              $scope.ws.send(msg);
            }
            consoleLog("  " + cnt + " messages sent");
          }
          $scope.$apply();
        }, 1000);
      }
    };

    // Cleanly close websocket when unload window
    window.onbeforeunload = function () {
      $scope.ws.onclose = function () {
        // intentionally set to empty
      }; // disable onclose handler first
      $scope.ws.close();
    };

    function stopTimer() {
    }

    function consoleLog(message, objectValue) {
      try {
        var date = new Date()
          , hours = date.getHours()
          , minutes = date.getMinutes()
          , seconds = date.getSeconds();

        hours = hours < 10 ? "0" + hours : hours;
        minutes = minutes < 10 ? "0" + minutes : minutes;
        seconds = seconds < 10 ? "0" + seconds : seconds;

        if (typeof objectValue != "undefined") {
          if (typeof objectValue == "object") {
            message = message + "(object) " + JSON.stringify(objectValue);
          } else {
            message = message + "(" + typeof message + ") " + objectValue;
          }
        }
<commit_msg>Code cleanup.<commit_after>/**
 * @name MainCtrl
 * @description Main controller.
 * @author <NAME>
 */
angular.module('umfTestApp')
  .controller('MainCtrl', ['$scope', '$location', function ($scope, $location) {
    'use strict';

    var VERSION = "1.0";

    $scope.payloadSizeOptions = [
      {name: '.5 kB', value: 0.5},
      {name: '1 kB', value: 1},
      {name: '2 kB', value: 2},
      {name: '4 kB', value: 4},
      {name: '8 kB', value: 8},
      {name: '16 kB', value: 16},
      {name: '32 kB', value: 32},
      {name: '64 kB', value: 64},
      {name: '128 kB', value: 128},
      {name: '256 kB', value: 256},
      {name: '512 kB', value: 512},
      {name: '1024 kB', value: 1024}
    ];
    $scope.msgTypes = [
      {name: 'Random', value: 'random'},
      {name: 'Chat', value: 'chat'},
      {name: 'Client info', value: 'client'},
      {name: 'Mouse position', value: 'mouse'},
      {name: 'Heart beat', value: 'heart'}
    ];
    $scope.startTestButtonOptions = [
      {name: 'Start', class: 'btn-primary'},
      {name: 'Stop', class: 'btn-danger'}
    ];
    $scope.iterationChoices = [
      {name: 'One shot', value: 1},
      {name: 'Twice', value: 2},
      {name: 'Five times', value: 5},
      {name: 'Until stopped', value: -1}
    ];
    $scope.console = [];
    $scope.messages = [
      {'output': 'Sent from my browser!'}
    ];

    $scope.settings = {
      textBuffer: '',
      timerID: null,
      msgPerSecond: 1,
      iterationCnt: 0,
      iteration: $scope.iterationChoices[0],
      payloadSize: $scope.payloadSizeOptions[0],
      msgType: $scope.msgTypes[0],
      startTestButton: $scope.startTestButtonOptions[0]
    };

    if ("WebSocket" in window) {
      $scope.ws = new WebSocket("ws://" + document.domain + ":5000/ws");
      if ($scope.ws) {
        consoleLog("Initializing UMFTester v" + VERSION);
        consoleLog("Connected to WebSocket.");
        consoleLog("Ready for testing.");
      }
    }

    $scope.ws.onmessage = function (msg) {
      var message = JSON.parse(msg.data);
      consoleLog("Incoming message: ", message);
    };

    // Cleanly close websocket when unload window
    window.onbeforeunload = function () {
      $scope.ws.onclose = function () {
        // intentionally set to empty
      }; // disable onclose handler first
      $scope.ws.close();
    };

    $scope.startTest = function () {
      var cnt
        , i
        , msg
        , payloadSize
        , settings = $scope.settings;

      settings.startTestButton = (settings.startTestButton.name == 'Start') ?
        $scope.startTestButtonOptions[1] : $scope.startTestButtonOptions[0];

      if (settings.startTestButton.name == 'Start') {
        if (settings.timerID != null) {
          clearInterval($scope.settings.timerID);
          $scope.settings.timerID = null;
          consoleLog("Test ended.");
        }
      } else {
        $scope.console = [];
        payloadSize = settings.payloadSize.value * 1024;
        settings.textBuffer = randomText(payloadSize);
        settings.iterationCnt = Number(settings.iteration.value);

        consoleLog("Starting test.");
        consoleLog("Messages per second: " + settings.msgPerSecond);
        consoleLog("Payload size: " + payloadSize + " bytes.");

        $scope.settings.timerID = setInterval(function () {
          consoleLog("iterationCnt: " + settings.iterationCnt);
          var go = true;
          if (settings.iteration.value != -1) {
            if (--settings.iterationCnt < 0) {
              clearInterval($scope.settings.timerID);
              $scope.settings.timerID = null;
              settings.startTestButton = $scope.startTestButtonOptions[0];
              consoleLog("Test ended.");
              go = false;
            }
          }
          if (go) {
            cnt = Number(settings.msgPerSecond);
            msg = $scope.messages[0];
            msg.output = settings.textBuffer;
            for (i = 0; i < cnt; i++) {
              msg = JSON.stringify(msg);
              $scope.ws.send(msg);
            }
            consoleLog("  " + cnt + " messages sent");
          }
          $scope.$apply();
        }, 1000);
      }
    };

    function consoleLog(message, objectValue) {
      try {
        var date = new Date()
          , hours = date.getHours()
          , minutes = date.getMinutes()
          , seconds = date.getSeconds();

        hours = hours < 10 ? "0" + hours : hours;
        minutes = minutes < 10 ? "0" + minutes : minutes;
        seconds = seconds < 10 ? "0" + seconds : seconds;

        if (typeof objectValue != "undefined") {
          if (typeof objectValue == "object") {
            message = message + "(object) " + JSON.stringify(objectValue);
          } else {
            message = message + "(" + typeof message + ") " + objectValue;
          }
        }

{'fraction_non_alphanumeric': 0.15615400368625845, 'fraction_numerical': 0.018226500102396067, 'mean_word_length': 2.0655994978028875, 'pattern_counts': {'":': 2, '<': 15, '<?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': '2988384', 'n_tokens_mistral': 3069, 'n_tokens_neox': 2917, 'n_words': 693}