<commit_before>import _ from 'lodash';

export const OPENCLGA_STATES = {
  DEFAULT: 'waiting',
  WAITING: 'waiting',
  PREPARING: 'preparing',
  RESTORING: 'restoring',
  PREPARED: 'prepared',
  RUNNING: 'running',
  PAUSING: 'pausing',
  PAUSED: 'paused',
  SAVING: 'saving',
  STOPPING: 'stopping',
  STOPPED: 'stopped'
};

export const DEVICE_TYPE = {
  GPU: 'gpu',
  CPU: 'cpu',
  DSP: 'dsp'
};

// This is the default websocket connection information
export const DEFAULT_WEBSOCKET_SERVER = null;
export const DEFAULT_WEBSOCKET_PORT = 8000;

const waitingState = (others) => {
  const anyPreparing = _.some(others, (state) => (state === OPENCLGA_STATES.PREPARING));
  const anyRestoring = _.some(others, (state) => (state === OPENCLGA_STATES.RESTORING));
  const allPrepared = others.every((state) => (state === OPENCLGA_STATES.PREPARED));

  if (anyPreparing) {
    return OPENCLGA_STATES.PREPARING;
  } else if (anyRestoring) {
    return OPENCLGA_STATES.RESTORING;
  } else if (allPrepared) {
    return OPENCLGA_STATES.PREPARED;
  }
};

const preparingState = (others) => {
  return others.every((state) => (state === OPENCLGA_STATES.PREPARED))
            ? OPENCLGA_STATES.PREPARED : OPENCLGA_STATES.PREPARING;
};

const restoringState = (others) => {
  return others.every((state) => (state === OPENCLGA_STATES.PREPARED))
              ? OPENCLGA_STATES.PREPARED : OPENCLGA_STATES.RESTORING;
};

const preparedState = (others) => {
  return _.some(others, (state) => (state === OPENCLGA_STATES.RUNNING))
              ? OPENCLGA_STATES.RUNNING : OPENCLGA_STATES.PREPARED;
};

const runningState = (others) => {
  const anyPausing = _.some(others, (state) => (state === OPENCLGA_STATES.PAUSING));
  const anyStopping = _.some(others, (state) => (state === OPENCLGA_STATES.STOPPING));
  const allPaused = others.every((state) => (state === OPENCLGA_STATES.PAUSED));
  const allStopped = others.every((state) => (state === OPENCLGA_STATES.STOPPED));

  if (anyPausing) {
    return OPENCLGA_STATES.PAUSING;
  } else if (anyStopping) {
    return OPENCLGA_STATES.STOPPING;
  } else if (allPaused) {
    return OPENCLGA_STATES.PAUSED;
  } else if (allStopped) {
    return OPENCLGA_STATES.STOPPED;
  } else {
    return OPENCLGA_STATES.RUNNING;
  }
};

const pausingState = (others) => {
  return others.every((state) => (state === OPENCLGA_STATES.PAUSED))
            ? OPENCLGA_STATES.PAUSED : OPENCLGA_STATES.PUASING;
};

const stoppingState = (others) => {
  return others.every((state) => (state === OPENCLGA_STATES.STOPPED))
              ? OPENCLGA_STATES.STOPPED : OPENCLGA_STATES.STOPPING;
};

const pausedState = (others) => {
  const anyRunning = _.some(others, (state) => (state === OPENCLGA_STATES.RUNNING));
  const anySaving = _.some(others, (state) => (state === OPENCLGA_STATES.SAVING));
  const anyStopping = _.some(others, (state) => (state === OPENCLGA_STATES.STOPPIG));
  if (anyRunning) {
    return OPENCLGA_STATES.RUNNING;
  } else if (anySaving) {
    return OPENCLGA_STATES.SAVING;
  } else if (anyStopping) {
    return OPENCLGA_STATES.STOPPING;
  } else {
    return OPENCLGA_STATES.PAUSED;
  }
}

const savingState = (others) => {
  const allPaused = others.every((state) => (state === OPENCLGA_STATES.PAUSED));
  return allPaused ? OPENCLGA_STATES.PAUSED : OPENCLGA_STATES.SAVING;
}

const stoppedState = (others) => {
  return OPENCLGA_STATES.STOPPED;
};

export const STATE_HANDLERS = {
  [OPENCLGA_STATES.WAITING]: waitingState,
  [OPENCLGA_STATES.PREPARING]: preparingState,
  [OPENCLGA_STATES.RESTORING]: restoringState,
  [OPENCLGA_STATES.PREPARED]: preparedState,
  [OPENCLGA_STATES.RUNNING]: runningState,
  [OPENCLGA_STATES.PAUSING]: pausingState,
  [OPENCLGA_STATES.PAUSED]: pausedState,
  [OPENCLGA_STATES.SAVING]: savingState,
  [OPENCLGA_STATES.STOPPING]: stoppingState,
  [OPENCLGA_STATES.STOPPED]: stoppedState
};

<commit_msg>add comments to websocket server<commit_after>import _ from 'lodash';

export const OPENCLGA_STATES = {
  DEFAULT: 'waiting',
  WAITING: 'waiting',
  PREPARING: 'preparing',
  RESTORING: 'restoring',
  PREPARED: 'prepared',
  RUNNING: 'running',
  PAUSING: 'pausing',
  PAUSED: 'paused',
  SAVING: 'saving',
  STOPPING: 'stopping',
  STOPPED: 'stopped'
};

export const DEVICE_TYPE = {
  GPU: 'gpu',
  CPU: 'cpu',
  DSP: 'dsp'
};

// This is the default websocket connection information:
// The default websocket server may have the following candidates:
// 1. 'dialog': for showing an input dialog for connecting to any servers.
// 2. '[IP address]': for connecting to specified server
// 3. null: for connecting to localhost server
export const DEFAULT_WEBSOCKET_SERVER = null;
export const DEFAULT_WEBSOCKET_PORT = 8000;

const waitingState = (others) => {
  const anyPreparing = _.some(others, (state) => (state === OPENCLGA_STATES.PREPARING));
  const anyRestoring = _.some(others, (state) => (state === OPENCLGA_STATES.RESTORING));
  const allPrepared = others.every((state) => (state === OPENCLGA_STATES.PREPARED));

  if (anyPreparing) {
    return OPENCLGA_STATES.PREPARING;
  } else if (anyRestoring) {
    return OPENCLGA_STATES.RESTORING;
  } else if (allPrepared) {
    return OPENCLGA_STATES.PREPARED;
  }
};

const preparingState = (others) => {
  return others.every((state) => (state === OPENCLGA_STATES.PREPARED))
            ? OPENCLGA_STATES.PREPARED : OPENCLGA_STATES.PREPARING;
};

const restoringState = (others) => {
  return others.every((state) => (state === OPENCLGA_STATES.PREPARED))
              ? OPENCLGA_STATES.PREPARED : OPENCLGA_STATES.RESTORING;
};

const preparedState = (others) => {
  return _.some(others, (state) => (state === OPENCLGA_STATES.RUNNING))
              ? OPENCLGA_STATES.RUNNING : OPENCLGA_STATES.PREPARED;
};

const runningState = (others) => {
  const anyPausing = _.some(others, (state) => (state === OPENCLGA_STATES.PAUSING));
  const anyStopping = _.some(others, (state) => (state === OPENCLGA_STATES.STOPPING));
  const allPaused = others.every((state) => (state === OPENCLGA_STATES.PAUSED));
  const allStopped = others.every((state) => (state === OPENCLGA_STATES.STOPPED));

  if (anyPausing) {
    return OPENCLGA_STATES.PAUSING;
  } else if (anyStopping) {
    return OPENCLGA_STATES.STOPPING;
  } else if (allPaused) {
    return OPENCLGA_STATES.PAUSED;
  } else if (allStopped) {
    return OPENCLGA_STATES.STOPPED;
  } else {
    return OPENCLGA_STATES.RUNNING;
  }
};

const pausingState = (others) => {
  return others.every((state) => (state === OPENCLGA_STATES.PAUSED))
            ? OPENCLGA_STATES.PAUSED : OPENCLGA_STATES.PUASING;
};

const stoppingState = (others) => {
  return others.every((state) => (state === OPENCLGA_STATES.STOPPED))
              ? OPENCLGA_STATES.STOPPED : OPENCLGA_STATES.STOPPING;
};

const pausedState = (others) => {
  const anyRunning = _.some(others, (state) => (state === OPENCLGA_STATES.RUNNING));
  const anySaving = _.some(others, (state) => (state === OPENCLGA_STATES.SAVING));
  const anyStopping = _.some(others, (state) => (state === OPENCLGA_STATES.STOPPIG));
  if (anyRunning) {
    return OPENCLGA_STATES.RUNNING;
  } else if (anySaving) {
    return OPENCLGA_STATES.SAVING;
  } else if (anyStopping) {
    return OPENCLGA_STATES.STOPPING;
  } else {
    return OPENCLGA_STATES.PAUSED;
  }
}

const savingState = (others) => {
  const allPaused = others.every((state) => (state === OPENCLGA_STATES.PAUSED));
  return allPaused ? OPENCLGA_STATES.PAUSED : OPENCLGA_STATES.SAVING;
}

const stoppedState = (others) => {
  return OPENCLGA_STATES.STOPPED;
};

export const STATE_HANDLERS = {
  [OPENCLGA_STATES.WAITING]: waitingState,
  [OPENCLGA_STATES.PREPARING]: preparingState,
  [OPENCLGA_STATES.RESTORING]: restoringState,
  [OPENCLGA_STATES.PREPARED]: preparedState,
  [OPENCLGA_STATES.RUNNING]: runningState,
  [OPENCLGA_STATES.PAUSING]: pausingState,
  [OPENCLGA_STATES.PAUSED]: pausedState,
  [OPENCLGA_STATES.SAVING]: savingState,
  [OPENCLGA_STATES.STOPPING]: stoppingState,
  [OPENCLGA_STATES.STOPPED]: stoppedState
};


{'fraction_non_alphanumeric': 0.13821036889332003, 'fraction_numerical': 0.0013708873379860418, 'mean_word_length': 4.485304169514696, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 55, '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': '7301457', 'n_tokens_mistral': 3051, 'n_tokens_neox': 2863, 'n_words': 554}