<commit_before>var _ = require('underscore');
var GeoJSONDataProviderBase = require('./geojson-data-provider-base');

var CategoryGeoJSONDataProvider = function (vectorLayerView, layerIndex) {
  GeoJSONDataProviderBase.apply(this, arguments);
};

_.extend(CategoryGeoJSONDataProvider.prototype, GeoJSONDataProviderBase.prototype);

CategoryGeoJSONDataProvider.prototype.getData = function (features) {
  var options = this._dataview.attributes;
  var columnName = options.column;
  var filterEnabled = options.filterEnabled;
  var numberOfCategories = 5;
  var sortedGroups;
  var count;
  if (filterEnabled) {
    // TODO: There's probably a more efficient way of doing this
    var groups = _.groupBy(features, function (feature) { return feature.properties[columnName]; });
    var groupCounts = _.map(Object.keys(groups), function (key) {
      return {
        key: key,
        value: groups[key].length
      };
    });
    sortedGroups = _.sortBy(groupCounts, function (group) {
      return group.value;
    }).reverse();
    count = features.length;
  } else {
    var filter = this._vectorLayerView.getFilter(this._layerIndex);
    sortedGroups = filter.getColumnValues(columnName);
    count = filter.getCount(columnName);
  }
  // TODO: Filter is undefined here when filterEnabled === true
  var nulls = filter.getValues(false, columnName).reduce(function (p, c) { return p + (c.properties[columnName] === null ? 1 : 0); }, 0);
  var data = {
    categories: [],
    categoriesCount: sortedGroups.length,
    count: count,
    max: sortedGroups[0].value,
    min: sortedGroups[sortedGroups.length - 1].value,
    nulls: nulls,
    type: 'aggregation'
  };
<commit_msg>Replaces implementation of the calculation of data for the category dataview.<commit_after>var _ = require('underscore');
var GeoJSONDataProviderBase = require('./geojson-data-provider-base');

var CategoryGeoJSONDataProvider = function (vectorLayerView, layerIndex) {
  GeoJSONDataProviderBase.apply(this, arguments);
};

_.extend(CategoryGeoJSONDataProvider.prototype, GeoJSONDataProviderBase.prototype);

CategoryGeoJSONDataProvider.prototype.getData = function () {
  var options = this._dataview.attributes;
  var columnName = options.column;
  var filterEnabled = options.filterEnabled;
  var numberOfCategories = 5;
  var filter = this._vectorLayerView.getFilter(this._layerIndex);
  var features = this._getFeatures();
  if (!filterEnabled) {
    features = filter.getValues(false, columnName);
  }

  // TODO: There's probably a more efficient way of doing this
  var groups = _.groupBy(features, function (feature) { return feature.properties[columnName]; });
  var groupCounts = _.map(Object.keys(groups), function (key) {
    return {
      key: key,
      value: groups[key].length
    };
  });
  var sortedGroups = _.sortBy(groupCounts, function (group) {
    return group.value;
  }).reverse();
  var count = features.length;

  var nulls = filter.getValues(false, columnName).reduce(function (p, c) { return p + (c.properties[columnName] === null ? 1 : 0); }, 0);
  var data = {
    categories: [],
    categoriesCount: sortedGroups.length,
    count: count,
    max: sortedGroups[0].value,
    min: sortedGroups[sortedGroups.length - 1].value,
    nulls: nulls,
    type: 'aggregation'
  };

{'fraction_non_alphanumeric': 0.1213134691395561, 'fraction_numerical': 0.0036485253876558225, 'mean_word_length': 4.197472353870458, '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': '4554965', 'n_tokens_mistral': 977, 'n_tokens_neox': 957, 'n_words': 232}