<commit_before>'use strict';

angular.module('sumaAnalysis')
  .factory('data', function ($http, $q, $timeout, processTimeSeriesData, processCalendarData, processHourlyData) {
    return {
      getSessionsData: function (cfg) {
        var dfd,
            options,
            self = this,
            url;

        dfd = $q.defer();
        url = 'lib/php/sessionsResults.php';

        options = {
          'params': {
            'id': cfg.params.init.id,
            'sdate': cfg.params.sdate || '',
            'edate': cfg.params.edate || '',
            'stime': cfg.params.stime || '',
            'etime': cfg.params.etime || '',
            'classifyCounts': 'session',
            'wholeSession': 'yes',
            'daygroup': 'all' ,
            'locations': 'all',
            'activities': 'all'
          },
          timeout: cfg.timeoutPromise.promise
        };

        this.httpSuccess = function (response) {
          dfd.resolve(response.data);
        };

        this.httpError = function (response) {
          if (response.status === 0) {
            dfd.reject({
              message: 'Data.getSessionsData Timeout',
              code: response.status,
              promiseTimeout: true
            });
          } else {
            dfd.reject({
              message: response.data.message,
              code: response.status
            });
          }
        };

        $http.get(url, options).then(self.httpSuccess, self.httpError);

        $timeout(function () {
          dfd.reject({
            message: 'Data.getSessionsData Timeout',
            code: 0
          });
          cfg.timeoutPromise.resolve();
        }, cfg.timeout);

        return dfd.promise;
      },
      getData: function (cfg) {
        var dfd,
            options,
            processor,
            self = this,
            url;

        dfd = $q.defer();
        url = 'lib/php/dataResults.php';

        if (cfg.dataProcessor === 'processTimeSeriesData') {
          processor = processTimeSeriesData;
        } else if (cfg.dataProcessor === 'processCalendarData') {
          processor = processCalendarData;
        } else if (cfg.dataProcessor === 'processHourlyData'){
          processor = processHourlyData;
        } else {
          dfd.reject({message: 'Data processor not found.', code: 'None found.'});
        }

        options = {
          params: {
            id: cfg.params.init.id,
            sdate: cfg.params.sdate || '',
            edate: cfg.params.edate || '',
            stime: cfg.params.stime || '',
            etime: cfg.params.etime || '',
            classifyCounts: cfg.params.classifyCounts ? cfg.params.classifyCounts.id : 'count',
            wholeSession: cfg.params.wholeSession ? cfg.params.wholeSession.id : 'no',
            daygroup: cfg.params.daygroup ? cfg.params.daygroup.id : 'all' ,
            locations: cfg.params.location ? cfg.params.location.id : 'all',
            activities: cfg.params.activity.type ? (cfg.params.activity.type + '-' + cfg.params.activity.id) : 'all'
          },
          timeout: cfg.timeoutPromise.promise
        };

        this.httpSuccess = function (response) {
          processor.get(response.data, cfg.acts, cfg.locs).then(function (processedData) {
            dfd.resolve(processedData);
          }, self.processorError);
        }

        this.httpError = function (response) {
          if (response.status === 0) {
            dfd.reject({
              message: 'Data.getData Timeout',
              code: response.status,
              promiseTimeout: true
            });
          } else {
            dfd.reject({
              message: response.data.message,
              code: response.status
            });
          }
        };<commit_msg>code cleanup<commit_after>'use strict';

angular.module('sumaAnalysis')
  .factory('data', function ($http, $q, $timeout, processTimeSeriesData, processCalendarData, processHourlyData) {
    return {
      getSessionsData: function (cfg) {
        var dfd,
            options,
            self = this,
            url;

        dfd = $q.defer();
        url = 'lib/php/sessionsResults.php';

        options = {
          'params': {
            'id': cfg.params.init.id,
            'sdate': cfg.params.sdate || '',
            'edate': cfg.params.edate || '',
            'stime': cfg.params.stime || '',
            'etime': cfg.params.etime || '',
            'classifyCounts': 'session',
            'wholeSession': 'yes',
            'daygroup': 'all' ,
            'locations': 'all',
            'activities': 'all'
          },
          timeout: cfg.timeoutPromise.promise
        };

        this.httpSuccess = function (response) {
          dfd.resolve(response.data);
        };

        this.httpError = function (response) {
          if (response.status === 0) {
            dfd.reject({
              message: 'Data.getSessionsData Timeout',
              code: response.status,
              promiseTimeout: true
            });
          } else {
            dfd.reject({
              message: response.data.message,
              code: response.status
            });
          }
        };

        $http.get(url, options).then(self.httpSuccess, self.httpError);

        $timeout(function () {
          dfd.reject({
            message: 'Data.getSessionsData Timeout',
            code: 0
          });
          cfg.timeoutPromise.resolve();
        }, cfg.timeout);

        return dfd.promise;
      },
      getData: function (cfg) {
        var dfd,
            options,
            processor,
            self = this,
            url;

        dfd = $q.defer();
        url = 'lib/php/dataResults.php';

        if (cfg.dataProcessor === 'processTimeSeriesData') {
          processor = processTimeSeriesData;
        } else if (cfg.dataProcessor === 'processCalendarData') {
          processor = processCalendarData;
        } else if (cfg.dataProcessor === 'processHourlyData'){
          processor = processHourlyData;
        } else {
          dfd.reject({message: 'Data processor not found.', code: 'None found.'});
        }

        options = {
          params: {
            id: cfg.params.init.id,
            sdate: cfg.params.sdate || '',
            edate: cfg.params.edate || '',
            stime: cfg.params.stime || '',
            etime: cfg.params.etime || '',
            classifyCounts: cfg.params.classifyCounts ? cfg.params.classifyCounts.id : 'count',
            wholeSession: cfg.params.wholeSession ? cfg.params.wholeSession.id : 'no',
            daygroup: cfg.params.daygroup ? cfg.params.daygroup.id : 'all' ,
            locations: cfg.params.location ? cfg.params.location.id : 'all',
            activities: cfg.params.activity.type ? (cfg.params.activity.type + '-' + cfg.params.activity.id) : 'all'
          },
          timeout: cfg.timeoutPromise.promise
        };

        this.httpSuccess = function (response) {
          processor.get(response.data, cfg.acts, cfg.locs).then(function (processedData) {
            dfd.resolve(processedData);
          }, self.processorError);
        };

        this.httpError = function (response) {
          if (response.status === 0) {
            dfd.reject({
              message: 'Data.getData Timeout',
              code: response.status,
              promiseTimeout: true
            });
          } else {
            dfd.reject({
              message: response.data.message,
              code: response.status
            });
          }
        };
{'fraction_non_alphanumeric': 0.13228283898305085, 'fraction_numerical': 0.0007944915254237289, 'mean_word_length': 1.5725476839237058, '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': '5200215', 'n_tokens_mistral': 2082, 'n_tokens_neox': 2041, 'n_words': 383}