<commit_before>/*
 * Copyright 2015 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/* global glowroot, moment, $ */

glowroot.controller('ErrorMessagesCtrl', [
  '$scope',
  '$http',
  '$location',
  'charts',
  'queryStrings',
  'httpErrors',
  function ($scope, $http, $location, charts, queryStrings, httpErrors) {

    $scope.$parent.activeTabItem = 'messages';

    var chartState = charts.createState();

    $scope.showChartOverlay = 0;
    $scope.showChartSpinner = 0;

    var errorMessageLimit = 25;
    var dataSeriesExtra;

    $scope.$watchGroup(['chartFrom', 'chartTo', 'chartRefresh'], function (newValues, oldValues) {
      if (newValues !== oldValues) {
        refreshData();
      }
    });

    function refreshData(deferred) {
      var query = {
        from: $scope.chartFrom,
        to: $scope.chartTo,
        transactionType: $scope.transactionType,
        transactionName: $scope.transactionName,
        include: $scope.errorFilterIncludes,
        exclude: $scope.errorFilterExcludes,
        errorMessageLimit: errorMessageLimit
      };
      if (deferred) {
        $scope.showChartOverlay++;
      } else {
        $scope.showChartSpinner++;
      }
      $http.get('backend/error/messages' + queryStrings.encodeObject(query))
          .success(function (data) {
            if (deferred) {
              $scope.showChartOverlay--;
            } else {
              $scope.showChartSpinner--;
            }
            if ($scope.showChartOverlay || $scope.showChartSpinner) {
              return;
            }
            $scope.chartNoData = !data.dataSeries.data.length;
            // reset axis in case user changed the date and then zoomed in/out to trigger this refresh
            chartState.plot.getAxes().xaxis.options.min = query.from;
            chartState.plot.getAxes().xaxis.options.max = query.to;
            chartState.dataPointIntervalMillis = charts.getDataPointIntervalMillis(query.from, query.to);
            if (data.dataSeries.data.length) {
              chartState.plot.setData([{data: data.dataSeries.data}]);
            } else {
              chartState.plot.setData([[]]);
            }
            chartState.plot.setupGrid();
            chartState.plot.draw();
            dataSeriesExtra = data.dataSeriesExtra;

            $scope.moreErrorMessagesAvailable = data.moreErrorMessagesAvailable;
            $scope.errorMessages = data.errorMessages;
            if (deferred) {
              deferred.resolve();
            }
          })
          .error(function (data, status) {
            if (deferred) {
              $scope.showChartOverlay--;
            } else {
              $scope.showChartSpinner--;
            }
            httpErrors.handler($scope, deferred)(data, status);
          });
    }

    $scope.tracesQueryString = function (errorMessage) {
      var query = {};
      if ($scope.transactionType !== $scope.layout.defaultTransactionType) {
        query['transaction-type'] = $scope.transactionType;
      }
      query['transaction-name'] = $scope.transactionName;
      query.from = $scope.chartFrom;
      query.to = $scope.chartTo;
      if (errorMessage.message.length <= 1000) {
        query.error = errorMessage.message;
        query.errorComparator = 'equals';
      } else {
        // this keeps url length under control
        query.error = errorMessage.message.substring(0, 1000);
        query.errorComparator = 'begins';
      }
      return queryStrings.encodeObject(query);
    };

    $scope.showMoreErrorMessages = function (deferred) {
      // double each time
      errorMessageLimit *= 2;
      refreshData(deferred);
    };

    $scope.refreshButtonClick = function () {
      $location.search('filter', $scope.errorFilter);
    };

    function parseQuery(text) {
      var includes = [];
      var excludes = [];
      var i;
      var c;
      var currTerm;
      var inQuote;
      var inExclude;

      function pushCurrTerm() {
        if (inExclude) {
          excludes.push(currTerm);
        } else {
          includes.push(currTerm);
        }
      }

      for (i = 0; i < text.length; i++) {
        c = text.charAt(i);
        if (currTerm !== undefined) {
          // inside quoted or non-quoted term
          if (c === inQuote || !inQuote && c === ' ') {
            // end of term (quoted or non-quoted)<commit_msg>Fix error chart refresh button<commit_after>/*
 * Copyright 2015 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/* global glowroot, moment, $ */

glowroot.controller('ErrorMessagesCtrl', [
  '$scope',
  '$http',
  '$location',
  'charts',
  'queryStrings',
  'httpErrors',
  function ($scope, $http, $location, charts, queryStrings, httpErrors) {

    $scope.$parent.activeTabItem = 'messages';

    var chartState = charts.createState();

    $scope.showChartOverlay = 0;
    $scope.showChartSpinner = 0;

    var errorMessageLimit = 25;
    var dataSeriesExtra;

    $scope.$watchGroup(['chartFrom', 'chartTo', 'chartRefresh'], function (newValues, oldValues) {
      if (newValues !== oldValues) {
        refreshData();
      }
    });

    function refreshData(deferred) {
      var query = {
        from: $scope.chartFrom,
        to: $scope.chartTo,
        transactionType: $scope.transactionType,
        transactionName: $scope.transactionName,
        include: $scope.errorFilterIncludes,
        exclude: $scope.errorFilterExcludes,
        errorMessageLimit: errorMessageLimit
      };
      if (deferred) {
        $scope.showChartOverlay++;
      } else {
        $scope.showChartSpinner++;
      }
      $http.get('backend/error/messages' + queryStrings.encodeObject(query))
          .success(function (data) {
            if (deferred) {
              $scope.showChartOverlay--;
            } else {
              $scope.showChartSpinner--;
            }
            if ($scope.showChartOverlay || $scope.showChartSpinner) {
              return;
            }
            $scope.chartNoData = !data.dataSeries.data.length;
            // reset axis in case user changed the date and then zoomed in/out to trigger this refresh
            chartState.plot.getAxes().xaxis.options.min = query.from;
            chartState.plot.getAxes().xaxis.options.max = query.to;
            chartState.dataPointIntervalMillis = charts.getDataPointIntervalMillis(query.from, query.to);
            if (data.dataSeries.data.length) {
              chartState.plot.setData([{data: data.dataSeries.data}]);
            } else {
              chartState.plot.setData([[]]);
            }
            chartState.plot.setupGrid();
            chartState.plot.draw();
            dataSeriesExtra = data.dataSeriesExtra;

            $scope.moreErrorMessagesAvailable = data.moreErrorMessagesAvailable;
            $scope.errorMessages = data.errorMessages;
            if (deferred) {
              deferred.resolve();
            }
          })
          .error(function (data, status) {
            if (deferred) {
              $scope.showChartOverlay--;
            } else {
              $scope.showChartSpinner--;
            }
            httpErrors.handler($scope, deferred)(data, status);
          });
    }

    $scope.tracesQueryString = function (errorMessage) {
      var query = {};
      if ($scope.transactionType !== $scope.layout.defaultTransactionType) {
        query['transaction-type'] = $scope.transactionType;
      }
      query['transaction-name'] = $scope.transactionName;
      query.from = $scope.chartFrom;
      query.to = $scope.chartTo;
      if (errorMessage.message.length <= 1000) {
        query.error = errorMessage.message;
        query.errorComparator = 'equals';
      } else {
        // this keeps url length under control
        query.error = errorMessage.message.substring(0, 1000);
        query.errorComparator = 'begins';
      }
      return queryStrings.encodeObject(query);
    };

    $scope.showMoreErrorMessages = function (deferred) {
      // double each time
      errorMessageLimit *= 2;
      refreshData(deferred);
    };

    $scope.refreshButtonClick = function () {
      $scope.$parent.chartRefresh++;
      $location.search('filter', $scope.errorFilter);
    };

    function parseQuery(text) {
      var includes = [];
      var excludes = [];
      var i;
      var c;
      var currTerm;
      var inQuote;
      var inExclude;

      function pushCurrTerm() {
        if (inExclude) {
          excludes.push(currTerm);
        } else {
          includes.push(currTerm);
        }
      }

      for (i = 0; i < text.length; i++) {
        c = text.charAt(i);
        if (currTerm !== undefined) {
          // inside quoted or non-quoted term
          if (c === inQuote || !inQuote && c === ' ') {
            // end of term (quoted or non-quoted)
{'fraction_non_alphanumeric': 0.11801053484602918, 'fraction_numerical': 0.004659643435980551, 'mean_word_length': 2.195145631067961, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '134828', 'n_tokens_mistral': 2745, 'n_tokens_neox': 2679, 'n_words': 636}