<commit_before>import axios from 'axios'
import * as log from 'electron-log'
import R from 'ramda'

export class WowsApi {
  constructor (key, url, shipdb) {
    this.api = axios.create({
      baseURL: url,
      timeout: 20000,
      params: {
        application_id: key
      }
    })

    const responseHandler = (response) => {
      if (response.data.status !== 'ok' || R.path(['data', 'error'], response)) {
        return Promise.reject(R.path(['data', 'error'], response))
      } else {
        return response
      }
    }

    const errorHandler = (error) => {
      return Promise.reject(error)
    }

    this.api.interceptors.response.use(responseHandler, errorHandler)

    this.shipdb = shipdb
    this.key = key
    this.url = url
  }

  clearCache () {
    this.shipdb.clear()
  }

  findPlayer (playerName) {
    return new Promise((resolve, reject) => {
      // Find the player's account ID. We use Wargaming's
      // API to search by the player's name. The API returns a list of
      // players whose names match our search (i.e. searching for 'Alfred'
      // returns 'Alfred1', 'Alfred_accurate', 'AlfredAlfred' an so on), so
      // we have to search the response list ourselves for the right player
      this.api.get(`/wows/account/list/?search=${encodeURIComponent(playerName)}`)
        .then(response => {
          const playerRecord = R.find(R.propEq('nickname', playerName))(response.data.data)
          return playerRecord
            ? resolve({
              // Player found, so return his account ID
              accountId: playerRecord.account_id,
              name: playerRecord.nickname
            })
            : reject(Error('Player not found'))
        })
        .catch(error => {
          console.log(error)
          return Error('Player not found')
        })
    })
  }

  getPlayers (accountIds, matchGroup = 'pvp') {
    if (matchGroup === 'ranked') matchGroup = 'rank_solo'
    else if (matchGroup === 'cooperative') matchGroup = 'pve'
    return new Promise((resolve, reject) => {
      // Our second step is looking up the player's stats using their account IDs.
      const params = {
        account_id: R.map(R.prop('accountId'), accountIds).join(','),
        extra: ''
      }
      if (matchGroup === 'rank_solo') params.extra = 'statistics.rank_solo'
      if (matchGroup === 'pve') params.extra = 'statistics.pve'

      this.api.get('/wows/account/info/', { params: params })
        .then(response => {
          const players = R.mapObjIndexed((playerStats, accountId, obj) => {
            if (playerStats && (playerStats.hidden_profile || !R.path(['statistics', matchGroup], playerStats))) {
              return {
                name: playerStats.nickname,
                hidden: true
              }
            } else {
              const group = playerStats.statistics[matchGroup]
              return {
                battles: group.battles,
                winrate: (group.wins / group.battles * 100),
                avgExp: (group.xp / group.battles),
                avgDmg: (group.damage_dealt / group.battles),
                kdRatio: (group.frags / (group.battles - group.survived_battles)),
                name: playerStats.nickname
              }
            }
          })(response.data.data)
          return resolve(players)
        })
        .catch(error => {
          return reject(error)
        })<commit_msg>Try to fix longstanding silly bug<commit_after>import axios from 'axios'
import * as log from 'electron-log'
import R from 'ramda'

export class WowsApi {
  constructor (key, url, shipdb) {
    this.api = axios.create({
      baseURL: url,
      timeout: 20000,
      params: {
        application_id: key
      }
    })

    const responseHandler = (response) => {
      if (response.data.status !== 'ok' || R.path(['data', 'error'], response)) {
        return Promise.reject(R.path(['data', 'error'], response))
      } else {
        return response
      }
    }

    const errorHandler = (error) => {
      return Promise.reject(error)
    }

    this.api.interceptors.response.use(responseHandler, errorHandler)

    this.shipdb = shipdb
    this.key = key
    this.url = url
  }

  clearCache () {
    this.shipdb.clear()
  }

  findPlayer (playerName) {
    return new Promise((resolve, reject) => {
      // Find the player's account ID. We use Wargaming's
      // API to search by the player's name. The API returns a list of
      // players whose names match our search (i.e. searching for 'Alfred'
      // returns 'Alfred1', 'Alfred_accurate', 'AlfredAlfred' an so on), so
      // we have to search the response list ourselves for the right player
      this.api.get(`/wows/account/list/?search=${encodeURIComponent(playerName)}`)
        .then(response => {
          const playerRecord = R.find(R.propEq('nickname', playerName))(response.data.data)
          return playerRecord
            ? resolve({
              // Player found, so return his account ID
              accountId: playerRecord.account_id,
              name: playerRecord.nickname
            })
            : reject(Error('Player not found'))
        })
        .catch(error => {
          console.log(error)
          return Error('Player not found')
        })
    })
  }

  getPlayers (accountIds, matchGroup = 'pvp') {
    if (matchGroup === 'ranked') matchGroup = 'rank_solo'
    else if (matchGroup === 'cooperative') matchGroup = 'pve'
    return new Promise((resolve, reject) => {
      // Our second step is looking up the player's stats using their account IDs.
      const params = {
        account_id: R.map(R.prop('accountId'), accountIds).join(','),
        extra: ''
      }
      if (matchGroup === 'rank_solo') params.extra = 'statistics.rank_solo'
      if (matchGroup === 'pve') params.extra = 'statistics.pve'

      this.api.get('/wows/account/info/', { params: params })
        .then(response => {
          const players = R.mapObjIndexed((playerStats, accountId, obj) => {
            if (playerStats && (!playerStats.statistics || playerStats.hidden_profile || !R.path(['statistics', matchGroup], playerStats))) {
              return {
                name: playerStats.nickname,
                hidden: true
              }
            } else {
              const group = playerStats.statistics[matchGroup]
              return {
                battles: group.battles,
                winrate: (group.wins / group.battles * 100),
                avgExp: (group.xp / group.battles),
                avgDmg: (group.damage_dealt / group.battles),
                kdRatio: (group.frags / (group.battles - group.survived_battles)),
                name: playerStats.nickname
              }
            }
          })(response.data.data)
          return resolve(players)
        })
        .catch(error => {
          return reject(error)
        })
{'fraction_non_alphanumeric': 0.12607116920842412, 'fraction_numerical': 0.00261437908496732, 'mean_word_length': 2.0374944861049844, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5501291', 'n_tokens_mistral': 2027, 'n_tokens_neox': 1962, 'n_words': 492}