<commit_before>import {
  GPS_FAVORITE,
  GPS_FAVORITE_REMOVE,
  GPS_AVOID,
  GPS_AVOID_REMOVE,
  GPS_SEARCH,
  CREATE_ROUTE,
  DELETE_ROUTE,
  CLEAR_ROUTE_HISTORY,
} from '../actions'

export const initialState = {
  favorites: [{
    id: 30000142,
    name: 'Jita',
    sec: 0.945913117
  //}, {
  //  id: 30002053,
  //  name: "Hek",
  //  sec: 0.549668267
  //}, {
  //  id: 30002659,
  //  name: "Dodixie",
  //  sec: 0.868406702
  //}, {
  //  id: 30002187,
  //  name: "Amarr",
  //  sec: 1
  }],
  avoidance: [],
  routes: [],
  search: {
    origin: '',
    destination: '',
  }
}

export const createRoute = (state, action) => {
  const { systems } = action
  const [origin, destination] = [
    systems.shortest[0],
    systems.shortest.slice().pop()
  ]

  const safest = {
    jumps: systems.safest.length,
    systems: systems.safest,
    bestSec: systems.safest.reduce((memo, {sec}) => Math.max(sec, memo), -1),
    worstSec: systems.safest.reduce((memo, {sec}) => Math.min(sec, memo), 1),
  }

  const shortest = {
    jumps: systems.shortest.length,
    systems: systems.shortest,
    bestSec: systems.shortest.reduce((memo, {sec}) => Math.max(sec, memo), -1),
    worstSec: systems.shortest.reduce((memo, {sec}) => Math.min(sec, memo), 1),
  }

  const routes = [{
    origin,
    destination,
    safest,
    shortest,
  }, ...state.routes]
  return Object.assign({}, state, { routes })
}

export const search = (state, action) => {
  const { origin, destination } = action
  const search = {
    origin: origin || state.origin,
    destination: destination || state.destination,
  }

  return Object.assign({}, state, { search })
}

export const addFavorite = (state, {system}) => {
  const favorites = state.favorites.find(fav => fav.id === system.id)
  ? state.favorites
  : [...state.favorites, system]
  return Object.assign({}, state, { favorites })
}

export const removeFavorite = (state, {system}) => {
  const favorites = state.favorites.filter(fav => fav.id !== system.id)
  return Object.assign({}, state, { favorites })
}

export const deleteRouteByOrigin = (state, {origin}) => {
  const route = state.routes.filter(r => route.origin.id !== origin.id)
  return Object.assign({}, state, { routes })
}

export const deleteRoute = (state, {origin, destination}) => {
  const routes = state.routes.filter(route => {
    return !((origin.id === route.origin.id) && (destination.id === route.destination.id))
  })
  return Object.assign({}, state, { routes })
}

export const gps = (state=initialState, action) => {
  switch(action.type) {

    case CREATE_ROUTE:
      return createRoute(state, action)
    case DELETE_ROUTE:
      return deleteRoute(state, action)
    case CLEAR_ROUTE_HISTORY:
      return Object.assign(state, {routes: []})
    case GPS_SEARCH:
      return search(state, action)
    case GPS_FAVORITE:
      return addFavorite(state, action)
    case GPS_FAVORITE_REMOVE:
      return removeFavorite(state, action)
  }

  return state
}<commit_msg>added deleteSystem to gps reducer<commit_after>import {
  GPS_FAVORITE,
  GPS_FAVORITE_REMOVE,
  GPS_AVOID,
  GPS_AVOID_REMOVE,
  GPS_SEARCH,
  CREATE_ROUTE,
  DELETE_ROUTE,
  DELETE_SYSTEM,
  CLEAR_ROUTE_HISTORY,
} from '../actions'

export const initialState = {
  favorites: [{
    id: 30000142,
    name: 'Jita',
    sec: 0.945913117
  //}, {
  //  id: 30002053,
  //  name: "Hek",
  //  sec: 0.549668267
  //}, {
  //  id: 30002659,
  //  name: "Dodixie",
  //  sec: 0.868406702
  //}, {
  //  id: 30002187,
  //  name: "Amarr",
  //  sec: 1
  }],
  avoidance: [],
  routes: [],
  search: {
    origin: '',
    destination: '',
  }
}

export const createRoute = (state, action) => {
  const { systems } = action
  const [origin, destination] = [
    systems.shortest[0],
    systems.shortest.slice().pop()
  ]

  const safest = {
    jumps: systems.safest.length,
    systems: systems.safest,
    bestSec: systems.safest.reduce((memo, {sec}) => Math.max(sec, memo), -1),
    worstSec: systems.safest.reduce((memo, {sec}) => Math.min(sec, memo), 1),
  }

  const shortest = {
    jumps: systems.shortest.length,
    systems: systems.shortest,
    bestSec: systems.shortest.reduce((memo, {sec}) => Math.max(sec, memo), -1),
    worstSec: systems.shortest.reduce((memo, {sec}) => Math.min(sec, memo), 1),
  }

  const routes = [{
    origin,
    destination,
    safest,
    shortest,
  }, ...state.routes]
  return Object.assign({}, state, { routes })
}

export const search = (state, action) => {
  const { origin, destination } = action
  const search = {
    origin: origin || state.origin,
    destination: destination || state.destination,
  }

  return Object.assign({}, state, { search })
}

export const addFavorite = (state, {system}) => {
  const favorites = state.favorites.find(fav => fav.id === system.id)
  ? state.favorites
  : [...state.favorites, system]
  return Object.assign({}, state, { favorites })
}

export const removeFavorite = (state, {system}) => {
  const favorites = state.favorites.filter(fav => fav.id !== system.id)
  return Object.assign({}, state, { favorites })
}

export const deleteRouteByOrigin = (state, {origin}) => {
  const route = state.routes.filter(r => route.origin.id !== origin.id)
  return Object.assign({}, state, { routes })
}

export const deleteRoute = (state, {origin, destination}) => {
  const routes = state.routes.filter(route => {
    return !((origin.id === route.origin.id) && (destination.id === route.destination.id))
  })
  return Object.assign({}, state, { routes })
}

export const deleteSystem = (state, {system}) => {
  const routes = state.routes.filter(r => {
    return (r.origin.id !== system.id)
    && (r.destination.id !== system.id)
  })

  return Object.assign({}, state, { routes })
}

export const gps = (state=initialState, action) => {
  switch(action.type) {

    case CREATE_ROUTE:
      return createRoute(state, action)
    case DELETE_ROUTE:
      return deleteRoute(state, action)
    case DELETE_SYSTEM:
      return deleteSystem(state, action)
    case CLEAR_ROUTE_HISTORY:
      return Object.assign(state, {routes: []})
    case GPS_SEARCH:
      return search(state, action)
    case GPS_FAVORITE:
      return addFavorite(state, action)
    case GPS_FAVORITE_REMOVE:
      return removeFavorite(state, action)
  }

  return state
}
{'fraction_non_alphanumeric': 0.16205533596837945, 'fraction_numerical': 0.02150197628458498, 'mean_word_length': 3.200531208499336, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 35, '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': '1260710', 'n_tokens_mistral': 2317, 'n_tokens_neox': 2232, 'n_words': 479}