<commit_before>import { compose } from '@ngrx/core/compose'
import { ActionReducer, combineReducers } from '@ngrx/store'
import { storeFreeze } from 'ngrx-store-freeze'
import { createSelector } from 'reselect'

import { environment } from '../../../environments/environment'
import * as fromConfig from './config/config.reducer'
import * as fromSensors from './sensors/sensors.reducer'
import * as fromSource from './source/source.reducer'
import * as fromStudy from './study/study.reducer'
import * as fromSubject from './subject/subject.reducer'

export interface State {
  config: fromConfig.State
  sensors: fromSensors.State
  source: fromSource.State
  study: fromStudy.State
  subject: fromSubject.State
}

const reducers = {
  config: fromConfig.reducer,
  sensors: fromSensors.reducer,
  source: fromSource.reducer,
  study: fromStudy.reducer,
  subject: fromSubject.reducer
}

const developmentReducer: ActionReducer<State> = compose(storeFreeze, combineReducers)(reducers)
const productionReducer: ActionReducer<State> = combineReducers(reducers)

export function reducer (state: any, action: any) {
  if (environment.PROD) {
    return productionReducer(state, action)
  } else {
    return developmentReducer(state, action)
  }
}

// Config Selectors
export const getConfigState = (state: State) => state.config
export const getConfigIsLoaded = createSelector(getConfigState, fromConfig.getIsLoaded)

// Study Selectors
export const getStudyState = (state: State) => state.study
export const getStudyIsLoaded = createSelector(getStudyState, fromStudy.getIsLoaded)
export const getStudyIsLoadedAndValid = createSelector(getStudyState, fromStudy.getIsLoadedAndValid)
export const getStudyEntities = createSelector(getStudyState, fromStudy.getEntities)
export const getStudySelected = createSelector(getStudyState, fromStudy.getSelected)
export const getStudyAll = createSelector(getStudyState, fromStudy.getAll)

// Subject Selectors
export const getSubjectState = (state: State) => state.subject
export const getSubjectIsLoaded = createSelector(getSubjectState, fromSubject.getIsLoaded)
export const getSubjectEntities = createSelector(getSubjectState, fromSubject.getEntities)
export const getSubjectAll = createSelector(getSubjectState, fromSubject.getAll)

// Source Selectors
export const getSourceState = (state: State) => state.source
export const getSourceIsLoaded = createSelector(getSourceState, fromSource.getIsLoaded)
export const getSourceEntities = createSelector(getSourceState, fromSource.getEntities)
export const getSourceAll = createSelector(getSourceState, fromSource.getAll)

// Sensors Selectors
export const getSensorsState = (state: State) => state.sensors
export const getSensorsIsLoaded = createSelector(getSensorsState, fromSensors.getIsLoaded)
export const getSensorsEntities = createSelector(getSensorsState, fromSensors.getEntities)
export const getSensorsAll = createSelector(getSensorsState, fromSensors.getAll)

// Source + Sensor Selector
export const getSourceAllWithSensors = createSelector(
  getSourceAll, getSensorsAll, (sources, sensors) => {
    if (sensors.length) {
      const sensorsBySource = sources.reduce((acc, source) => {
        return { ...acc, [source.id]: [] }
      }, {})
<commit_msg>migrate to ngrx@4<commit_after>import { ActionReducer, ActionReducerMap, createFeatureSelector, createSelector } from '@ngrx/store'
import { storeFreeze } from 'ngrx-store-freeze'
import { environment } from '../../../environments/environment'

import * as fromConfig from './config/config.reducer'
import * as fromSensors from './sensors/sensors.reducer'
import * as fromSource from './source/source.reducer'
import * as fromStudy from './study/study.reducer'
import * as fromSubject from './subject/subject.reducer'

export interface State {
  config: fromConfig.State
  sensors: fromSensors.State
  source: fromSource.State
  study: fromStudy.State
  subject: fromSubject.State
}

export const reducers: ActionReducerMap<State> = {
  config: fromConfig.reducer,
  sensors: fromSensors.reducer,
  source: fromSource.reducer,
  study: fromStudy.reducer,
  subject: fromSubject.reducer
}

export const metaReducers: ActionReducer<any, any>[] = !environment.PROD
  ? [storeFreeze]
  : []

// Config Selectors
export const getConfigState = createFeatureSelector<fromConfig.State>('config')
export const getConfigIsLoaded = createSelector(getConfigState, fromConfig.getIsLoaded)

// Study Selectors
export const getStudyState = createFeatureSelector<fromStudy.State>('study')
export const getStudyIsLoaded = createSelector(getStudyState, fromStudy.getIsLoaded)
export const getStudyIsLoadedAndValid = createSelector(getStudyState, fromStudy.getIsLoadedAndValid)
export const getStudyEntities = createSelector(getStudyState, fromStudy.getEntities)
export const getStudySelected = createSelector(getStudyState, fromStudy.getSelected)
export const getStudyAll = createSelector(getStudyState, fromStudy.getAll)

// Subject Selectors
export const getSubjectState = createFeatureSelector<fromSubject.State>('subject')
export const getSubjectIsLoaded = createSelector(getSubjectState, fromSubject.getIsLoaded)
export const getSubjectEntities = createSelector(getSubjectState, fromSubject.getEntities)
export const getSubjectAll = createSelector(getSubjectState, fromSubject.getAll)

// Source Selectors
export const getSourceState = createFeatureSelector<fromSource.State>('source')
export const getSourceIsLoaded = createSelector(getSourceState, fromSource.getIsLoaded)
export const getSourceEntities = createSelector(getSourceState, fromSource.getEntities)
export const getSourceAll = createSelector(getSourceState, fromSource.getAll)

// Sensors Selectors
export const getSensorsState = createFeatureSelector<fromSensors.State>('sensors')
export const getSensorsIsLoaded = createSelector(getSensorsState, fromSensors.getIsLoaded)
export const getSensorsEntities = createSelector(getSensorsState, fromSensors.getEntities)
export const getSensorsAll = createSelector(getSensorsState, fromSensors.getAll)

// Source + Sensor Selector
export const getSourceAllWithSensors = createSelector(
  getSourceAll, getSensorsAll, (sources, sensors) => {
    if (sensors.length) {
      const sensorsBySource = sources.reduce((acc, source) => {
        return { ...acc, [source.id]: [] }
      }, {})

{'fraction_non_alphanumeric': 0.09253118585188694, 'fraction_numerical': 0.00015790304752881732, 'mean_word_length': 6.356562137049942, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 21, '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': '4797599', 'n_tokens_mistral': 1803, 'n_tokens_neox': 1760, 'n_words': 432}