<commit_before>/* global miqHttpInject */

  ManageIQ.angular.app.controller('containerLiveDashboardController', ['$http', '$window', 'miqService',
    function($http, $window, miqService) {
    var dash = this;
    dash.tenant = '_ops';
    dash.minBucketDurationInSecondes = 20 * 60;

    var NUMBER_OF_MILISEC_IN_HOUR = 60 * 60 * 1000;
    var NUMBER_OF_MILISEC_IN_SEC = 1000;

    // get the pathname and remove trailing / if exist
    var pathname = $window.location.pathname.replace(/\/$/, '');
    var id = '/' + (/^\/[^\/]+\/(\d+)$/.exec(pathname)[1]);

    var initialization = function() {
      dash.tenantChanged = false;

      dash.filtersText = '';
      dash.definitions = [];
      dash.items = [];
      dash.tags = {};
      dash.tagsLoaded = false;

      dash.applied = false;
      dash.filterChanged = true;
      dash.viewGraph = false;
      dash.chartData = {};

      dash.filterConfig.fields = [];
      dash.filterConfig.resultsCount = dash.items.length;
      dash.filterConfig.appliedFilters = [];
      dash.filterConfig.onFilterChange = filterChange;

      dash.toolbarConfig.filterConfig = dash.filterConfig;
      dash.toolbarConfig.actionsConfig = dash.actionsConfig;

      dash.url = '/container_dashboard/data' + id + '/?live=true&tenant=' + dash.tenant;
    }

    var filterChange = function (filters) {
      dash.filterChanged = true;
      dash.filtersText = "";
      dash.tags = {};
      dash.filterConfig.appliedFilters.forEach(function (filter) {
        dash.filtersText += filter.title + " : " + filter.value + "\n";
        dash.tags[filter.id] = filter.value;
      });
    };

    var selectionChange = function() {
      dash.itemSelected = false;
      for (var i = 0; i < dash.items.length && !dash.itemSelected; i++) {
        if (dash.items[i].selected) {
          dash.itemSelected = true;
        }
      }
    };

    dash.doApply = function() {
      dash.applied = true;
      dash.filterChanged = false;
      dash.refresh();
    };

    dash.doViewGraph = function() {
      dash.viewGraph = true;
      dash.chartDataInit = false;
      dash.refresh_graph_data();
    };

    dash.doViewMetrics = function() {
      dash.viewGraph = false;
      dash.refresh();
    };

    dash.doRefreshTenant = function() {
      initialization();
      getMetricTags();
    };

    var getMetricTags = function() {
      $http.get(dash.url + '&query=metric_tags&limit=250')
        .then(getMetricTagsData)
        .catch(miqService.handleFailure);
    };

    var getLatestData = function(item) {
      var params = '&query=get_data&type=' + item.type + '&metric_id=' + item.id +
        '&limit=5&order=DESC';

      $http.get(dash.url + params)
        .then(function(response) { getContainerDashboardData(item, response); })
        .catch(miqService.handleFailure);
    };

    dash.refresh = function() {
      dash.loadingMetrics = true;
      var _tags = dash.tags !== {} ? '&tags=' + JSON.stringify(dash.tags) : '';
      $http.get(dash.url + '&query=metric_definitions' + _tags)
        .then(getMetricDefinitionsData)
        .catch(miqService.handleFailure);
    };

    dash.refresh_graph = function(metricId, metricType, currentItem) {
      var numberOfBucketsInChart = 300;

      dash.metricId = metricId;
      dash.currentItem = currentItem;
      var ends = dash.timeFilter.date.valueOf(); // javascript time is in milisec
      var diff = dash.timeFilter.time_range * dash.timeFilter.range_count * NUMBER_OF_MILISEC_IN_HOUR; // time_range is in hours
      var starts = ends - diff;
      var bucket_duration = parseInt(diff / NUMBER_OF_MILISEC_IN_SEC / numberOfBucketsInChart); // bucket duration is in seconds

      // make sure backet duration is not smaller then minBucketDurationInSecondes seconds
      if (bucket_duration < dash.minBucketDurationInSecondes) {
        bucket_duration = dash.minBucketDurationInSecondes;
      }

      // hawkular time is in milisec (hawkular bucket_duration is in seconds)
      var params = '&query=get_data&type=' + metricType + '&metric_id=' + dash.metricId + '&ends=' + ends +
                   '&starts=' + starts + '&bucket_duration=' + bucket_duration + 's';

      $http.get(dash.url + params)
        .then(getContainerParamsData)
        .catch(miqService.handleFailure);
    };

    dash.refresh_graph_data = function() {
      dash.loadCount = 0;
      dash.loadingData = true;
      dash.chartData = {};
<commit_msg>Fix typos<commit_after>/* global miqHttpInject */

  ManageIQ.angular.app.controller('containerLiveDashboardController', ['$http', '$window', 'miqService',
    function($http, $window, miqService) {
    var dash = this;
    dash.tenant = '_ops';
    dash.minBucketDurationInSecondes = 20 * 60;

    var NUMBER_OF_MILLISEC_IN_HOUR = 60 * 60 * 1000;
    var NUMBER_OF_MILLISEC_IN_SEC = 1000;

    // get the pathname and remove trailing / if exist
    var pathname = $window.location.pathname.replace(/\/$/, '');
    var id = '/' + (/^\/[^\/]+\/(\d+)$/.exec(pathname)[1]);

    var initialization = function() {
      dash.tenantChanged = false;

      dash.filtersText = '';
      dash.definitions = [];
      dash.items = [];
      dash.tags = {};
      dash.tagsLoaded = false;

      dash.applied = false;
      dash.filterChanged = true;
      dash.viewGraph = false;
      dash.chartData = {};

      dash.filterConfig.fields = [];
      dash.filterConfig.resultsCount = dash.items.length;
      dash.filterConfig.appliedFilters = [];
      dash.filterConfig.onFilterChange = filterChange;

      dash.toolbarConfig.filterConfig = dash.filterConfig;
      dash.toolbarConfig.actionsConfig = dash.actionsConfig;

      dash.url = '/container_dashboard/data' + id + '/?live=true&tenant=' + dash.tenant;
    }

    var filterChange = function (filters) {
      dash.filterChanged = true;
      dash.filtersText = "";
      dash.tags = {};
      dash.filterConfig.appliedFilters.forEach(function (filter) {
        dash.filtersText += filter.title + " : " + filter.value + "\n";
        dash.tags[filter.id] = filter.value;
      });
    };

    var selectionChange = function() {
      dash.itemSelected = false;
      for (var i = 0; i < dash.items.length && !dash.itemSelected; i++) {
        if (dash.items[i].selected) {
          dash.itemSelected = true;
        }
      }
    };

    dash.doApply = function() {
      dash.applied = true;
      dash.filterChanged = false;
      dash.refresh();
    };

    dash.doViewGraph = function() {
      dash.viewGraph = true;
      dash.chartDataInit = false;
      dash.refresh_graph_data();
    };

    dash.doViewMetrics = function() {
      dash.viewGraph = false;
      dash.refresh();
    };

    dash.doRefreshTenant = function() {
      initialization();
      getMetricTags();
    };

    var getMetricTags = function() {
      $http.get(dash.url + '&query=metric_tags&limit=250')
        .then(getMetricTagsData)
        .catch(miqService.handleFailure);
    };

    var getLatestData = function(item) {
      var params = '&query=get_data&type=' + item.type + '&metric_id=' + item.id +
        '&limit=5&order=DESC';

      $http.get(dash.url + params)
        .then(function(response) { getContainerDashboardData(item, response); })
        .catch(miqService.handleFailure);
    };

    dash.refresh = function() {
      dash.loadingMetrics = true;
      var _tags = dash.tags !== {} ? '&tags=' + JSON.stringify(dash.tags) : '';
      $http.get(dash.url + '&query=metric_definitions' + _tags)
        .then(getMetricDefinitionsData)
        .catch(miqService.handleFailure);
    };

    dash.refresh_graph = function(metricId, metricType, currentItem) {
      var numberOfBucketsInChart = 300;

      dash.metricId = metricId;
      dash.currentItem = currentItem;
      var ends = dash.timeFilter.date.valueOf(); // javascript time is in milisec
      var diff = dash.timeFilter.time_range * dash.timeFilter.range_count * NUMBER_OF_MILLISEC_IN_HOUR; // time_range is in hours
      var starts = ends - diff;
      var bucket_duration = parseInt(diff / NUMBER_OF_MILLISEC_IN_SEC / numberOfBucketsInChart); // bucket duration is in seconds

      // make sure bucket duration is not smaller then minBucketDurationInSecondes seconds
      if (bucket_duration < dash.minBucketDurationInSecondes) {
        bucket_duration = dash.minBucketDurationInSecondes;
      }

      // hawkular time is in milisec (hawkular bucket_duration is in seconds)
      var params = '&query=get_data&type=' + metricType + '&metric_id=' + dash.metricId + '&ends=' + ends +
                   '&starts=' + starts + '&bucket_duration=' + bucket_duration + 's';

      $http.get(dash.url + params)
        .then(getContainerParamsData)
        .catch(miqService.handleFailure);
    };

    dash.refresh_graph_data = function() {
      dash.loadCount = 0;
      dash.loadingData = true;
      dash.chartData = {};

{'fraction_non_alphanumeric': 0.13486176668914363, 'fraction_numerical': 0.005844009889862891, 'mean_word_length': 2.683360927152318, 'pattern_counts': {'":': 0, '<': 7, '<?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': '3146298', 'n_tokens_mistral': 2816, 'n_tokens_neox': 2709, 'n_words': 515}