<commit_before>'use strict';
angular.module('testReporterApp')
  .directive('errorReport', [ '$http', '$q','SolrSearch','$rootScope', function ($http, $q, SolrSearch, $rootScope) {
    return {
        templateUrl: '/views/directives/error-report.html',
        restrict: 'A',
        scope: {
          errorReport: '='
        },
        link: function ($scope) {
          $scope.$watch('errorReport', function (testReport) {
              if(!testReport) {
                return;
              }
              var erroredExecutions = [];
              var errors = [];
              testReport.cases.forEach(function (tc) {
                tc.executions.forEach(function (te) {
                  if(!te.passing && !te.skipped) {
                    erroredExecutions.push(te);
                  }
                });
              });

              var failingTest = erroredExecutions.shift();
              SolrSearch.getSimilarDocuments(failingTest)
                .then(function _(response) {
                  var error = {
                    error: response.test.error,
                    interestingTerms: response.data.interestingTerms,
                    url: response.url,
                    affectedTests: [response.test]
                  };
                  var docs = response.data.response.docs;

                  docs.forEach(function (doc) {
                    var match = erroredExecutions.findIndex(function(te) {
                      return te.id == doc.id;
                    });

                    if(match !== -1) {
                      error.affectedTests.push(erroredExecutions.splice(match, 1)[0]);
                    }
                  });

                  errors.push(error);
                  var nextError = erroredExecutions.shift();
                  if(nextError) {
                    return SolrSearch.getSimilarDocuments(nextError)
                    .then(_)
                  }
                })
                .then(function() {
                  $rootScope.$broadcast('error-report', errors);
                  $scope.errorDetails = errors.sort(function (a, b) {
                    return b.affectedTests.length - a.affectedTests.length;
                  });
                });
          });
        }
    }
  }]);<commit_msg>Filtering error report collection so that only errors with mulitple affected reports are shown<commit_after>'use strict';
angular.module('testReporterApp')
  .directive('errorReport', [ '$http', '$q','SolrSearch','$rootScope', function ($http, $q, SolrSearch, $rootScope) {
    return {
        templateUrl: '/views/directives/error-report.html',
        restrict: 'A',
        scope: {
          errorReport: '='
        },
        link: function ($scope) {
          $scope.$watch('errorReport', function (testReport) {
              if(!testReport) {
                return;
              }
              var erroredExecutions = [];
              var errors = [];
              testReport.cases.forEach(function (tc) {
                tc.executions.forEach(function (te) {
                  if(!te.passing && !te.skipped) {
                    erroredExecutions.push(te);
                  }
                });
              });

              var failingTest = erroredExecutions.shift();
              SolrSearch.getSimilarDocuments(failingTest)
                .then(function _(response) {
                  var error = {
                    error: response.test.error,
                    interestingTerms: response.data.interestingTerms,
                    url: response.url,
                    affectedTests: [response.test]
                  };
                  var docs = response.data.response.docs;

                  docs.forEach(function (doc) {
                    var match = erroredExecutions.findIndex(function(te) {
                      return te.id == doc.id;
                    });

                    if(match !== -1) {
                      error.affectedTests.push(erroredExecutions.splice(match, 1)[0]);
                    }
                  });

                  errors.push(error);
                  var nextError = erroredExecutions.shift();
                  if(nextError) {
                    return SolrSearch.getSimilarDocuments(nextError)
                    .then(_)
                  }
                })
                .then(function() {
                  $rootScope.$broadcast('error-report', errors);
                  $scope.errorDetails = errors.sort(function (a, b) {
                    return b.affectedTests.length - a.affectedTests.length;
                  }).filter(function (e) {
                    return e.affectedTests.length > 1;
                  });
                });
          });
        }
    }
  }]);
{'fraction_non_alphanumeric': 0.11474722047409272, 'fraction_numerical': 0.0014684287812041115, 'mean_word_length': 1.2301216089803555, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '5435093', 'n_tokens_mistral': 1242, 'n_tokens_neox': 1118, 'n_words': 190}