<commit_before>import {
  createSelector,
  createSelectorCreator,
  defaultMemoize,
} from 'reselect';
import {
  omit,
  filter,
  pickBy,
  mapValues,
  zipObject,
  difference,
  values,
  includes,
  isEqual,
  flatten,
  map,
  size,
} from 'lodash';

import {
  currentSectorSelector,
  currentEntityTypeSelector,
  currentEntitySelector,
  entitySelector,
  isSidebarEditActiveSelector,
  sidebarEditEntitySelector,
  sidebarEditChildrenSelector,
  savedSectorSelector,
  fetchedSectorSelector,
} from 'store/selectors/base.selectors';
import { isViewingSharedSector } from 'store/selectors/sector.selectors';
import Entities from 'constants/entities';
import { allSectorKeys, coordinateKey } from 'utils/common';
import { areNeighbors } from 'utils/hex/common';

const createDeepEqualSelector = createSelectorCreator(defaultMemoize, isEqual);

export const isFetchingCurrent = createDeepEqualSelector(
  [fetchedSectorSelector, savedSectorSelector, currentSectorSelector],
  (fetched, saved, sector) =>
    includes(saved, sector) && !includes(fetched, sector),
);

export const getSavedEntities = createDeepEqualSelector(
  [entitySelector, savedSectorSelector],
  (entities, savedSectors) =>
    mapValues(entities, entityList =>
      pickBy(entityList, ({ sector }) => includes(savedSectors, sector)),
    ),
);

export const getCurrentTopLevelEntities = createDeepEqualSelector(
  [currentSectorSelector, entitySelector, isViewingSharedSector],
  (currentSector, entities, isShared) =>
    Object.assign(
      ...filter(Entities, ({ topLevel }) => topLevel).map(({ key }) =>
        mapValues(
          pickBy(
            entities[key],
            ({ sector, isHidden }) =>
              sector === currentSector && (!isShared || !isHidden),
          ),
          (entity, entityId) => ({
            ...entity,
            type: key,
            numChildren: Entities[key].children.reduce(
              (total, childKey) =>
                total +
                filter(
                  entities[childKey],
                  ({ parent, isHidden }) =>
                    parent === entityId && (!isShared || !isHidden),
                ).length,
              0,
            ),
          }),
        ),
      ),
    ),
);

export const getCurrentEntities = createDeepEqualSelector(
  [currentSectorSelector, entitySelector, isViewingSharedSector],
  (currentSector, entities, isShared) =>
    mapValues(entities, (entityList, entityType) =>
      pickBy(entityList, (entity, entityId) => {
        if (entity.sector !== currentSector && entityId !== currentSector) {
          return false;
        }
        let { isHidden } = entity;
        let currentEntity = entity;
        while (!isHidden && currentEntity) {
          isHidden = currentEntity.isHidden; // eslint-disable-line
          currentEntity = (entities[currentEntity.parentEntity] || {})[
            currentEntity.parent
          ];
        }
        return !isShared || !isHidden;
      }),
    ),<commit_msg>Fix eslint error<commit_after>import {
  createSelector,
  createSelectorCreator,
  defaultMemoize,
} from 'reselect';
import {
  omit,
  filter,
  pickBy,
  mapValues,
  zipObject,
  difference,
  values,
  includes,
  isEqual,
  flatten,
  map,
  size,
} from 'lodash';

import {
  currentSectorSelector,
  currentEntityTypeSelector,
  currentEntitySelector,
  entitySelector,
  isSidebarEditActiveSelector,
  sidebarEditEntitySelector,
  sidebarEditChildrenSelector,
  savedSectorSelector,
  fetchedSectorSelector,
} from 'store/selectors/base.selectors';
import { isViewingSharedSector } from 'store/selectors/sector.selectors';
import Entities from 'constants/entities';
import { allSectorKeys, coordinateKey } from 'utils/common';
import { areNeighbors } from 'utils/hex/common';

const createDeepEqualSelector = createSelectorCreator(defaultMemoize, isEqual);

export const isFetchingCurrent = createDeepEqualSelector(
  [fetchedSectorSelector, savedSectorSelector, currentSectorSelector],
  (fetched, saved, sector) =>
    includes(saved, sector) && !includes(fetched, sector),
);

export const getSavedEntities = createDeepEqualSelector(
  [entitySelector, savedSectorSelector],
  (entities, savedSectors) =>
    mapValues(entities, entityList =>
      pickBy(entityList, ({ sector }) => includes(savedSectors, sector)),
    ),
);

export const getCurrentTopLevelEntities = createDeepEqualSelector(
  [currentSectorSelector, entitySelector, isViewingSharedSector],
  (currentSector, entities, isShared) =>
    Object.assign(
      ...filter(Entities, ({ topLevel }) => topLevel).map(({ key }) =>
        mapValues(
          pickBy(
            entities[key],
            ({ sector, isHidden }) =>
              sector === currentSector && (!isShared || !isHidden),
          ),
          (entity, entityId) => ({
            ...entity,
            type: key,
            numChildren: Entities[key].children.reduce(
              (total, childKey) =>
                total +
                filter(
                  entities[childKey],
                  ({ parent, isHidden }) =>
                    parent === entityId && (!isShared || !isHidden),
                ).length,
              0,
            ),
          }),
        ),
      ),
    ),
);

export const getCurrentEntities = createDeepEqualSelector(
  [currentSectorSelector, entitySelector, isViewingSharedSector],
  (currentSector, entities, isShared) =>
    mapValues(entities, entityList =>
      pickBy(entityList, (entity, entityId) => {
        if (entity.sector !== currentSector && entityId !== currentSector) {
          return false;
        }
        let { isHidden } = entity;
        let currentEntity = entity;
        while (!isHidden && currentEntity) {
          isHidden = currentEntity.isHidden; // eslint-disable-line
          currentEntity = (entities[currentEntity.parentEntity] || {})[
            currentEntity.parent
          ];
        }
        return !isShared || !isHidden;
      }),
    ),
{'fraction_non_alphanumeric': 0.11455727863931967, 'fraction_numerical': 0.00033350008337502084, 'mean_word_length': 2.8106734434561624, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, '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': '117733', 'n_tokens_mistral': 1677, 'n_tokens_neox': 1672, 'n_words': 335}