<commit_before>(function (window, angular, undefined) {
  'use strict';

  angular
    .module('tc.aaf')
    .service('Utils', Utils);

  /**
   * @name Utils
   * @desc Utils class for Manage Challenges
   * @param {!angular.$http}
   * @param {!angular.$q}
   * @returns 
   * @ngInject
   */
  Utils.$inject = ['$filter', '$http', '$q', '$window', 'ngTableParams', 'TABLE'];
  function Utils($filter, $http, $q, $window, ngTableParams, TABLE) {
    var _challenges;
    
    var serviceAPI = {
      getBrowser: getBrowser,
      getJsonData: getJsonData,
      handleTable: handleTable
    };

    return serviceAPI;

    /***** Private Functions *****/

    function getBrowser() {
      var userAgent = $window.navigator.userAgent;
      var browsers = {chrome: /chrome/i, safari: /safari/i, firefox: /firefox/i, ie: /internet explorer/i};
      for (var key in browsers) {
        if (browsers[key].test(userAgent)) {
          return key;
        }
      }
      return 'unknown';      
    }


    //TODO: remove or replace when we refactor to use ng-grid
    //helper function for configuring ng-tables
    function handleTable(controller, $scope, headers, data, sorting) {
      var perPage = TABLE.defaultRowsPerPage;
      var vm = controller;

      vm.columnHeaders = headers;
      vm.tableParams = new ngTableParams(
        {
          page: 1, // show first page
          count: perPage, //fixed page size
          sorting: sorting // initial sorting
        },
        {
          total: data.length, // length of data
          getData: function ($defer, params) {
            // use built-in angular filter
            var orderedData = params.sorting() ? $filter('orderBy')(data, params.orderBy()) : data;
            $defer.resolve($scope.tableRows = orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count()));
          }
        });
    }

    function getJsonData(jsonUrl) {
      var deferred = $q.defer();
      
      $http({method: 'GET', url: jsonUrl})
        .success(function (data, status, headers, config) {
          deferred.resolve(data);
        })
        .error(function (data, status, headers, config) {
          deferred.reject(data);
        });
      return deferred.promise;
    }

  }

})(window, window.angular);<commit_msg>helper functions for api call<commit_after>(function (window, angular, undefined) {
  'use strict';

  angular
    .module('tc.aaf')
    .service('Utils', Utils);

  /**
   * @name Utils
   * @desc Utils class for Manage Challenges
   * @param {!angular.$http}
   * @param {!angular.$q}
   * @returns 
   * @ngInject
   */
  Utils.$inject = ['$filter', '$http', '$q', '$window', 'ngTableParams', 'TABLE'];
  function Utils($filter, $http, $q, $window, ngTableParams, TABLE) {
    var _challenges;
    
    var serviceAPI = {
      apiCall: apiCall,
      initCase: initCase,
      getBrowser: getBrowser,
      getJsonData: getJsonData,
      handleTable: handleTable
    };

    return serviceAPI;

    /***** Private Functions *****/

    function getBrowser() {
      var userAgent = $window.navigator.userAgent;
      var browsers = {chrome: /chrome/i, safari: /safari/i, firefox: /firefox/i, ie: /internet explorer/i};
      for (var key in browsers) {
        if (browsers[key].test(userAgent)) {
          return key;
        }
      }
      return 'unknown';      
    }


    //TODO: remove or replace when we refactor to use ng-grid
    //helper function for configuring ng-tables
    function handleTable(controller, $scope, headers, data, sorting) {
      var perPage = TABLE.defaultRowsPerPage;
      var vm = controller;

      vm.columnHeaders = headers;
      vm.tableParams = new ngTableParams(
        {
          page: 1, // show first page
          count: perPage, //fixed page size
          sorting: sorting // initial sorting
        },
        {
          total: data.length, // length of data
          getData: function ($defer, params) {
            // use built-in angular filter
            var orderedData = params.sorting() ? $filter('orderBy')(data, params.orderBy()) : data;
            $defer.resolve($scope.tableRows = orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count()));
          }
        });
    }

    function getJsonData(jsonUrl) {
      var deferred = $q.defer();
      
      $http({method: 'GET', url: jsonUrl})
        .success(function (data, status, headers, config) {
          deferred.resolve(data);
        })
        .error(function (data, status, headers, config) {
          deferred.reject(data);
        });
      return deferred.promise;
    }

    function apiCall(uri) {
      var deferred = $q.defer();
      
      $http({method: 'GET', url: '/api'})
        .success(function (data, status, headers, config) {
          console.log('got this data: ', data.content);
          deferred.resolve(data.content);
        })
        .error(function (data, status, headers, config) {
          deferred.reject(data);
        });
      return deferred.promise;
    }

    function initCase(str) {
      return str.toLowerCase().replace(/(?:^|\s)[a-z]/g, function (m) {
            return m.toUpperCase();
      });      
    }

  }

})(window, window.angular);
{'fraction_non_alphanumeric': 0.14258555133079848, 'fraction_numerical': 0.0007604562737642585, 'mean_word_length': 2.2197062423500613, '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': '2731551', 'n_tokens_mistral': 1608, 'n_tokens_neox': 1550, 'n_words': 392}