<commit_before>'use strict';
const CliTable = require('cli-table');
const chalk = require('chalk');
const tradePairs = require('./tradePairs');
const tradePairParser = require('./tradePairParser');
const formatter = require('./formatter');

class TableData {

  constructor() {
    this.tradePairs = [];
  }

  init() {
    this.tradePairs = tradePairs.getTradePairs();
  }

  getTable() {
    return new Promise((resolve, reject) => {
      let table = new CliTable({
        head: this.getHead()
      });

      this.fillContent(table)
        .then(table => resolve(table))
        .catch(error => reject(error));
    });
  }

  getHead() {
    return [
      chalk.cyan.bold('name'),
      chalk.cyan.bold('ll'),
      chalk.cyan.bold('stat'),
      chalk.cyan.bold('oo?'),
      chalk.cyan.bold('coins'),
      chalk.cyan.bold('in BTC'),
      chalk.cyan.bold('change'),
      chalk.cyan.bold('pr2Buy'),
      chalk.cyan.bold('pr2Sell'),
      chalk.cyan.bold('lastPrice'),
      chalk.cyan.bold('price diff'),
      chalk.cyan.bold('price is'),
      chalk.cyan.bold('# buys'),
      chalk.cyan.bold('1/6/12/24/+'),
      chalk.cyan.bold('# sells'),
      chalk.cyan.bold('1/6/12/24/+'),
      chalk.cyan.bold('profit'),
      chalk.cyan.bold('last error')
    ];
  }

  fillContent(table) {
    return new Promise((resolve, reject) => {
      let dataPromises = [];
      for (let market of Object.keys(this.tradePairs)) {
        if (this.tradePairs[market].length === 0) {
          continue;
        }

        for (let tradePair of this.tradePairs[market]) {
          dataPromises.push(tradePairParser.getData(tradePair, market));
        }
      }

      Promise.all(dataPromises)
        .then(values => {

          let totalBTCValue = 0.0;
          let totalProfit = 0.0;

          for (let data of values) {
            if (data === undefined || data.lastTimeStamp === undefined) {
              continue;
            }

            if(!isNaN(parseFloat(formatter.btcValue(data.coins, data.lastPriceInBTC)))) {
              totalBTCValue += parseFloat(formatter.btcValue(data.coins, data.lastPriceInBTC));
            }

            if(!isNaN(parseFloat(data.profit))) {
              totalProfit += parseFloat(data.profit);
            }


            table.push([
              formatter.tradePair(data.tradePair),
              formatter.timeSince(data.lastTimeStamp),
              formatter.timeToStatus(data.lastTimeStamp),
              formatter.openOrders(data.openOrders || data.noOpenOrders),
              formatter.coins(data.coins),
              formatter.btcValue(data.coins, data.lastPriceInBTC),
              formatter.currentProfit(data.coins, data.boughtPrice, data.lastPriceInBTC),
              formatter.price(data.buyPrice),
              formatter.price(data.sellPrice),
              formatter.lastPrice(data.lastPrice, data.tendency),
              formatter.priceDiff(data.priceStatusBuy || data.priceStatusSell, data.buyPrice, data.sellPrice, data.lastPrice),
              formatter.buySellMessage(data.priceStatusBuy || data.priceStatusSell || data.priceStatusSweet),
              formatter.trades(data.buyCounter, data.lastTimeStampBuy),
              formatter.tradesInTimeSlots(data.buys),
              formatter.trades(data.sellCounter, data.lastTimeStampSell),
              formatter.tradesInTimeSlots(data.sells),
              formatter.price(data.profit),
              formatter.errorCode(data.lastErrorCode, data.lastErrorTimeStamp)
            ]);
          }

          table.push([
            formatter.tradePair('TOTAL'),
            '',<commit_msg>Typo.<commit_after>'use strict';
const CliTable = require('cli-table');
const chalk = require('chalk');
const tradePairs = require('./tradePairs');
const tradePairParser = require('./tradePairParser');
const formatter = require('./formatter');

class TableData {

  constructor() {
    this.tradePairs = [];
  }

  init() {
    this.tradePairs = tradePairs.getTradePairs();
  }

  getTable() {
    return new Promise((resolve, reject) => {
      let table = new CliTable({
        head: this.getHead()
      });

      this.fillContent(table)
        .then(table => resolve(table))
        .catch(error => reject(error));
    });
  }

  getHead() {
    return [
      chalk.cyan.bold('name'),
      chalk.cyan.bold('ll'),
      chalk.cyan.bold('stat'),
      chalk.cyan.bold('oo?'),
      chalk.cyan.bold('coins'),
      chalk.cyan.bold('in BTC'),
      chalk.cyan.bold('change'),
      chalk.cyan.bold('pr2Buy'),
      chalk.cyan.bold('pr2Sell'),
      chalk.cyan.bold('lastPrice'),
      chalk.cyan.bold('price diff'),
      chalk.cyan.bold('price is'),
      chalk.cyan.bold('# buys'),
      chalk.cyan.bold('1/6/12/24/+'),
      chalk.cyan.bold('# sells'),
      chalk.cyan.bold('1/6/12/24/+'),
      chalk.cyan.bold('profit'),
      chalk.cyan.bold('last error')
    ];
  }

  fillContent(table) {
    return new Promise((resolve, reject) => {
      let dataPromises = [];
      for (let market of Object.keys(this.tradePairs)) {
        if (this.tradePairs[market].length === 0) {
          continue;
        }

        for (let tradePair of this.tradePairs[market]) {
          dataPromises.push(tradePairParser.getData(tradePair, market));
        }
      }

      Promise.all(dataPromises)
        .then(values => {
          let totalBTCValue = 0.0;
          let totalProfit = 0.0;

          for (let data of values) {
            if (data === undefined || data.lastTimeStamp === undefined) {
              continue;
            }

            if (!isNaN(parseFloat(formatter.btcValue(data.coins, data.lastPriceInBTC)))) {
              totalBTCValue += parseFloat(formatter.btcValue(data.coins, data.lastPriceInBTC));
            }

            if (!isNaN(parseFloat(data.profit))) {
              totalProfit += parseFloat(data.profit);
            }

            table.push([
              formatter.tradePair(data.tradePair),
              formatter.timeSince(data.lastTimeStamp),
              formatter.timeToStatus(data.lastTimeStamp),
              formatter.openOrders(data.openOrders || data.noOpenOrders),
              formatter.coins(data.coins),
              formatter.btcValue(data.coins, data.lastPriceInBTC),
              formatter.currentProfit(data.coins, data.boughtPrice, data.lastPriceInBTC),
              formatter.price(data.buyPrice),
              formatter.price(data.sellPrice),
              formatter.lastPrice(data.lastPrice, data.tendency),
              formatter.priceDiff(data.priceStatusBuy || data.priceStatusSell, data.buyPrice, data.sellPrice, data.lastPrice),
              formatter.buySellMessage(data.priceStatusBuy || data.priceStatusSell || data.priceStatusSweet),
              formatter.trades(data.buyCounter, data.lastTimeStampBuy),
              formatter.tradesInTimeSlots(data.buys),
              formatter.trades(data.sellCounter, data.lastTimeStampSell),
              formatter.tradesInTimeSlots(data.sells),
              formatter.price(data.profit),
              formatter.errorCode(data.lastErrorCode, data.lastErrorTimeStamp)
            ]);
          }

          table.push([
            formatter.tradePair('TOTAL'),
            '',
{'fraction_non_alphanumeric': 0.1417311946902655, 'fraction_numerical': 0.005254424778761062, 'mean_word_length': 2.2787851314596557, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '2232799', 'n_tokens_mistral': 2328, 'n_tokens_neox': 2167, 'n_words': 304}