<commit_before>import { applyAsyncLoading } from './loading';
import app from 'ampersand-app';
import { compact, flatten, sortBy } from 'lodash';

const SET_REMOTE_RESULTS = 'SET_REMOTE_RESULTS';

export const setRemoteResults = (results) => ({ type: SET_REMOTE_RESULTS, results });

export const fetch = applyAsyncLoading(id => (dispatch) => {
  const dbRegistry = app.core.dbRegistry;
  const dbs = id ?
    [dbRegistry.get(`remote-consortium-${id}`)] :
    dbRegistry.all.filter(({ name }) => name.includes('remote-consortium-'));

  return Promise.all(dbs.map(db => db.all()))
    .then((responses) => {
      const results = sortBy(compact(flatten(responses)), ['endDate', 'startDate']).reverse();
      dispatch(setRemoteResults(results));
      return results;
    });
});

export const fetchRemoteResultsForUser = username => (dispatch, getState) => {
  const dbRegistry = app.core.dbRegistry;
  const dbs = dbRegistry.all.filter(({ name }) => name.includes('remote-consortium-'));

  return Promise.all(dbs.map(db => db.all()))
    .then((responses) => {
      const userResults = compact(flatten(responses))
        .filter(obj => obj.usernames.indexOf(username) > -1)
        .map((res) => {
          return {
            ...res,
            consortium: getState().consortia.find(({ _id }) => _id === res.consortiumId),
            // This doesn't actually seem to be used-- project: getState().projects.find(({ consortiumId }) => consortiumId === res.consortiumId),
            computation: getState().computations.find(({ _id }) => _id === res.computationId),
          };
        });
      const results = sortBy(userResults, ['endDate', 'startDate']).reverse();
      dispatch(setRemoteResults(results));
      return results;
    });
};

export default function reducer(state = null, action = {}) {
  switch (action.type) {
    case 'SET_REMOTE_RESULTS':
      if (!action.results) { return null; }
      return [...action.results];
    default: return state;
  }
}<commit_msg>line length formatting<commit_after>import { applyAsyncLoading } from './loading';
import app from 'ampersand-app';
import { compact, flatten, sortBy } from 'lodash';

const SET_REMOTE_RESULTS = 'SET_REMOTE_RESULTS';

export const setRemoteResults = (results) => ({ type: SET_REMOTE_RESULTS, results });

export const fetch = applyAsyncLoading(id => (dispatch) => {
  const dbRegistry = app.core.dbRegistry;
  const dbs = id ?
    [dbRegistry.get(`remote-consortium-${id}`)] :
    dbRegistry.all.filter(({ name }) => name.includes('remote-consortium-'));

  return Promise.all(dbs.map(db => db.all()))
    .then((responses) => {
      const results = sortBy(compact(flatten(responses)), ['endDate', 'startDate']).reverse();
      dispatch(setRemoteResults(results));
      return results;
    });
});

export const fetchRemoteResultsForUser = username => (dispatch, getState) => {
  const dbRegistry = app.core.dbRegistry;
  const dbs = dbRegistry.all.filter(({ name }) => name.includes('remote-consortium-'));

  return Promise.all(dbs.map(db => db.all()))
    .then((responses) => {
      const userResults = compact(flatten(responses))
        .filter(obj => obj.usernames.indexOf(username) > -1)
        .map((res) => {
          return {
            ...res,
            consortium: getState().consortia.find(({ _id }) => _id === res.consortiumId),
            // This doesn't actually seem to be used
            // project: getState().projects.find(({ consortiumId }) =>
            //   consortiumId === res.consortiumId),
            computation: getState().computations.find(({ _id }) => _id === res.computationId),
          };
        });
      const results = sortBy(userResults, ['endDate', 'startDate']).reverse();
      dispatch(setRemoteResults(results));
      return results;
    });
};

export default function reducer(state = null, action = {}) {
  switch (action.type) {
    case 'SET_REMOTE_RESULTS':
      if (!action.results) { return null; }
      return [...action.results];
    default: return state;
  }
}
{'fraction_non_alphanumeric': 0.16588030792152966, 'fraction_numerical': 0.0004966476285075739, 'mean_word_length': 3.317256162915327, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 37, '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': '13910', 'n_tokens_mistral': 1240, 'n_tokens_neox': 1192, 'n_words': 256}