<commit_before>(function() {
  var DashboardCtrl = function($scope, Events, Widget, $routeParams, $location, $http, $timeout, $q, Dashboard) {
    $scope.refreshEnabled = false;
    $scope.refreshRate = 60;

    var loadDashboard = _.throttle(function() {
      $scope.dashboard = Dashboard.get({ slug: $routeParams.dashboardSlug }, function (dashboard) {
        Events.record(currentUser, "view", "dashboard", dashboard.id);

        $scope.$parent.pageTitle = dashboard.name;

        var promises = [];

        $scope.dashboard.widgets = _.map($scope.dashboard.widgets, function (row) {
          return _.map(row, function (widget) {
            var w = new Widget(widget);

            if (w.visualization) {
              promises.push(w.getQuery().getQueryResult().toPromise());
            }

            return w;
          });
        });

        $q.all(promises).then(function(queryResults) {
          var filters = {};
          _.each(queryResults, function(queryResult) {
            var queryFilters = queryResult.getFilters();
            _.each(queryFilters, function (filter) {
              if (!_.has(filters, filter.name)) {
                // TODO: first object should be a copy, otherwise one of the chart filters behaves different than the others.
                filters[filter.name] = filter;
                filters[filter.name].originFilters = [];
                if (_.has($location.search(), filter.name)) {
                  filter.current = $location.search()[filter.name];
                }

                $scope.$watch(function () { return filter.current }, function (value) {
                  _.each(filter.originFilters, function (originFilter) {
                    originFilter.current = value;
                  });
                });
              }

              // TODO: merge values.
              filters[filter.name].originFilters.push(filter);
            });
          });

          $scope.filters = _.values(filters);
        });


      }, function () {
        // error...
        // try again. we wrap loadDashboard with throttle so it doesn't happen too often.\
        // we might want to consider exponential backoff and also move this as a general solution in $http/$resource for
        // all AJAX calls.
        loadDashboard();
      });
    }, 1000);

    loadDashboard();

    var autoRefresh = function() {
      if ($scope.refreshEnabled) {
        $timeout(function() {
          Dashboard.get({
            slug: $routeParams.dashboardSlug
          }, function(dashboard) {
            var newWidgets = _.groupBy(_.flatten(dashboard.widgets), 'id');<commit_msg>Fix: filters got linked when they shouldn't have.<commit_after>(function() {
  var DashboardCtrl = function($scope, Events, Widget, $routeParams, $location, $http, $timeout, $q, Dashboard) {
    $scope.refreshEnabled = false;
    $scope.refreshRate = 60;

    var loadDashboard = _.throttle(function() {
      $scope.dashboard = Dashboard.get({ slug: $routeParams.dashboardSlug }, function (dashboard) {
        Events.record(currentUser, "view", "dashboard", dashboard.id);

        $scope.$parent.pageTitle = dashboard.name;

        var promises = [];

        $scope.dashboard.widgets = _.map($scope.dashboard.widgets, function (row) {
          return _.map(row, function (widget) {
            var w = new Widget(widget);

            if (w.visualization) {
              promises.push(w.getQuery().getQueryResult().toPromise());
            }

            return w;
          });
        });

        $q.all(promises).then(function(queryResults) {
          var filters = {};
          _.each(queryResults, function(queryResult) {
            var queryFilters = queryResult.getFilters();
            _.each(queryFilters, function (queryFilter) {
              var hasQueryStringValue = _.has($location.search(), queryFilter.name);

              if (!(hasQueryStringValue || dashboard.dashboard_filters_enabled)) {
                // If dashboard filters not enabled, or no query string value given, skip filters linking.
                return;
              }

              if (!_.has(filters, queryFilter.name)) {
                var filter = _.extend({}, queryFilter);
                filters[filter.name] = filter;
                filters[filter.name].originFilters = [];
                if (hasQueryStringValue) {
                  filter.current = $location.search()[filter.name];
                }

                $scope.$watch(function () { return filter.current }, function (value) {
                  _.each(filter.originFilters, function (originFilter) {
                    originFilter.current = value;
                  });
                });
              }

              // TODO: merge values.
              filters[queryFilter.name].originFilters.push(queryFilter);
            });
          });

          $scope.filters = _.values(filters);
        });


      }, function () {
        // error...
        // try again. we wrap loadDashboard with throttle so it doesn't happen too often.\
        // we might want to consider exponential backoff and also move this as a general solution in $http/$resource for
        // all AJAX calls.
        loadDashboard();
      });
    }, 1000);

    loadDashboard();

    var autoRefresh = function() {
      if ($scope.refreshEnabled) {
        $timeout(function() {
          Dashboard.get({
            slug: $routeParams.dashboardSlug
          }, function(dashboard) {
            var newWidgets = _.groupBy(_.flatten(dashboard.widgets), 'id');
{'fraction_non_alphanumeric': 0.12522490104354084, 'fraction_numerical': 0.0021590500179920835, 'mean_word_length': 1.8938053097345133, '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': '1072802', 'n_tokens_mistral': 1460, 'n_tokens_neox': 1411, 'n_words': 331}