<commit_before>import { createSelector } from 'reselect';
import micromatch from 'micromatch';
import fuzzy from 'fuzzy';
import Utils from '../../utils';

const getTasks = (state) => state.tasks;
const getFilter = (state) => ({requestTypes: state.filter.requestTypes, filterText: state.filter.filterText});

export default createSelector([getTasks, getFilter], (tasks, filter) => {

  // Filter by requestType
  tasks = _.filter(tasks, (task) => {
    return task.taskRequest && _.contains(filter.requestTypes, task.taskRequest.request.requestType);
  });

  if (filter.filterText) {
    const host = {extract: (t) => `${t.taskId && t.taskId.host}`};
    const id = {extract: (t) => `${t.taskId ? t.taskId.id : t.pendingTask.pendingTaskId.id}`};
    const rack = {extract: (t) => `${t.taskId && t.taskId.rackId}`};

    if (Utils.isGlobFilter(filter.filterText)) {
      let res1 = _.filter(tasks, (task) => {
        return micromatch.any(host.extract(task), filter.filterText + '*');
      });
      let res2 = _.filter(tasks, (task) => {
        return micromatch.any(id.extract(task), filter.filterText + '*');
      });
      let res3 = _.filter(tasks, (task) => {
        return micromatch.any(rack.extract(task), filter.filterText + '*');
      });
      tasks = _.union(res1, res2, res3).reverse();
    } else {
      _.each(tasks, (t) => t.id = id.extract(t));
      let res1 = fuzzy.filter(filter.filterText, tasks, host);
      let res2 = fuzzy.filter(filter.filterText, tasks, id);
      let res3 = fuzzy.filter(filter.filterText, tasks, rack);
      tasks = _.uniq(_.pluck(_.sortBy(_.union(res3, _.union(res1, res2)), (t) => Utils.fuzzyAdjustScore(filter.filterText, t)), 'original').reverse());
    }
  }

  return tasks;
});
<commit_msg>cleanup<commit_after>import { createSelector } from 'reselect';
import micromatch from 'micromatch';
import fuzzy from 'fuzzy';
import Utils from '../../utils';

const getTasks = (state) => state.tasks;
const getFilter = (state) => ({requestTypes: state.filter.requestTypes, filterText: state.filter.filterText});

export default createSelector([getTasks, getFilter], (tasks, filter) => {

  // Filter by requestType
  tasks = _.filter(tasks, (task) => {
    return task.taskRequest && _.contains(filter.requestTypes, task.taskRequest.request.requestType);
  });

  // Filter by glob or fuzzy string
  if (filter.filterText) {
    const host = {extract: (t) => `${t.taskId && t.taskId.host}`};
    const id = {extract: (t) => `${t.taskId ? t.taskId.id : t.pendingTask.pendingTaskId.id}`};
    const rack = {extract: (t) => `${t.taskId && t.taskId.rackId}`};

    if (Utils.isGlobFilter(filter.filterText)) {
      let res1 = _.filter(tasks, (task) => {
        return micromatch.any(host.extract(task), filter.filterText + '*');
      });
      let res2 = _.filter(tasks, (task) => {
        return micromatch.any(id.extract(task), filter.filterText + '*');
      });
      let res3 = _.filter(tasks, (task) => {
        return micromatch.any(rack.extract(task), filter.filterText + '*');
      });
      tasks = _.union(res1, res2, res3).reverse();
    } else {
      _.each(tasks, (t) => t.id = id.extract(t));
      let res1 = fuzzy.filter(filter.filterText, tasks, host);
      let res2 = fuzzy.filter(filter.filterText, tasks, id);
      let res3 = fuzzy.filter(filter.filterText, tasks, rack);
      tasks = _.uniq(_.pluck(_.sortBy(_.union(res3, _.union(res1, res2)), (t) => Utils.fuzzyAdjustScore(filter.filterText, t)), 'original').reverse());
    }
  }

  return tasks;
});

{'fraction_non_alphanumeric': 0.18212669683257918, 'fraction_numerical': 0.006787330316742082, 'mean_word_length': 3.5114795918367347, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, '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': '6075352', 'n_tokens_mistral': 1188, 'n_tokens_neox': 1151, 'n_words': 248}