<commit_before>import orderBy from 'lodash/orderBy'
import { createSelector } from 'reselect'

import { FAMILY_ANALYSIS_STATUS_OPTIONS } from 'shared/utils/constants'

import {
  getProjectsByGuid, getFamiliesByGuid, getIndividualsByGuid, getSamplesByGuid,
} from 'redux/selectors'

import {
  SHOW_ALL,
  SORT_BY_FAMILY_NAME,
  CASE_REVIEW_STATUS_OPTIONS,
  FAMILY_FILTER_OPTIONS,
  FAMILY_SORT_OPTIONS,
  SORT_BY_FAMILY_GUID,
  VARIANT_SORT_OPTONS,
  VARIANT_EXPORT_DATA,
  VARIANT_GENOTYPE_EXPORT_DATA,
} from './constants'


const FAMILY_FILTER_LOOKUP = FAMILY_FILTER_OPTIONS.reduce(
  (acc, opt) => ({
    ...acc,
    ...{ [opt.value]: opt.createFilter },
  }), {},
)

const FAMILY_SORT_LOOKUP = FAMILY_SORT_OPTIONS.reduce(
  (acc, opt) => ({
    ...acc,
    ...{ [opt.value]: opt.createSortKeyGetter },
  }), {},
)

const VARIANT_SORT_LOOKUP = VARIANT_SORT_OPTONS.reduce(
  (acc, opt) => ({
    ...acc,
    ...{ [opt.value]: opt.comparator },
  }), {},
)

// project data selectors

export const getProjectDetailsIsLoading = state => state.projectDetailsLoading.isLoading
export const getProjectSavedVariantsIsLoading = state => state.projectSavedVariantsLoading.isLoading
export const getProjectGuid = state => state.currentProjectGuid

export const getProject = createSelector(
  getProjectsByGuid, getProjectGuid, (projectsByGuid, currentProjectGuid) => projectsByGuid[currentProjectGuid],
)

const filterProjectEntities = (entities, currentProjectGuid) =>
  Object.values(entities).filter(o => o.projectGuid === currentProjectGuid)

export const getProjectFamilies = createSelector(getFamiliesByGuid, getProjectGuid, filterProjectEntities)

export const getProjectIndividuals = createSelector(getIndividualsByGuid, getProjectGuid, filterProjectEntities)

export const getProjectSamples = createSelector(getSamplesByGuid, getProjectGuid, filterProjectEntities)

// Saved variant selectors
export const getSavedVariantTableState = state => state.savedVariantTableState
export const getSavedVariantCategoryFilter = state => state.savedVariantTableState.categoryFilter || SHOW_ALL
export const getSavedVariantSortOrder = state => state.savedVariantTableState.sortOrder || SORT_BY_FAMILY_GUID
export const getSavedVariantHideExcluded = state => state.savedVariantTableState.hideExcluded
export const getSavedVariantCurrentPage = state => state.savedVariantTableState.currentPage || 1
export const getSavedVariantRecordsPerPage = state => state.savedVariantTableState.recordsPerPage || 25

export const getProjectSavedVariants = createSelector(
  state => state.projectSavedVariants,
  (state, props) => props.match.params,
  (projectSavedVariants, { tag, familyGuid, variantGuid }) => {
    let variants = Object.values(projectSavedVariants)<commit_msg>Added getProjectFamiliesByGuid, etc. selectors<commit_after>import orderBy from 'lodash/orderBy'
import { createSelector } from 'reselect'

import { FAMILY_ANALYSIS_STATUS_OPTIONS } from 'shared/utils/constants'

import { getProjectsByGuid, getFamiliesByGuid, getIndividualsByGuid, getSamplesByGuid } from 'redux/selectors'

import {
  SHOW_ALL,
  SORT_BY_FAMILY_NAME,
  CASE_REVIEW_STATUS_OPTIONS,
  FAMILY_FILTER_OPTIONS,
  FAMILY_SORT_OPTIONS,
  SORT_BY_FAMILY_GUID,
  VARIANT_SORT_OPTONS,
  VARIANT_EXPORT_DATA,
  VARIANT_GENOTYPE_EXPORT_DATA,
} from './constants'


const FAMILY_FILTER_LOOKUP = FAMILY_FILTER_OPTIONS.reduce(
  (acc, opt) => ({
    ...acc,
    [opt.value]: opt.createFilter,
  }), {},
)

const FAMILY_SORT_LOOKUP = FAMILY_SORT_OPTIONS.reduce(
  (acc, opt) => ({
    ...acc,
    [opt.value]: opt.createSortKeyGetter,
  }), {},
)

const VARIANT_SORT_LOOKUP = VARIANT_SORT_OPTONS.reduce(
  (acc, opt) => ({
    ...acc,
    [opt.value]: opt.comparator,
  }), {},
)

// project data selectors

export const getProjectDetailsIsLoading = state => state.projectDetailsLoading.isLoading
export const getProjectSavedVariantsIsLoading = state => state.projectSavedVariantsLoading.isLoading
export const getProjectGuid = state => state.currentProjectGuid

export const getProject = createSelector(
  getProjectsByGuid, getProjectGuid, (projectsByGuid, currentProjectGuid) => projectsByGuid[currentProjectGuid],
)

const filterProjectEntities = (entities, currentProjectGuid) => Object.entries(entities).filter(
  ([, o]) => o.projectGuid === currentProjectGuid,
).reduce((acc, [k, o]) => {
  return { ...acc, [k]: o }
}, {})


export const getProjectFamiliesByGuid = createSelector(getFamiliesByGuid, getProjectGuid, filterProjectEntities)
export const getProjectIndividualsByGuid = createSelector(getIndividualsByGuid, getProjectGuid, filterProjectEntities)
export const getProjectSamplesByGuid = createSelector(getSamplesByGuid, getProjectGuid, filterProjectEntities)

export const getProjectFamilies = createSelector(getProjectFamiliesByGuid, d => Object.values(d))
export const getProjectIndividuals = createSelector(getProjectIndividualsByGuid, d => Object.values(d))
export const getProjectSamples = createSelector(getProjectSamplesByGuid, d => Object.values(d))

// Saved variant selectors
export const getSavedVariantTableState = state => state.savedVariantTableState
export const getSavedVariantCategoryFilter = state => state.savedVariantTableState.categoryFilter || SHOW_ALL
export const getSavedVariantSortOrder = state => state.savedVariantTableState.sortOrder || SORT_BY_FAMILY_GUID
export const getSavedVariantHideExcluded = state => state.savedVariantTableState.hideExcluded
export const getSavedVariantCurrentPage = state => state.savedVariantTableState.currentPage || 1
export const getSavedVariantRecordsPerPage = state => state.savedVariantTableState.recordsPerPage || 25

export const getProjectSavedVariants = createSelector(
  state => state.projectSavedVariants,
  (state, props) => props.match.params,
  (projectSavedVariants, { tag, familyGuid, variantGuid }) => {
    let variants = Object.values(projectSavedVariants)
{'fraction_non_alphanumeric': 0.09709066305818674, 'fraction_numerical': 0.0010148849797023004, 'mean_word_length': 6.447103274559194, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 43, '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': '3687438', 'n_tokens_mistral': 1857, 'n_tokens_neox': 1809, 'n_words': 348}